From 3c1ac0a17afe842f0685b5834dea3d45ee2eb6cc Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Tue, 15 Sep 2015 23:12:02 +0000 Subject: [PATCH] [elf2] Relocate absolute symbols. llvm-svn: 247738 --- lld/ELF/Writer.cpp | 13 +++++++++---- lld/test/elf2/Inputs/abs.s | 2 ++ lld/test/elf2/relocation-absolute.s | 12 ++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 lld/test/elf2/Inputs/abs.s create mode 100644 lld/test/elf2/relocation-absolute.s diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 8c4503eed3fe..9826203636a5 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -477,14 +477,19 @@ template void OutputSection::writeTo(uint8_t *Buf) { SymbolBody *Body = File->getSymbolBody(SymIndex); if (!Body) continue; - // Skip unsupported for now. - auto *DR = dyn_cast>(Body); - if (!DR) + + uintX_t SymVA; + if (auto *DR = dyn_cast>(Body)) + SymVA = getSymVA(DR); + else if (auto *DA = dyn_cast>(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(DR); uint8_t *Location = Base + Offset; switch (Type) { case llvm::ELF::R_X86_64_PC32: diff --git a/lld/test/elf2/Inputs/abs.s b/lld/test/elf2/Inputs/abs.s new file mode 100644 index 000000000000..5e3f124c5683 --- /dev/null +++ b/lld/test/elf2/Inputs/abs.s @@ -0,0 +1,2 @@ +.global abs +abs = 0x42 diff --git a/lld/test/elf2/relocation-absolute.s b/lld/test/elf2/relocation-absolute.s new file mode 100644 index 000000000000..bc4bda258ff4 --- /dev/null +++ b/lld/test/elf2/relocation-absolute.s @@ -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