diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index ae24890ea57c6428c637ef96e8de71aff75f5666..ef9e1cfc030d121a58dee162a52527e8aa3841aa 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -1070,7 +1070,7 @@ void ObjFile::initializeSymbols(const object::ELFFile &obj) { uint8_t stOther = eSym.st_other; uint8_t type = eSym.getType(); uint64_t value = eSym.st_value; - if (config->adlt) { + if (config->adlt && secIdx != SHN_ABS) { const Elf_Shdr *eSec = *obj.getSection(secIdx); value -= eSec->sh_addr; } diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 6ef2dd6187c5fd48a7918c79e9774a4bdd8d166d..a0ef192d6711f7d876ec524ec1bbe13191a42470 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1433,13 +1433,22 @@ template void RelocationScanner::scanOne(RelTy *&i) { offset -= sec.address; Symbol *s = &sym; - if (sec.name != "") - s = &file->getSymbolFromElfSymTab(symIndex); + if (!(expr == R_PLT || expr == R_PLT_PC || expr == R_GOT || expr == R_GOT_PC)) + if (Symbol *tmp = &file->getSymbolFromElfSymTab(symIndex)) + if (tmp->getName() != s->getName()) + s = tmp; s = sym.getName().size() ? elf::symtab->find(sym.getName()) : &sym; - if (!s) // if symbol was not found in elf::symtab s = &sym; + + if (s->isUndefined()) { + if (expr == R_PLT || expr == R_PLT_PC) + s->needsPlt = 1; + else if (expr == R_GOT || expr == R_GOT_PC) + s->needsGot = 1; + } + auto pushReloc = [&]() { sec.relocations.push_back({expr, type, offset, addend, s}); }; @@ -1451,7 +1460,11 @@ template void RelocationScanner::scanOne(RelTy *&i) { case R_AARCH64_ADD_ABS_LO12_NC: case R_AARCH64_ADR_PREL_PG_HI21: case R_AARCH64_LDST8_ABS_LO12_NC: + case R_AARCH64_LDST32_ABS_LO12_NC: case R_AARCH64_LDST64_ABS_LO12_NC: + case R_AARCH64_LDST128_ABS_LO12_NC: + case R_AARCH64_PREL32: + case R_AARCH64_PREL64: pushReloc(); return; // plt relocs @@ -1686,6 +1699,11 @@ void RelocationScanner::scan(ArrayRef rels) { template void elf::scanRelocations(InputSectionBase &s) { RelocationScanner scanner(s); + if (config->adlt) { + bool isDebug = false; + if (isDebug) + lld::outs() << s.file->getName().str() + ": " + s.name.str() + '\n'; + } const RelsOrRelas rels = s.template relsOrRelas(); if (rels.areRelocsRel()) scanner.template scan(rels.rels); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 4f4658d7cc2421eb1d551690913222dd76e961ac..a3db65a4732cdfc3c42015ff5324b415fa7dd076 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1944,10 +1944,7 @@ template void Writer::finalizeSections() { if (config->adlt) for (InputFile *file : ctx->sharedFilesExtended) for (InputSectionBase *sec : file->getSections()) { - bool isExclusive = sec && (sec->type == SHT_NULL || - sec->name.startswith(".got.plt") || - !sec->name.startswith(".debug_")); - if (isExclusive) + if (sec && sec->isLive()) scanRelocations(*sec); } if (!config->adlt)