diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 82b685c86a2f4476d8ee712361ffd77f2c92b345..9ae3bccee1e994a7892e22d2a71def7003811be6 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -145,13 +145,13 @@ static bool isCompatible(InputFile *file) { } InputFile *existing = nullptr; - if (!ctx->objectFiles.empty()) - existing = ctx->objectFiles[0]; - else if (!ctx->sharedFiles.empty()) - existing = ctx->sharedFiles[0]; - else if (!ctx->bitcodeFiles.empty()) - existing = ctx->bitcodeFiles[0]; - std::string with; + if (!ctx->objectFiles.empty()) + existing = ctx->objectFiles[0]; + else if (!ctx->sharedFiles.empty()) + existing = ctx->sharedFiles[0]; + else if (!ctx->bitcodeFiles.empty()) + existing = ctx->bitcodeFiles[0]; + std::string with; if (existing) with = " with " + toString(existing); error(toString(file) + " is incompatible" + with); @@ -1768,6 +1768,11 @@ SharedFileExtended::findInputSection(uint64_t offset) const { return nullptr; } +template +bool SharedFileExtended::isDynamicSection(InputSectionBase &sec) const { + return sec.type == llvm::ELF::SHT_NULL || sec.name.startswith(".got.plt"); +} + template Defined *SharedFileExtended::findDefinedSymbol( uint64_t offset, StringRef fatalTitle, diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index bc3d594189ee8a6b224dd854db638005b1f06191..da44677d5e6dd0cf4d3a7132058613731623a31d 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -414,6 +414,13 @@ public: InputSectionBase *findInputSection(StringRef name) const; InputSectionBase *findInputSection(uint64_t offset) const; + bool isDynamicSection(InputSectionBase &sec) const; + + template + Symbol &getRelocTargetSymADLT(const RelT &rel, InputSectionBase &sec) const { + uint32_t symIndex = rel.getSymbol(config->isMips64EL); + return getSymbolADLT(symIndex, isDynamicSection(sec)); + } ArrayRef getLocalSymbols() override { if (this->allSymbols.empty()) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 7357297af5b09cec846de7cd0d86b9067980e31a..0eb2968413bddb05fb4888a7c749490fe14e98ac 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -347,9 +347,11 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef rels) { for (const RelTy &rel : rels) { RelType type = rel.getType(config->isMips64EL); - const ELFFileBase *file = cast_or_null(file); - Symbol &sym = config->adlt ? getSharedFile()->getRelocTargetSym(rel) - : getFile()->getRelocTargetSym(rel); + const ObjFile *file = + config->adlt ? getSharedFile() : getFile(); + Symbol &sym = config->adlt + ? getSharedFile()->getRelocTargetSymADLT(rel, *sec) + : file->getRelocTargetSym(rel); auto *p = reinterpret_cast(buf); buf += sizeof(RelTy); @@ -384,7 +386,7 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef rels) { uint32_t secIdx = cast(sym).discardedSecIdx; Elf_Shdr_Impl sec = file->template getELFShdrs()[secIdx]; warn("relocation refers to a discarded section: " + - CHECK(file->getObj().getSectionName(sec), file) + + CHECK(file->getObj().getSectionName(sec), file) + "\n>>> referenced by " + getObjMsg(p->r_offset)); } p->setSymbolAndType(0, 0, false); diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index ec3228a986cf2a0597d8559dd6b64e2f075ca9f2..455ab20e033323566abaae3b2947bb9f223043d1 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1447,7 +1447,7 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, template void RelocationScanner::scanOne(RelTy *&i) { const RelTy &rel = *i; uint32_t symIndex = rel.getSymbol(config->isMips64EL); - bool fromDynamic = sec.type == SHT_NULL || sec.name.startswith(".got.plt"); + bool fromDynamic = sec.getSharedFile()->isDynamicSection(sec); Symbol &sym = config->adlt ? sec.getSharedFile()->getSymbolADLT(symIndex, fromDynamic) @@ -2338,8 +2338,6 @@ bool ThunkCreator::createThunks(uint32_t pass, // original target so another Thunk can be generated. if (pass > 0 && normalizeExistingThunk(rel, src)) continue; - if (!rel.sym) - continue; // ADLT fix if (!target->needsThunk(rel.expr, rel.type, isec->file, src, *rel.sym, rel.addend)) continue; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index de16dec8e6098c52d90dce222ea2b6bd438acc57..51dee08eb6add4d42987531aed4ae3d9198a5d4e 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1955,7 +1955,7 @@ template void Writer::finalizeSections() { if (sec && sec->isLive()) scanRelocations(*sec); } - if (!config->adlt) + else for (InputSectionBase *sec : inputSections) if (sec->isLive() && isa(sec) && (sec->flags & SHF_ALLOC)) scanRelocations(*sec);