[lld] r174161 - [ELF][x86-64] Fix ifunc and add test.

Michael J. Spencer bigcheesegs at gmail.com
Fri Feb 1 01:14:21 PST 2013


Author: mspencer
Date: Fri Feb  1 03:14:21 2013
New Revision: 174161

URL: http://llvm.org/viewvc/llvm-project?rev=174161&view=rev
Log:
[ELF][x86-64] Fix ifunc and add test.

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.

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

Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=174161&r1=174160&r2=174161&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Fri Feb  1 03:14:21 2013
@@ -442,11 +442,11 @@ ErrorOr<const AtomLayout &> DefaultLayou
     } 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

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=174161&r1=174160&r2=174161&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp Fri Feb  1 03:14:21 2013
@@ -157,7 +157,7 @@ class GOTPLTPass LLVM_FINAL : public Pas
     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();

Modified: lld/trunk/test/elf/ifunc.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ifunc.test?rev=174161&r1=174160&r2=174161&view=diff
==============================================================================
--- lld/trunk/test/elf/ifunc.test (original)
+++ lld/trunk/test/elf/ifunc.test Fri Feb  1 03:14:21 2013
@@ -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





More information about the llvm-commits mailing list