This is an archive of the discontinued LLVM Phabricator instance.

[llvm-mc] - Produce R_X86_64_PLT32 for "call/jmp foo".
ClosedPublic

Authored by grimar on Feb 16 2018, 6:02 AM.

Details

Summary

This is PR36370,

For instructions like call foo and jmp foo patch changes
relocation produced from R_X86_64_PC32 to R_X86_64_PLT32.
Relocation can be used as a marker for 32-bit PC-relative branches.
Linker will reduce PLT32 relocation to PC32 if function is defined locally.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Feb 16 2018, 6:02 AM
grimar added a subscriber: ikudrin.Feb 16 2018, 6:02 AM
grimar updated this revision to Diff 134632.Feb 16 2018, 8:23 AM
  • NFC update.
grimar updated this revision to Diff 134794.Feb 17 2018, 4:46 AM
  • Addressed commen, added case for call foo@GOTPCREL to basic-elf-64.s.

Does this change add reference to _GLOBAL_OFFSET_TABLE_?

[hjl@gnu-tools-1 tmp]$ cat x.s
call foo
[hjl@gnu-tools-1 tmp]$ cat y.s
call foo@PLT
[hjl@gnu-tools-1 tmp]$ gcc -c x.s y.s
[hjl@gnu-tools-1 tmp]$ readelf -rs x.o y.o

File: x.o

Relocation section '.rela.text' at offset 0xc8 contains 1 entry:

Offset          Info           Type           Sym. Value    Sym. Name + Addend

000000000001 000400000004 R_X86_64_PLT32 0000000000000000 foo - 4

Symbol table '.symtab' contains 5 entries:

Num:    Value          Size Type    Bind   Vis      Ndx Name
  0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
  1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
  2: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
  3: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
  4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo

File: y.o

Relocation section '.rela.text' at offset 0xf8 contains 1 entry:

Offset          Info           Type           Sym. Value    Sym. Name + Addend

000000000001 000500000004 R_X86_64_PLT32 0000000000000000 foo - 4

Symbol table '.symtab' contains 6 entries:

Num:    Value          Size Type    Bind   Vis      Ndx Name
  0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
  1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
  2: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
  3: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
  4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _GLOBAL_OFFSET_TABLE_
  5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo

[hjl@gnu-tools-1 tmp]$

There should be no reference to _GLOBAL_OFFSET_TABLE_ for "call foo".

Does this change add reference to _GLOBAL_OFFSET_TABLE_?

[hjl@gnu-tools-1 tmp]$ cat x.s
call foo
[hjl@gnu-tools-1 tmp]$ cat y.s
call foo@PLT
[hjl@gnu-tools-1 tmp]$ gcc -c x.s y.s
[hjl@gnu-tools-1 tmp]$ readelf -rs x.o y.o

No, I think gas do that, but not llvm-mc (and hence not this patch):

umb@umb-virtual-machine:~/tests_2018/27$ ~/binutils-2.30-branch/binutils-gdb/build/gas/as-new -v
GNU assembler version 2.30.51 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.30.51.20180214
umb@umb-virtual-machine:~/tests_2018/27$ cat > test.s
call foo@PLT
^C
umb@umb-virtual-machine:~/tests_2018/27$ /home/umb/LLVM/build_goldplugin/bin/llvm-mc -filetype=obj -triple=x86_64-pc-linux test.s -o test.mc.o
umb@umb-virtual-machine:~/tests_2018/27$ ~/binutils-2.30-branch/binutils-gdb/build/gas/as-new test.s -o test.gas.o
umb@umb-virtual-machine:~/tests_2018/27$ readelf -s test.mc.o test.gas.o
File: test.mc.o
Symbol table '.symtab' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo

File: test.gas.o
Symbol table '.symtab' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
     4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _GLOBAL_OFFSET_TABLE_
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
grimar edited the summary of this revision. (Show Details)Feb 20 2018, 2:18 AM
This revision was not accepted when it landed; it landed in state Needs Review.Feb 20 2018, 2:22 AM
This revision was automatically updated to reflect the committed changes.