From: Michael J. Spencer Date: Fri, 1 Feb 2013 09:14:21 +0000 (+0000) Subject: [ELF][x86-64] Fix ifunc and add test. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=08b49bf27eeca43fd6a07ff949f96979890494dd;p=platform%2Fupstream%2Fllvm.git [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. llvm-svn: 174161 --- diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index 76e55e2..9358a79 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -442,11 +442,11 @@ ErrorOr DefaultLayout::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(atom)) { // Absolute atoms are not part of any section, they are global for the whole // link diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp index 3a4dee7..ead1277 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp @@ -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(); diff --git a/lld/test/elf/ifunc.test b/lld/test/elf/ifunc.test index 595a880..e1a5d7b 100644 --- a/lld/test/elf/ifunc.test +++ b/lld/test/elf/ifunc.test @@ -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