readelf.c display_lto_symtab offset outside bounds of constant string
authorAlan Modra <amodra@gmail.com>
Tue, 20 Oct 2020 04:29:40 +0000 (14:59 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 20 Oct 2020 07:33:19 +0000 (18:03 +1030)
commitb9e920ecd6f65bd37917b2f9e6d3fed9c8a60f66
tree96973238c3e2fd9ef143ee1efd73308f6a78951d
parentce786647f0c54c9ca61bb6790a1d52a1c4781f82
readelf.c display_lto_symtab offset outside bounds of constant string

Using gcc-10 or current mainline gcc, binutils configured with
--disable-nls results in:

readelf.c: In function 'display_lto_symtab':
readelf.c:12283:26: error: offset '17' outside bounds of constant string [-Werror=array-bounds]
12283 |   SECTION_NAME (section) + strlen (".gnu.lto_.symtab.")) > 0
      |                          ^

Which is actually a bogus warning in this case because we've already
checked the name string for validity, so SECTION_NAME won't ever be
"<none>", "<no-strings>" or "<corrupt>".  This patch fixes the problem
by making SECTION_NAME simply return the string from the string table.
Other places also shouldn't be trying to match any of the error
strings against a section name, so fix them too.

* readelf.c: Delete whitespace at end of line throughout.
(SECTION_NAME, SECTION_NAME_VALID): New.
(SECTION_NAME_PRINT): Rename from SECTION_NAME.  Formatting.
(printable_section_name, dump_relocations): Use SECTION_NAME_PRINT.
(process_section_headers, process_section_groups): Likewise.
(shdr_to_ctf_sect): Likewise.
(find_section, find_section_in_set): Use SECTION_NAME_VALID.
(ia64_process_unwind, hppa_process_unwind): Likewise.
(display_debug_section, initialise_dumps_byname): Likewise.
(process_lto_symbol_tables): Likewise.  Check trailing period of
lto symbol table names.
(display_lto_symtab): Use sizeof instead of strlen.
binutils/ChangeLog
binutils/readelf.c