[ELF][x86-64] Fix ifunc and add test.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Fri, 1 Feb 2013 09:14:21 +0000 (09:14 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Fri, 1 Feb 2013 09:14:21 +0000 (09:14 +0000)
In an previous commit I managed to completely disable the IRELATIVE relocation
writing code. I also used the wrong addend for the static relocation. Fix both
these issues and add a test. This test is quite brittle because there's no way
to do arithmetic on variables in FileCheck.

llvm-svn: 174161

lld/lib/ReaderWriter/ELF/DefaultLayout.h
lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
lld/test/elf/ifunc.test

index 76e55e2..9358a79 100644 (file)
@@ -442,11 +442,11 @@ ErrorOr<const AtomLayout &> DefaultLayout<ELFT>::addAtom(const Atom *atom) {
     } else {
       section = _sectionMap[sectionKey];
     }
-    return section->appendAtom(atom);
     // Add runtime relocations to the .rela section.
     for (const auto &reloc : *definedAtom)
       if (_targetInfo.isRuntimeRelocation(*definedAtom, *reloc))
         getRelocationTable()->addRelocation(*definedAtom, *reloc);
+    return section->appendAtom(atom);
   } else if (const AbsoluteAtom *absoluteAtom = dyn_cast<AbsoluteAtom>(atom)) {
     // Absolute atoms are not part of any section, they are global for the whole
     // link
index 3a4dee7..ead1277 100644 (file)
@@ -157,7 +157,7 @@ class GOTPLTPass LLVM_FINAL : public Pass {
     auto ga = new (_file._alloc) GOTAtom(_file, ".got.plt");
     ga->addReference(R_X86_64_IRELATIVE, 0, &da, 0);
     auto pa = new (_file._alloc) PLTAtom(_file, ".plt");
-    pa->addReference(R_X86_64_PC32, 2, ga, 0);
+    pa->addReference(R_X86_64_PC32, 2, ga, -4);
 #ifndef NDEBUG
     ga->_name = "__got_ifunc_";
     ga->_name += da.name();
index 595a880..e1a5d7b 100644 (file)
@@ -1,8 +1,13 @@
 RUN: lld -core -target x86_64-linux -emit-yaml -output=- %p/Inputs/ifunc.x86-64 \
 RUN: | FileCheck %s
+
 RUN: lld -core -target x86_64-linux -emit-yaml -output=- %p/Inputs/ifunc.x86-64 \
 RUN: %p/Inputs/ifunc.cpp.x86-64 | FileCheck %s --check-prefix=PLT
 
+RUN: lld -core -target x86_64-linux -output=%t %p/Inputs/ifunc.x86-64 \
+RUN: %p/Inputs/ifunc.cpp.x86-64 && llvm-objdump -d %t| FileCheck %s \
+RUN:   --check-prefix=BIN
+
 CHECK: name: hey
 CHECK: scope: global
 CHECK: type: resolver
@@ -25,3 +30,9 @@ PLT: name: [[PLTNAME]]
 PLT: type: stub
 PLT: references
 PLT: kind: R_X86_64_PC32
+
+// This is a horribly brittle test. We need a way to do arithmetic on captured
+// variables.
+BIN: 400136: ff 25 c4 0e 00 00 jumpq *3780(%rip)
+BIN: .got.plt:
+BIN-NEXT: 401000 00000000 00000000