diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 1688c8ab93080fce3f253c37f9d450329a92cf12..5517c153a9b0b2c74620015f01176b759af67f6c 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -449,6 +449,11 @@ public: int symTabShndxSecIdx = 0; int eFirstGlobal = 0; + // Output information data: + llvm::SetVector programHeaderIndexes; + // TODO: dynamic relocation indexes + + // SharedFile compability layer: // This is actually a vector of Elf_Verdef pointers. SmallVector verdefs; // If the output file needs Elf_Verneed data structures for this file, this is diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index a087d61ae59fd7cc4b61604b2c088ba1164e9a18..de6fb6eefb0b573debf01805f3bd2e00380f74d5 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -2134,7 +2134,7 @@ template void Writer::finalizeSections() { finalizeSynthetic(in.iplt.get()); finalizeSynthetic(in.ppc32Got2.get()); finalizeSynthetic(in.partIndex.get()); - + if (config->adlt) { finalizeSynthetic(in.adltData.get()); finalizeSynthetic(in.adltStrTab.get()); @@ -2312,6 +2312,19 @@ static uint64_t computeFlags(uint64_t flags) { return flags; } +static InputSection *getInputSection(OutputSection *sec) { + if (!sec || !sec->hasInputSections || sec->commands.empty()) + return nullptr; + SectionCommand *cmd = sec->commands.front(); + InputSectionDescription *isd = cast(cmd); + return isd->sections.front(); +} + +struct LoadInfoForADLT { + int phIndex; // input + SmallVector phSections; +}; + // Decide which program headers to create and which sections to include in each // one. template @@ -2322,6 +2335,10 @@ SmallVector Writer::createPhdrs(Partition &part) { return ret.back(); }; + auto getCurrentIndex = [&]() -> int { + return static_cast(ret.size()) - 1; + }; + unsigned partNo = part.getNumber(); bool isMain = partNo == 1; @@ -2376,6 +2393,9 @@ SmallVector Writer::createPhdrs(Partition &part) { } } + // ADLT: Collect load headers info + SmallVector adltLoadInfo; + for (OutputSection *sec : outputSections) { if (!needsPtLoad(sec)) continue; @@ -2407,9 +2427,35 @@ SmallVector Writer::createPhdrs(Partition &part) { (sameLMARegion || load->lastSec == Out::programHeaders))) { load = addHdr(PT_LOAD, newFlags); flags = newFlags; + if (config->adlt) { + adltLoadInfo.emplace_back(); + adltLoadInfo.back().phIndex = getCurrentIndex(); + } } load->add(sec); + if (config->adlt && !adltLoadInfo.empty()) + adltLoadInfo.back().phSections.push_back(sec); + } + + // ADLT: Fill load headers info + if (config->adlt) { + for (LoadInfoForADLT &info : adltLoadInfo) + for (OutputSection *sec : info.phSections) { + auto *isec = getInputSection(sec); + assert(isec); + auto *file = isec->file; + if (!file) // skip generated sections. + continue; // TODO: fix .rodata_$ADLT_POSTFIX sections. + auto *soFile = cast>(file); + soFile->programHeaderIndexes.insert(info.phIndex); + } + + // Check outputs + for (ELFFileBase *baseFile : ctx->sharedFilesExtended) { + auto *soFile = cast>(baseFile); + assert(!soFile->programHeaderIndexes.empty()); + } } // Add a TLS segment if any.