ELF: Move GOT relocation handler code to one place. NFC.

llvm-svn: 259471
This commit is contained in:
Rui Ueyama 2016-02-02 07:07:35 +00:00
parent 554f273b9d
commit f263c4b0f1
1 changed files with 22 additions and 18 deletions

View File

@ -346,15 +346,28 @@ void Writer<ELFT>::scanRelocs(
continue; continue;
} }
bool NeedsGot = false; // If a relocation needs GOT, we create a GOT slot for the symbol.
if (Body && Target->needsGot(Type, *Body)) {
if (Body->isInGot())
continue;
Out<ELFT>::Got->addEntry(Body);
if (Body) { if (Config->EMachine == EM_MIPS)
NeedsGot = Target->needsGot(Type, *Body); // MIPS ABI has special rules to process GOT entries
if (NeedsGot) { // and doesn't require relocation entries for them.
if (Body->isInGot()) // See "Global Offset Table" in Chapter 5 in the following document
continue; // for detailed description:
Out<ELFT>::Got->addEntry(Body); // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
} continue;
bool CBP = canBePreempted(Body, /*NeedsGot=*/true);
bool Dynrel = Config->Shared && !Target->isRelRelative(Type) &&
!Target->isSizeRel(Type);
if (CBP)
Body->setUsedInDynamicReloc();
if (CBP || Dynrel)
Out<ELFT>::RelaDyn->addReloc({&C, &RI});
continue;
} }
if (Config->EMachine == EM_MIPS) { if (Config->EMachine == EM_MIPS) {
@ -367,15 +380,6 @@ void Writer<ELFT>::scanRelocs(
// relocation too because that case is possible for executable file // relocation too because that case is possible for executable file
// linking only. // linking only.
continue; continue;
if (NeedsGot) {
// MIPS ABI has special rules to process GOT entries
// and doesn't require relocation entries for them.
// See "Global Offset Table" in Chapter 5 in the following document
// for detailed description:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
Body->setUsedInDynamicReloc();
continue;
}
if (Body == Config->MipsGpDisp) if (Body == Config->MipsGpDisp)
// MIPS _gp_disp designates offset between start of function and gp // MIPS _gp_disp designates offset between start of function and gp
// pointer into GOT therefore any relocations against it do not require // pointer into GOT therefore any relocations against it do not require
@ -386,7 +390,7 @@ void Writer<ELFT>::scanRelocs(
// Here we are creating a relocation for the dynamic linker based on // Here we are creating a relocation for the dynamic linker based on
// a relocation from an object file, but some relocations need no // a relocation from an object file, but some relocations need no
// load-time fixup when the final target is known. Skip such relocation. // load-time fixup when the final target is known. Skip such relocation.
bool CBP = canBePreempted(Body, NeedsGot); bool CBP = canBePreempted(Body, /*NeedsGot=*/false);
bool NoDynrel = Target->isRelRelative(Type) || Target->isSizeRel(Type) || bool NoDynrel = Target->isRelRelative(Type) || Target->isSizeRel(Type) ||
!Config->Shared; !Config->Shared;
if (!CBP && NoDynrel) if (!CBP && NoDynrel)