[lld] r176310 - [ELF][x86-64] Only emit a PLT entry for a PLT relocation if the target atom is a SharedLibraryAtom.
Michael J. Spencer
bigcheesegs at gmail.com
Thu Feb 28 16:03:57 PST 2013
Author: mspencer
Date: Thu Feb 28 18:03:56 2013
New Revision: 176310
URL: http://llvm.org/viewvc/llvm-project?rev=176310&view=rev
Log:
[ELF][x86-64] Only emit a PLT entry for a PLT relocation if the target atom is a SharedLibraryAtom.
This seems to be what ld does, but I'm not sure how it works with symbol interposition.
With this hello-world with glibc dynamically linked works.
Added:
lld/trunk/test/elf/Inputs/relocs-dynamic.x86-64
lld/trunk/test/elf/Inputs/x86-64-relocs.S
lld/trunk/test/elf/x86-64-dynamic-relocs.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp?rev=176310&r1=176309&r2=176310&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp Thu Feb 28 18:03:56 2013
@@ -399,7 +399,8 @@ public:
if (const DefinedAtom *da = dyn_cast_or_null<const DefinedAtom>(ref.target()))
if (da->contentType() == DefinedAtom::typeResolver)
return handleIFUNC(ref);
- const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target()));
+ if (isa<const SharedLibraryAtom>(ref.target()))
+ const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target()));
return error_code::success();
}
Added: lld/trunk/test/elf/Inputs/relocs-dynamic.x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/relocs-dynamic.x86-64?rev=176310&view=auto
==============================================================================
Binary files lld/trunk/test/elf/Inputs/relocs-dynamic.x86-64 (added) and lld/trunk/test/elf/Inputs/relocs-dynamic.x86-64 Thu Feb 28 18:03:56 2013 differ
Added: lld/trunk/test/elf/Inputs/x86-64-relocs.S
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/x86-64-relocs.S?rev=176310&view=auto
==============================================================================
--- lld/trunk/test/elf/Inputs/x86-64-relocs.S (added)
+++ lld/trunk/test/elf/Inputs/x86-64-relocs.S Thu Feb 28 18:03:56 2013
@@ -0,0 +1,12 @@
+ .text
+ .globl main
+ .align 16, 0x90
+ .type main, at function
+main: # @main
+ call foo at PLT
+ ret
+
+ .globl foo
+ .type foo, at function
+foo:
+ ret
Added: lld/trunk/test/elf/x86-64-dynamic-relocs.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/x86-64-dynamic-relocs.test?rev=176310&view=auto
==============================================================================
--- lld/trunk/test/elf/x86-64-dynamic-relocs.test (added)
+++ lld/trunk/test/elf/x86-64-dynamic-relocs.test Thu Feb 28 18:03:56 2013
@@ -0,0 +1,26 @@
+RUN: lld -core -target x86_64-linux %p/Inputs/relocs-dynamic.x86-64 -emit-yaml \
+RUN: -output=- -noinhibit-exec -output-type=dynamic | FileCheck %s
+
+path: <linker-internal>
+defined-atoms:
+ - name: main
+ scope: global
+ content: [ E8, 00, 00, 00, 00, C3 ]
+ alignment: 2^4
+ section-choice: custom-required
+ section-name: .text
+ references:
+ - kind: R_X86_64_PLT32
+ offset: 1
+ target: foo
+ addend: -4
+ - name: foo
+ scope: global
+ content: [ C3 ]
+ alignment: 6 mod 2^4
+ section-choice: custom-required
+ section-name: .text
+
+# Don't generate a PLT/GOT entry for a PLT32 relocation to a non-shared symbol.
+CHECK-NOT: got
+CHECK-NOT: stub
More information about the llvm-commits
mailing list