Bug 18169 - sh_info of .rel.plt/.rela.plt sections isn't correct
Summary: sh_info of .rel.plt/.rela.plt sections isn't correct
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.26
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-26 16:56 UTC by H.J. Lu
Modified: 2015-03-30 11:46 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2015-03-26 16:56:26 UTC
gABI says that sh_info of SHT_REL/SHT_RELA sections has the section header
index of the section to which the relocation applies.


[hjl@gnu-tools-1 rel]$ cat x.c
extern void bar (void);

void
foo ()
{
  bar ();
}
[hjl@gnu-tools-1 rel]$ make
cc -m32 -O2 -fPIC   -c -o x.o x.c
./ld -m elf_i386 --emit-relocs -shared -o x.so x.o
readelf -SW x.so #| grep REL
There are 18 section headers, starting at offset 0x540:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .hash             HASH            000000b4 0000b4 00002c 04   A  2   0  4
  [ 2] .dynsym           DYNSYM          000000e0 0000e0 000060 10   A  3   1  4
  [ 3] .dynstr           STRTAB          00000140 000140 000021 00   A  0   0  1
  [ 4] .rel.plt          REL             00000164 000164 000008 08  AI  2   5  4
  [ 5] .plt              PROGBITS        00000170 000170 000020 04  AX  0   0 16
  [ 6] .text             PROGBITS        00000190 000190 00001d 00  AX  0   0 16
  [ 7] .rel.text         REL             00000000 000518 000018 08   I 16   6  4
  [ 8] .eh_frame         PROGBITS        000001b0 0001b0 000070 00   A  0   0  4
  [ 9] .rel.eh_frame     REL             00000000 000530 000010 08   I 16   8  4
  [10] .dynamic          DYNAMIC         00001220 000220 000078 08  WA  3   0  4
  [11] .got.plt          PROGBITS        00001298 000298 000010 04  WA  0   0  4
  [12] .data             PROGBITS        000012a8 0002a8 000000 00  WA  0   0  1
  [13] .bss              NOBITS          000012a8 0002a8 000000 00  WA  0   0  1
  [14] .comment          PROGBITS        00000000 0002a8 00002c 01  MS  0   0  1
  [15] .shstrtab         STRTAB          00000000 0002d4 000078 00      0   0  1
  [16] .symtab           SYMTAB          00000000 00034c 000170 10     17  18  4
  [17] .strtab           STRTAB          00000000 0004bc 00005a 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
[hjl@gnu-tools-1 rel]$ 

sh_info of .rel.plt is 5 which points to .plt section. It should be 0.
Comment 1 Sourceware Commits 2015-03-30 11:42:03 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bd53a53af486c6e5ab88b7f64342244392be1f1f

commit bd53a53af486c6e5ab88b7f64342244392be1f1f
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Mar 30 04:40:33 2015 -0700

    Properly set sh_info for .rela.plt/rel.plt section
    
    Since .rela.plt/rel.plt section may contain relocations against .got.plt
    section, we set sh_info for .rela.plt/rel.plt section to .got.plt section
    index if target has .got.plt section.
    
    bfd/
    
    	PR ld/18169
    	* elf-bfd.h (elf_backend_data): Add get_reloc_section.
    	(_bfd_elf_get_reloc_section): New.
    	* elf.c (_bfd_elf_get_reloc_section): Likewise.
    	(assign_section_numbers): Call get_reloc_section to look up the
    	section the relocs apply.
    	* elfxx-target.h (elf_backend_get_reloc_section): Likewise.
    	(elfNN_bed): Initialize get_reloc_section with
    	elf_backend_get_reloc_section.
    
    ld/testsuite/
    
    	PR ld/18169
    	* ld-elf/linkinfo1a.d: Updated.
    	* ld-elf/linkinfo1b.d: Likewise.
Comment 2 H.J. Lu 2015-03-30 11:46:58 UTC
Fixed.