[lld] r174426 - [ELF] Implement GOTPCREL for defined atoms.
Michael J. Spencer
bigcheesegs at gmail.com
Tue Feb 5 11:14:29 PST 2013
Author: mspencer
Date: Tue Feb 5 13:14:28 2013
New Revision: 174426
URL: http://llvm.org/viewvc/llvm-project?rev=174426&view=rev
Log:
[ELF] Implement GOTPCREL for defined atoms.
Added:
lld/trunk/test/elf/Inputs/gotpcrel.S
- copied, changed from r174425, lld/trunk/test/elf/Inputs/undef-gotpcrel.S
lld/trunk/test/elf/Inputs/gotpcrel.x86-64
lld/trunk/test/elf/gotpcrel.test
- copied, changed from r174425, lld/trunk/test/elf/undef-gotpcrel.test
Removed:
lld/trunk/test/elf/Inputs/undef-gotpcrel.S
lld/trunk/test/elf/Inputs/undef-gotpcrel.x86-64
lld/trunk/test/elf/undef-gotpcrel.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=174426&r1=174425&r2=174426&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp Tue Feb 5 13:14:28 2013
@@ -152,11 +152,8 @@ class GOTPLTPass LLVM_FINAL : public Pas
if (da)
handleGOTTPOFF(ref, *da);
break;
- case R_X86_64_GOTPCREL: // GOTPCREL to an undefined weak symbol.
- // Always convert it to a non-got reference.
- const_cast<Reference &>(ref).setKind(R_X86_64_PC32);
- if (isa<const UndefinedAtom>(ref.target()))
- handleUndefGOTPCREL(ref);
+ case R_X86_64_GOTPCREL:
+ handleGOTPCREL(ref);
break;
}
}
@@ -225,10 +222,29 @@ class GOTPLTPass LLVM_FINAL : public Pas
return _null;
}
+ const GOTAtom *getGOT(const DefinedAtom &da) {
+ auto got = _gotMap.find(&da);
+ if (got == _gotMap.end()) {
+ auto g = new (_file._alloc) GOTAtom(_file, ".got");
+ g->addReference(R_X86_64_64, 0, &da, 0);
+#ifndef NDEBUG
+ g->_name = "__got_";
+ g->_name += da.name();
+#endif
+ _gotMap[&da] = g;
+ return g;
+ }
+ return got->second;
+ }
+
/// \brief Handle a GOTPCREL relocation to an undefined weak atom by using a
/// null GOT entry.
- void handleUndefGOTPCREL(const Reference &ref) {
- const_cast<Reference &>(ref).setTarget(getNullGOT());
+ void handleGOTPCREL(const Reference &ref) {
+ const_cast<Reference &>(ref).setKind(R_X86_64_PC32);
+ if (isa<UndefinedAtom>(ref.target()))
+ const_cast<Reference &>(ref).setTarget(getNullGOT());
+ else if (const DefinedAtom *da = dyn_cast<const DefinedAtom>(ref.target()))
+ const_cast<Reference &>(ref).setTarget(getGOT(*da));
}
public:
Copied: lld/trunk/test/elf/Inputs/gotpcrel.S (from r174425, lld/trunk/test/elf/Inputs/undef-gotpcrel.S)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/gotpcrel.S?p2=lld/trunk/test/elf/Inputs/gotpcrel.S&p1=lld/trunk/test/elf/Inputs/undef-gotpcrel.S&r1=174425&r2=174426&rev=174426&view=diff
==============================================================================
--- lld/trunk/test/elf/Inputs/undef-gotpcrel.S (original)
+++ lld/trunk/test/elf/Inputs/gotpcrel.S Tue Feb 5 13:14:28 2013
@@ -4,6 +4,7 @@
.type main, at function
main: # @main
movq blah at GOTPCREL(%rip), %rax
+ movq main at GOTPCREL(%rip), %rax
ret
.weak blah
Added: lld/trunk/test/elf/Inputs/gotpcrel.x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/gotpcrel.x86-64?rev=174426&view=auto
==============================================================================
Binary files lld/trunk/test/elf/Inputs/gotpcrel.x86-64 (added) and lld/trunk/test/elf/Inputs/gotpcrel.x86-64 Tue Feb 5 13:14:28 2013 differ
Removed: lld/trunk/test/elf/Inputs/undef-gotpcrel.S
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/undef-gotpcrel.S?rev=174425&view=auto
==============================================================================
--- lld/trunk/test/elf/Inputs/undef-gotpcrel.S (original)
+++ lld/trunk/test/elf/Inputs/undef-gotpcrel.S (removed)
@@ -1,10 +0,0 @@
- .text
- .globl main
- .align 16, 0x90
- .type main, at function
-main: # @main
- movq blah at GOTPCREL(%rip), %rax
- ret
-
- .weak blah
- .type blah, at function
Removed: lld/trunk/test/elf/Inputs/undef-gotpcrel.x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/undef-gotpcrel.x86-64?rev=174425&view=auto
==============================================================================
Binary files lld/trunk/test/elf/Inputs/undef-gotpcrel.x86-64 (original) and lld/trunk/test/elf/Inputs/undef-gotpcrel.x86-64 (removed) differ
Copied: lld/trunk/test/elf/gotpcrel.test (from r174425, lld/trunk/test/elf/undef-gotpcrel.test)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/gotpcrel.test?p2=lld/trunk/test/elf/gotpcrel.test&p1=lld/trunk/test/elf/undef-gotpcrel.test&r1=174425&r2=174426&rev=174426&view=diff
==============================================================================
--- lld/trunk/test/elf/undef-gotpcrel.test (original)
+++ lld/trunk/test/elf/gotpcrel.test Tue Feb 5 13:14:28 2013
@@ -1,10 +1,17 @@
RUN: lld -core -target x86_64-linux -output=- -entry=main \
-RUN: %p/Inputs/undef-gotpcrel.x86-64 -emit-yaml -noinhibit-exec \
+RUN: %p/Inputs/gotpcrel.x86-64 -emit-yaml -noinhibit-exec \
RUN: | FileCheck %s -check-prefix=YAML
YAML: name: main
YAML: kind: R_X86_64_PC32
YAML: target: [[NULLGOT:[a-zA-Z0-9_]+]]
+YAML: kind: R_X86_64_PC32
+YAML: target: [[MAINGOT:[a-zA-Z0-9_]+]]
YAML: name: [[NULLGOT]]
YAML: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
+YAML-NOT: references:
+
+YAML: name: [[MAINGOT]]
+YAML: kind: R_X86_64_64
+YAML: target: main
Removed: lld/trunk/test/elf/undef-gotpcrel.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/undef-gotpcrel.test?rev=174425&view=auto
==============================================================================
--- lld/trunk/test/elf/undef-gotpcrel.test (original)
+++ lld/trunk/test/elf/undef-gotpcrel.test (removed)
@@ -1,10 +0,0 @@
-RUN: lld -core -target x86_64-linux -output=- -entry=main \
-RUN: %p/Inputs/undef-gotpcrel.x86-64 -emit-yaml -noinhibit-exec \
-RUN: | FileCheck %s -check-prefix=YAML
-
-YAML: name: main
-YAML: kind: R_X86_64_PC32
-YAML: target: [[NULLGOT:[a-zA-Z0-9_]+]]
-
-YAML: name: [[NULLGOT]]
-YAML: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
More information about the llvm-commits
mailing list