[lld] r247738 - [elf2] Relocate absolute symbols.

Michael J. Spencer via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 16:12:03 PDT 2015


Author: mspencer
Date: Tue Sep 15 18:12:02 2015
New Revision: 247738

URL: http://llvm.org/viewvc/llvm-project?rev=247738&view=rev
Log:
[elf2] Relocate absolute symbols.

Added:
    lld/trunk/test/elf2/Inputs/abs.s
    lld/trunk/test/elf2/relocation-absolute.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247738&r1=247737&r2=247738&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Sep 15 18:12:02 2015
@@ -477,14 +477,19 @@ template <class ELFT> void OutputSection
         SymbolBody *Body = File->getSymbolBody(SymIndex);
         if (!Body)
           continue;
-        // Skip unsupported for now.
-        auto *DR = dyn_cast<DefinedRegular<ELFT>>(Body);
-        if (!DR)
+
+        uintX_t SymVA;
+        if (auto *DR = dyn_cast<DefinedRegular<ELFT>>(Body))
+          SymVA = getSymVA<ELFT>(DR);
+        else if (auto *DA = dyn_cast<DefinedAbsolute<ELFT>>(Body))
+          SymVA = DA->Sym.st_value;
+        else
+          // Skip unsupported for now.
           continue;
+
         uintX_t Offset = RI.r_offset;
         uint32_t Type = RI.getType(EObj->isMips64EL());
         uintX_t P = this->getVA() + C->getOutputSectionOff();
-        uintX_t SymVA = getSymVA<ELFT>(DR);
         uint8_t *Location = Base + Offset;
         switch (Type) {
         case llvm::ELF::R_X86_64_PC32:

Added: lld/trunk/test/elf2/Inputs/abs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/Inputs/abs.s?rev=247738&view=auto
==============================================================================
--- lld/trunk/test/elf2/Inputs/abs.s (added)
+++ lld/trunk/test/elf2/Inputs/abs.s Tue Sep 15 18:12:02 2015
@@ -0,0 +1,2 @@
+.global abs
+abs = 0x42

Added: lld/trunk/test/elf2/relocation-absolute.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation-absolute.s?rev=247738&view=auto
==============================================================================
--- lld/trunk/test/elf2/relocation-absolute.s (added)
+++ lld/trunk/test/elf2/relocation-absolute.s Tue Sep 15 18:12:02 2015
@@ -0,0 +1,12 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/abs.s -o %tabs
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+// RUN: lld -flavor gnu2 %tabs %t -o %tout
+// RUN: llvm-objdump -s %tout
+// REQUIRES: x86
+
+.global _start
+_start:
+  movl $abs, %edx
+
+#CHECK:      Contents of section .text:
+#CHECK-NEXT:  {{[0-1a-f]+}} ba420000 00




More information about the llvm-commits mailing list