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