From: Alan Modra Date: Fri, 2 Nov 2018 02:34:31 +0000 (+1030) Subject: Squash readelf warning on zero sh_link reloc section X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=285e3f99c77510344021b1252c594b28fe7971e8;p=binutils-gdb.git Squash readelf warning on zero sh_link reloc section On readelf examining a static executable built with current glibc, we get a silly warning. Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .note.ABI-tag NOTE 0000000000400190 000190 000020 00 A 0 0 4 [ 2] .note.gnu.build-id NOTE 00000000004001b0 0001b0 000024 00 A 0 0 4 readelf: Warning: [ 3]: Link field (0) should index a symtab section. [ 3] .rela.plt RELA 00000000004001d8 0001d8 000228 18 AI 0 20 8 This .rela.plt section contains only IRELATIVE relocations (which have symbol index zero), so it isn't appropriate to warn. A zero sh_link section is deliberately chosen for such a section (see PR10337 and PR23850). So this patch disables the SHT_REL* sh_link warning. I've also removed the .rel.dyn/.rela.dyn section name test to disable the sh_info warning for SHT_REL* sections. While relocation sections in an executable need not specify the section they relocate (the relocation sh_offset field is an address, not a section offset), that isn't true in a relocatable file where sh_offset is relative to a section. If .rela.dyn happens to exist in an ET_REL object it must specify a valid section. * readelf.c (process_section_headers): Don't warn on a zero sh_info or sh_link for any reloc section in an executable or shared library. Do warn for .rel.dyn/.rela.dyn in ET_REL. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 8404b670c99..662ee24adc6 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2018-11-02 Alan Modra + + * readelf.c (process_section_headers): Don't warn on a zero + sh_info or sh_link for any reloc section in an executable or + shared library. Do warn for .rel.dyn/.rela.dyn in ET_REL. + 2018-11-01 Thomas Preud'homme * testsuite/config/default.exp: Define LD, LDFLAGS and diff --git a/binutils/readelf.c b/binutils/readelf.c index d8d0d6e9546..39744009ab7 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -6299,14 +6299,21 @@ process_section_headers (Filedata * filedata) /* Check the sh_link field. */ switch (section->sh_type) { + case SHT_REL: + case SHT_RELA: + if (section->sh_link == 0 + && (filedata->file_header.e_type == ET_EXEC + || filedata->file_header.e_type == ET_DYN)) + /* A dynamic relocation section where all entries use a + zero symbol index need not specify a symtab section. */ + break; + /* Fall through. */ case SHT_SYMTAB_SHNDX: case SHT_GROUP: case SHT_HASH: case SHT_GNU_HASH: case SHT_GNU_versym: - case SHT_REL: - case SHT_RELA: - if (section->sh_link < 1 + if (section->sh_link == 0 || section->sh_link >= filedata->file_header.e_shnum || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM)) @@ -6320,7 +6327,7 @@ process_section_headers (Filedata * filedata) case SHT_GNU_verneed: case SHT_GNU_verdef: case SHT_GNU_LIBLIST: - if (section->sh_link < 1 + if (section->sh_link == 0 || section->sh_link >= filedata->file_header.e_shnum || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB) warn (_("[%2u]: Link field (%u) should index a string section.\n"), @@ -6353,7 +6360,13 @@ process_section_headers (Filedata * filedata) { case SHT_REL: case SHT_RELA: - if (section->sh_info < 1 + if (section->sh_info == 0 + && (filedata->file_header.e_type == ET_EXEC + || filedata->file_header.e_type == ET_DYN)) + /* Dynamic relocations apply to segments, so they do not + need to specify the section they relocate. */ + break; + if (section->sh_info == 0 || section->sh_info >= filedata->file_header.e_shnum || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS @@ -6363,21 +6376,8 @@ process_section_headers (Filedata * filedata) && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY /* FIXME: Are other section types valid ? */ && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS)) - { - if (section->sh_info == 0 - && (filedata->file_header.e_type == ET_EXEC - || filedata->file_header.e_type == ET_DYN - /* These next two tests may be redundant, but - they have been left in for paranoia's sake. */ - || streq (SECTION_NAME (section), ".rel.dyn") - || streq (SECTION_NAME (section), ".rela.dyn"))) - /* Dynamic relocations apply to segments, not sections, so - they do not need an sh_info value. */ - ; - else - warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), - i, section->sh_info); - } + warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), + i, section->sh_info); break; case SHT_DYNAMIC: