Fix R_X86_64_RELATIVE for local symbols that refer to other sections.

We were mixing up the relocated and target sections.

llvm-svn: 249360
This commit is contained in:
Rafael Espindola
2015-10-05 22:49:16 +00:00
parent b4606e183e
commit 41127ad7af
2 changed files with 10 additions and 2 deletions

View File

@@ -103,7 +103,10 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
const Elf_Rel &RI = Rel.RI;
OutputSection<ELFT> *Out = C.getOutputSection();
uint32_t SymIndex = RI.getSymbol(IsMips64EL);
const SymbolBody *Body = C.getFile()->getSymbolBody(SymIndex);
const ObjectFile<ELFT> &File = *C.getFile();
const SymbolBody *Body = File.getSymbolBody(SymIndex);
const ELFFile<ELFT> &Obj = File.getObj();
uint32_t Type = RI.getType(IsMips64EL);
if (Body && Target->relocNeedsGot(Type, *Body)) {
P->r_offset = GotSec.getEntryAddr(*Body);
@@ -124,7 +127,8 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
if (Body)
Addent += getSymVA(cast<ELFSymbolBody<ELFT>>(*Body), BssSec);
else
Addent += C.getOutputSectionOff() + Out->getVA();
Addent += getLocalSymVA(
Obj.getRelocationSymbol(&RI, File.getSymbolTable()), File);
}
}
if (IsRela)

View File

@@ -11,6 +11,7 @@
// CHECK-NEXT: 0x[[BAR_ADDR:.*]] R_X86_64_RELATIVE - 0x[[BAR_ADDR]]
// CHECK-NEXT: 0x2010 R_X86_64_RELATIVE - 0x2009
// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x[[ZED_ADDR:.*]]
// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x[[FOO_ADDR]]
// CHECK-NEXT: }
// CHECK-NEXT: ]
@@ -47,3 +48,6 @@ bar:
.hidden zed
.comm zed,1
.quad zed
.section abc,"a"
.quad foo