Handle a common symbol needing a R_X86_64_RELATIVE.

llvm-svn: 249357
This commit is contained in:
Rafael Espindola 2015-10-05 21:23:08 +00:00
parent 808d2a070d
commit 9c3e4d2af5
4 changed files with 18 additions and 6 deletions

View File

@ -81,12 +81,13 @@ PltSection<ELFT>::getEntryAddr(const SymbolBody &B) const {
template <class ELFT>
RelocationSection<ELFT>::RelocationSection(SymbolTableSection<ELFT> &DynSymSec,
const GotSection<ELFT> &GotSec,
const OutputSection<ELFT> &BssSec,
bool IsRela)
: OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" : ".rel.dyn",
IsRela ? llvm::ELF::SHT_RELA
: llvm::ELF::SHT_REL,
llvm::ELF::SHF_ALLOC),
DynSymSec(DynSymSec), GotSec(GotSec), IsRela(IsRela) {
DynSymSec(DynSymSec), GotSec(GotSec), BssSec(BssSec), IsRela(IsRela) {
this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
}
@ -120,9 +121,10 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
} else {
P->setSymbolAndType(0, Target->getRelativeReloc(), IsMips64EL);
if (IsRela) {
Addent += C.getOutputSectionOff() + Out->getVA();
if (Body)
Addent += cast<DefinedRegular<ELFT>>(Body)->Sym.st_value;
Addent += getSymVA(cast<ELFSymbolBody<ELFT>>(*Body), BssSec);
else
Addent += C.getOutputSectionOff() + Out->getVA();
}
}
if (IsRela)

View File

@ -193,7 +193,8 @@ class RelocationSection final : public OutputSectionBase<ELFT::Is64Bits> {
public:
RelocationSection(SymbolTableSection<ELFT> &DynSymSec,
const GotSection<ELFT> &GotSec, bool IsRela);
const GotSection<ELFT> &GotSec,
const OutputSection<ELFT> &BssSec, bool IsRela);
void addReloc(const DynamicReloc<ELFT> &Reloc) { Relocs.push_back(Reloc); }
void finalize() override;
void writeTo(uint8_t *Buf) override;
@ -204,6 +205,7 @@ private:
std::vector<DynamicReloc<ELFT>> Relocs;
SymbolTableSection<ELFT> &DynSymSec;
const GotSection<ELFT> &GotSec;
const OutputSection<ELFT> &BssSec;
const bool IsRela;
};

View File

@ -84,8 +84,9 @@ public:
typedef typename ELFFile<ELFT>::Elf_Rela Elf_Rela;
Writer(SymbolTable *T)
: SymTabSec(*T, StrTabSec, BssSec), DynSymSec(*T, DynStrSec, BssSec),
RelaDynSec(DynSymSec, GotSec, T->shouldUseRela()), PltSec(GotSec),
HashSec(DynSymSec), DynamicSec(*T, HashSec, RelaDynSec, BssSec),
RelaDynSec(DynSymSec, GotSec, BssSec, T->shouldUseRela()),
PltSec(GotSec), HashSec(DynSymSec),
DynamicSec(*T, HashSec, RelaDynSec, BssSec),
BssSec(PltSec, GotSec, BssSec, ".bss", SHT_NOBITS,
SHF_ALLOC | SHF_WRITE) {}
void run();

View File

@ -10,6 +10,7 @@
// CHECK-NEXT: 0x[[FOO_ADDR:.*]] R_X86_64_RELATIVE - 0x[[FOO_ADDR]]
// 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: }
// CHECK-NEXT: ]
@ -18,6 +19,8 @@
// CHECK-NEXT: Value: 0x[[FOO_ADDR]]
// CHECK: Name: bar
// CHECK-NEXT: Value: 0x[[BAR_ADDR]]
// CHECK: Name: zed
// CHECK-NEXT: Value: 0x[[ZED_ADDR]]
// CHECK: ]
// CHECK: DynamicSymbols [
@ -40,3 +43,7 @@ foo:
bar:
.quad bar
.quad bar + 1
.hidden zed
.comm zed,1
.quad zed