llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.23k stars 12.07k forks source link

x86: .plt.got is not supported (if R_X86_64_JUMP_SLOT and R_X86_64_GLOB, omit R_X86_64_JUMP_SLOT) #32285

Open hjl-tools opened 7 years ago

hjl-tools commented 7 years ago
Bugzilla Link 32938
Version unspecified
OS Linux
CC @MaskRay,@rui314

Extended Description

[hjl@gnu-6 lld-2]$ cat x.c extern void foo (void);

void * foo_p () { foo (); return foo; } [hjl@gnu-6 lld-2]$ make ./clang -fpic -c -o x.o x.c ./ld.lld --shared -o x.so x.o [hjl@gnu-6 lld-2]$ readelf -r x.so

Relocation section '.rela.dyn' at offset 0x240 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 0000000030d0 000100000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0

Relocation section '.rela.plt' at offset 0x258 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000002018 000100000007 R_X86_64_JUMP_SLO 0000000000000000 foo + 0 [hjl@gnu-6 lld-2]$ ld --shared -o x.so x.o [hjl@gnu-6 lld-2]$ readelf -r x.so

Relocation section '.rela.dyn' at offset 0x240 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000200ff8 000300000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0 [hjl@gnu-6 lld-2]$

hjl-tools commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#48621

MaskRay commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#48621

MaskRay commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#37257

MaskRay commented 5 years ago

Bug llvm/llvm-bugzilla-archive#37257 has been marked as a duplicate of this bug.

llvmbot commented 6 years ago

see pr37257.

llvmbot commented 6 years ago

This has been noticed in the wild.

Also, fixing this might prove a memory saving optimization as no symbol would be both at the .got and .plt.got and we would not need to keep both indexes.

llvmbot commented 7 years ago

We are not going to implement this, according to comments at D37333 review page.

llvmbot commented 7 years ago

Posted draft WIP version of fix here: https://reviews.llvm.org/D37333

llvmbot commented 7 years ago

Bug llvm/llvm-project#28346 has been marked as a duplicate of this bug.

rui314 commented 7 years ago

OK. Mine was GNU ld (GNU Binutils for Ubuntu) 2.24.

hjl-tools commented 7 years ago

Actually I got the same result with ld.bfd. What am I missing?

$ /ssd/clang/bin/clang -fpic -c -o x.o x.c $ ld.bfd --shared -o x.so x.o $ readelf -r x.so

Relocation section '.rela.dyn' at offset 0x220 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000200408 000400000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0

Relocation section '.rela.plt' at offset 0x238 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000200428 000400000007 R_X86_64_JUMP_SLO 0000000000000000 foo + 0

Which ld.bfd were you using? Please try binutils 2.28.

rui314 commented 7 years ago

Actually I got the same result with ld.bfd. What am I missing?

$ /ssd/clang/bin/clang -fpic -c -o x.o x.c $ ld.bfd --shared -o x.so x.o $ readelf -r x.so

Relocation section '.rela.dyn' at offset 0x220 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000200408 000400000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0

Relocation section '.rela.plt' at offset 0x238 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000200428 000400000007 R_X86_64_JUMP_SLO 0000000000000000 foo + 0

hjl-tools commented 7 years ago

What is your lld version? I cannot reproduce the issue.

$ readelf -r x.so

Relocation section '.rela.dyn' at offset 0x240 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 0000000030d0 000100000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0

Relocation section '.rela.plt' at offset 0x258 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000002018 000100000007 R_X86_64_JUMP_SLO 0000000000000000 foo + 0

There is 2 dynamic relocations against the same symbol, foo, for 2 GOT entries. Only one GOT entry and one dynamic relocation are required.

rui314 commented 7 years ago

What is your lld version? I cannot reproduce the issue.

$ readelf -r x.so

Relocation section '.rela.dyn' at offset 0x240 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 0000000030d0 000100000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0

Relocation section '.rela.plt' at offset 0x258 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000002018 000100000007 R_X86_64_JUMP_SLO 0000000000000000 foo + 0