diff options
author | Rui Ueyama <ruiu@google.com> | 2016-02-02 07:07:35 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2016-02-02 07:07:35 +0000 |
commit | f263c4b0f1b4c798c5fbfae0cb13d661f3a97372 (patch) | |
tree | 721ff0918860b036cff3b085cf404565f6dd23d0 | |
parent | 554f273b9d629fccfeada1442cd2274d88181df1 (diff) | |
download | bcm5719-llvm-f263c4b0f1b4c798c5fbfae0cb13d661f3a97372.tar.gz bcm5719-llvm-f263c4b0f1b4c798c5fbfae0cb13d661f3a97372.zip |
ELF: Move GOT relocation handler code to one place. NFC.
llvm-svn: 259471
-rw-r--r-- | lld/ELF/Writer.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 1371a96236d..3d7c748b0c5 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -346,15 +346,28 @@ void Writer<ELFT>::scanRelocs( 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) { - NeedsGot = Target->needsGot(Type, *Body); - if (NeedsGot) { - if (Body->isInGot()) - continue; - Out<ELFT>::Got->addEntry(Body); - } + if (Config->EMachine == EM_MIPS) + // 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 + 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) { @@ -367,15 +380,6 @@ void Writer<ELFT>::scanRelocs( // relocation too because that case is possible for executable file // linking only. 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) // MIPS _gp_disp designates offset between start of function and gp // 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 // a relocation from an object file, but some relocations need no // 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) || !Config->Shared; if (!CBP && NoDynrel) |