binutils-filename-in-error-messages.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --- binutils.orig/binutils/readelf.c 2021-07-19 12:39:14.206556025 +0100
  2. +++ binutils-2.37/binutils/readelf.c 2021-07-19 12:44:37.712728732 +0100
  3. @@ -21873,45 +21873,52 @@ process_file (char * file_name)
  4. struct stat statbuf;
  5. char armag[SARMAG];
  6. bool ret = true;
  7. + char * name;
  8. + char * saved_program_name;
  9. +
  10. + /* Overload program_name to include file_name. Doing this means
  11. + that warning/error messages will positively identify the file
  12. + concerned even when multiple instances of readelf are running. */
  13. + name = xmalloc (strlen (program_name) + strlen (file_name) + 3);
  14. + sprintf (name, "%s: %s", program_name, file_name);
  15. + saved_program_name = program_name;
  16. + program_name = name;
  17. if (stat (file_name, &statbuf) < 0)
  18. {
  19. if (errno == ENOENT)
  20. - error (_("'%s': No such file\n"), file_name);
  21. + error (_("No such file\n"));
  22. else
  23. - error (_("Could not locate '%s'. System error message: %s\n"),
  24. - file_name, strerror (errno));
  25. - return false;
  26. + error (_("Could not locate file. System error message: %s\n"),
  27. + strerror (errno));
  28. + goto done;
  29. }
  30. if (! S_ISREG (statbuf.st_mode))
  31. {
  32. - error (_("'%s' is not an ordinary file\n"), file_name);
  33. - return false;
  34. + error (_("Not an ordinary file\n"));
  35. + goto done;
  36. }
  37. filedata = calloc (1, sizeof * filedata);
  38. if (filedata == NULL)
  39. {
  40. error (_("Out of memory allocating file data structure\n"));
  41. - return false;
  42. + goto done;
  43. }
  44. filedata->file_name = file_name;
  45. filedata->handle = fopen (file_name, "rb");
  46. if (filedata->handle == NULL)
  47. {
  48. - error (_("Input file '%s' is not readable.\n"), file_name);
  49. - free (filedata);
  50. - return false;
  51. + error (_("Not readable\n"));
  52. + goto done;
  53. }
  54. if (fread (armag, SARMAG, 1, filedata->handle) != 1)
  55. {
  56. - error (_("%s: Failed to read file's magic number\n"), file_name);
  57. - fclose (filedata->handle);
  58. - free (filedata);
  59. - return false;
  60. + error (_("Failed to read file's magic number\n"));
  61. + goto done;
  62. }
  63. filedata->file_size = (bfd_size_type) statbuf.st_size;
  64. @@ -21919,33 +21926,39 @@ process_file (char * file_name)
  65. if (memcmp (armag, ARMAG, SARMAG) == 0)
  66. {
  67. - if (! process_archive (filedata, false))
  68. - ret = false;
  69. + if (process_archive (filedata, false))
  70. + ret = true;
  71. }
  72. else if (memcmp (armag, ARMAGT, SARMAG) == 0)
  73. {
  74. - if ( ! process_archive (filedata, true))
  75. - ret = false;
  76. + if (process_archive (filedata, true))
  77. + ret = true;
  78. }
  79. else
  80. {
  81. if (do_archive_index && !check_all)
  82. - error (_("File %s is not an archive so its index cannot be displayed.\n"),
  83. - file_name);
  84. + error (_("Not an archive so its index cannot be displayed.\n"));
  85. rewind (filedata->handle);
  86. filedata->archive_file_size = filedata->archive_file_offset = 0;
  87. - if (! process_object (filedata))
  88. - ret = false;
  89. + if (process_object (filedata))
  90. + ret = true;
  91. }
  92. - fclose (filedata->handle);
  93. - free (filedata->section_headers);
  94. - free (filedata->program_headers);
  95. - free (filedata->string_table);
  96. - free (filedata->dump.dump_sects);
  97. - free (filedata);
  98. + done:
  99. + if (filedata)
  100. + {
  101. + if (filedata->handle != NULL)
  102. + fclose (filedata->handle);
  103. + free (filedata->section_headers);
  104. + free (filedata->program_headers);
  105. + free (filedata->string_table);
  106. + free (filedata->dump.dump_sects);
  107. + free (filedata);
  108. + }
  109. + free (program_name);
  110. + program_name = saved_program_name;
  111. free (ba_cache.strtab);
  112. ba_cache.strtab = NULL;
  113. --- binutils.orig/binutils/readelf.c 2021-08-10 10:15:22.088016072 +0100
  114. +++ binutils-2.37/binutils/readelf.c 2021-08-10 10:15:55.567907891 +0100
  115. @@ -21884,7 +21884,7 @@ process_file (char * file_name)
  116. Filedata * filedata = NULL;
  117. struct stat statbuf;
  118. char armag[SARMAG];
  119. - bool ret = true;
  120. + bool ret = false;
  121. char * name;
  122. char * saved_program_name;