[lld] r176324 - [Writer][ELF][x86-64] Handle GOTPCREL relocations to SharedLibraryAtoms.

Michael J. Spencer bigcheesegs at gmail.com
Thu Feb 28 17:09:47 PST 2013


Author: mspencer
Date: Thu Feb 28 19:09:46 2013
New Revision: 176324

URL: http://llvm.org/viewvc/llvm-project?rev=176324&view=rev
Log:
[Writer][ELF][x86-64] Handle GOTPCREL relocations to SharedLibraryAtoms.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
    lld/trunk/test/elf/Inputs/shared.c
    lld/trunk/test/elf/Inputs/shared.so-x86-64
    lld/trunk/test/elf/Inputs/use-shared.c
    lld/trunk/test/elf/Inputs/use-shared.x86-64
    lld/trunk/test/elf/dynamic.test
    lld/trunk/test/elf/x86-64-dynamic.test

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=176324&r1=176323&r2=176324&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 19:09:46 2013
@@ -409,6 +409,31 @@ public:
       return handlePLT32(ref);
     return handleIFUNC(ref);
   }
+
+  const GOTAtom *getSharedGOT(const SharedLibraryAtom *sla) {
+    auto got = _gotMap.find(sla);
+    if (got == _gotMap.end()) {
+      auto g = new (_file._alloc) GOTAtom(_file, ".got.dyn");
+      g->addReference(R_X86_64_GLOB_DAT, 0, sla, 0);
+#ifndef NDEBUG
+      g->_name = "__got_";
+      g->_name += sla->name();
+#endif
+      _gotMap[sla] = g;
+      return g;
+    }
+    return got->second;
+  }
+
+  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));
+    else if (const auto sla = dyn_cast<const SharedLibraryAtom>(ref.target()))
+      const_cast<Reference &>(ref).setTarget(getSharedGOT(sla));
+  }
 };
 } // end anon namespace
 

Modified: lld/trunk/test/elf/Inputs/shared.c
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/shared.c?rev=176324&r1=176323&r2=176324&view=diff
==============================================================================
--- lld/trunk/test/elf/Inputs/shared.c (original)
+++ lld/trunk/test/elf/Inputs/shared.c Thu Feb 28 19:09:46 2013
@@ -1,5 +1,8 @@
 #include <stdio.h>
 
+extern int i;
+int i = 42;
+
 void foo() {
   puts("Fooo!!");
 }

Modified: lld/trunk/test/elf/Inputs/shared.so-x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/shared.so-x86-64?rev=176324&r1=176323&r2=176324&view=diff
==============================================================================
Binary files lld/trunk/test/elf/Inputs/shared.so-x86-64 (original) and lld/trunk/test/elf/Inputs/shared.so-x86-64 Thu Feb 28 19:09:46 2013 differ

Modified: lld/trunk/test/elf/Inputs/use-shared.c
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/use-shared.c?rev=176324&r1=176323&r2=176324&view=diff
==============================================================================
--- lld/trunk/test/elf/Inputs/use-shared.c (original)
+++ lld/trunk/test/elf/Inputs/use-shared.c Thu Feb 28 19:09:46 2013
@@ -1,5 +1,7 @@
+extern int i;
 void foo();
 
 int main() {
   foo();
+  return i;
 }

Modified: lld/trunk/test/elf/Inputs/use-shared.x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/use-shared.x86-64?rev=176324&r1=176323&r2=176324&view=diff
==============================================================================
Binary files lld/trunk/test/elf/Inputs/use-shared.x86-64 (original) and lld/trunk/test/elf/Inputs/use-shared.x86-64 Thu Feb 28 19:09:46 2013 differ

Modified: lld/trunk/test/elf/dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/dynamic.test?rev=176324&r1=176323&r2=176324&view=diff
==============================================================================
--- lld/trunk/test/elf/dynamic.test (original)
+++ lld/trunk/test/elf/dynamic.test Thu Feb 28 19:09:46 2013
@@ -28,22 +28,26 @@ CHECK: flags r--
 
 CHECK: Dynamic Symbols:
 CHECK:   foo FUNC {{[0-9a-f]+}} 0 {{[0-9a-f]+}} undef,global
-CHECK:   Total: 1
+CHECK:   i FUNC {{[0-9a-f]+}} 0 {{[0-9a-f]+}} undef,global
+CHECK:   Total: 2
 
 CHECK: Sections:
 CHECK:   .hash {{[0-9a-f]+}} 8 4 required,rodata
 
-CHECK: Dynamic section contains 11 entries
+CHECK: Dynamic section contains 14 entries
 CHECK:   Tag                Type                 Name/Value
 CHECK:  0x0000000000000004 (HASH)
 CHECK:  0x0000000000000005 (STRTAB)
 CHECK:  0x0000000000000006 (SYMTAB)
 CHECK:  0x000000000000000a (STRSZ)
 CHECK:  0x000000000000000b (SYMENT) 24
+CHECK:  0x0000000000000007 (RELA)
+CHECK:  0x0000000000000008 (RELASZ) 24
+CHECK:  0x0000000000000009 (RELAENT) 24
 CHECK:  0x0000000000000002 (PLTRELSZ) 24
 CHECK:  0x0000000000000003 (PLTGOT)
 CHECK:  0x0000000000000014 (PLTREL) RELA
 CHECK:  0x0000000000000017 (JMPREL)
 CHECK:  0x0000000000000001 (NEEDED) Shared library: [shared.so-x86-64]
 CHECK:  0x0000000000000000 (NULL)               0x0
-CHECK:   Total: 11
+CHECK:   Total: 14

Modified: lld/trunk/test/elf/x86-64-dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/x86-64-dynamic.test?rev=176324&r1=176323&r2=176324&view=diff
==============================================================================
--- lld/trunk/test/elf/x86-64-dynamic.test (original)
+++ lld/trunk/test/elf/x86-64-dynamic.test Thu Feb 28 19:09:46 2013
@@ -25,6 +25,16 @@ CHECK:    alignment:       2^3
 CHECK:    section-choice:  custom-required
 CHECK:    section-name:    .got.plt
 CHECK:    permissions:     rw-
+        - name:            __got_i
+CHECK:    type:            got
+CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
+CHECK:    section-choice:  custom-required
+CHECK:    section-name:    .got.dyn
+CHECK:    permissions:     rw-
+CHECK:    references:
+CHECK:      - kind:            R_X86_64_GLOB_DAT
+CHECK:        offset:          0
+CHECK:        target:          i
         - name:            __got_foo
 CHECK:    type:            got
 CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
@@ -45,9 +55,13 @@ CHECK:  - name:            main
 CHECK:    scope:           global
 CHECK:    references:
 CHECK:      - kind:            R_X86_64_PC32
-CHECK:        offset:          7
+CHECK:        offset:          18
               target:          __plt_foo
 CHECK:        addend:          -4
+CHECK:     - kind:            R_X86_64_PC32
+CHECK:        offset:          25
+              target:          __got_i
+CHECK:        addend:          -4
 
         - name:            .PLT0
 CHECK:    type:            stub





More information about the llvm-commits mailing list