[elf2] Relocate absolute symbols.

llvm-svn: 247738
This commit is contained in:
Michael J. Spencer 2015-09-15 23:12:02 +00:00
parent f23dee5408
commit 3c1ac0a17a
3 changed files with 23 additions and 4 deletions

View File

@ -477,14 +477,19 @@ template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
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:

View File

@ -0,0 +1,2 @@
.global abs
abs = 0x42

View File

@ -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