[PATCH] D28612: [ELF] - Added support for --emit-relocs.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 03:01:44 PST 2017


grimar added a comment.

In https://reviews.llvm.org/D28612#644422, @ruiu wrote:

> Did you verify that this output is the same as ld.bfd's output?


Sure I did, 
below is output from bfd:

  Section Headers:
    [Nr] Name              Type             Address           Offset
         Size              EntSize          Flags  Link  Info  Align
    [ 0]                   NULL             0000000000000000  00000000
         0000000000000000  0000000000000000           0     0     0
    [ 1] .text             PROGBITS         0000000000400078  00000078
         0000000000000018  0000000000000000  AX       0     0     4
    [ 2] .rela.text        RELA             0000000000000000  000001f0
         0000000000000060  0000000000000018   I       4     1     8
    [ 3] .shstrtab         STRTAB           0000000000000000  00000250
         0000000000000026  0000000000000000           0     0     1
    [ 4] .symtab           SYMTAB           0000000000000000  00000090
         0000000000000108  0000000000000018           5     6     8
    [ 5] .strtab           STRTAB           0000000000000000  00000198
         0000000000000052  0000000000000000           0     0     1
  
  Relocation section '.rela.text' at offset 0x1f0 contains 4 entries:
    Offset          Info           Type           Sym. Value    Sym. Name + Addend
  00000040007a  00010000000a R_X86_64_32       0000000000400078 .text + 1
  00000040007f  000a00000004 R_X86_64_PLT32    0000000000400078 fn - 4
  000000400086  00010000000a R_X86_64_32       0000000000400078 .text + d
  00000040008b  000700000004 R_X86_64_PLT32    0000000000400084 fn2 - 4
  
  Symbol table '.symtab' contains 11 entries:
     Num:    Value          Size Type    Bind   Vis      Ndx Name
       0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
       1: 0000000000400078     0 SECTION LOCAL  DEFAULT    1 
       2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS emit-relocs.s.tmp1.o
       3: 0000000000400079     0 NOTYPE  LOCAL  DEFAULT    1 bar
       4: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS emit-relocs.s.tmp2.o
       5: 0000000000400085     0 NOTYPE  LOCAL  DEFAULT    1 foo
       6: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT    1 __bss_start
       7: 0000000000400084     0 FUNC    GLOBAL DEFAULT    1 fn2
       8: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT    1 _edata
       9: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT    1 _end
      10: 0000000000400078     0 FUNC    GLOBAL DEFAULT    1 fn

and our output:

  Section Headers:
    [Nr] Name              Type             Address           Offset
         Size              EntSize          Flags  Link  Info  Align
    [ 0]                   NULL             0000000000000000  00000000
         0000000000000000  0000000000000000           0     0     0
    [ 1] .text             PROGBITS         0000000000201000  00001000
         0000000000000018  0000000000000000  AX       0     0     4
    [ 2] .rela.text        RELA             0000000000000000  00001018
         0000000000000060  0000000000000018           4     1     8
    [ 3] .comment          PROGBITS         0000000000000000  00001078
         0000000000000012  0000000000000001  MS       0     0     1
    [ 4] .symtab           SYMTAB           0000000000000000  00001090
         00000000000000a8  0000000000000018           6     5     8
    [ 5] .shstrtab         STRTAB           0000000000000000  00001138
         0000000000000035  0000000000000000           0     0     1
    [ 6] .strtab           STRTAB           0000000000000000  0000116d
         0000000000000011  0000000000000000           0     0     1
  
  Relocation section '.rela.text' at offset 0x1018 contains 4 entries:
    Offset          Info           Type           Sym. Value    Sym. Name + Addend
  000000201002  00020000000a R_X86_64_32       0000000000201000  + 1
  000000201007  000500000004 R_X86_64_PLT32    0000000000201000 fn - 4
  00000020100e  00040000000a R_X86_64_32       000000000020100c  + 1
  000000201013  000600000004 R_X86_64_PLT32    000000000020100c fn2 - 4
  
  Symbol table '.symtab' contains 7 entries:
     Num:    Value          Size Type    Bind   Vis      Ndx Name
       0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
       1: 0000000000201001     0 NOTYPE  LOCAL  DEFAULT    1 bar
       2: 0000000000201000     0 SECTION LOCAL  DEFAULT    1 
       3: 000000000020100d     0 NOTYPE  LOCAL  DEFAULT    1 foo
       4: 000000000020100c     0 SECTION LOCAL  DEFAULT    1 
       5: 0000000000201000     0 FUNC    GLOBAL DEFAULT    1 fn
       6: 000000000020100c     0 FUNC    GLOBAL DEFAULT    1 fn2

DIfference that bfd creates 1 section symbol, we create 2 with different values. But final values in '.rela.text' 
are the same after that, so I think that should work fine.

Another difference that bfd marks ".rela.text" section with SHF_INFO_LINK flag (original objects does not have it),
I am not sure if it is critical to have, I think we can try without for now and add it separatelly if we need.


https://reviews.llvm.org/D28612





More information about the llvm-commits mailing list