From 46eda4683acc4518ba0303b946800e946d2f8208 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 19 Apr 2024 03:53:02 -0400 Subject: [PATCH] Added common header + debug trace. Change-Id: Idfaa883c681454581be7fb563261368079a59ba5 Signed-off-by: Anton Volkov --- lld/ELF/Writer.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index fb2f260f3d94..11e3abf34a71 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -116,7 +116,7 @@ static void removeEmptyPTLoad(SmallVector &phdrs) { for (OutputSection *sec : outputSections) if (removed.count(sec->ptLoad)) sec->ptLoad = nullptr; - + if (config->adlt) { assert(it == phdrs.end() && "adlt: ph-index in .adlt invalid due to shift"); } @@ -2376,6 +2376,11 @@ SmallVector Writer::createPhdrs(Partition &part) { load = addHdr(PT_LOAD, flags); load->add(Out::elfHeader); load->add(Out::programHeaders); + if (config->adlt) // add common header for all libs + for (auto *base : ctx->sharedFilesExtended) { + auto *soFile = cast>(base); + soFile->programHeaderIndexes.insert(getCurrentIndex()); + } } } @@ -2461,9 +2466,19 @@ SmallVector Writer::createPhdrs(Partition &part) { } // Check outputs + auto adltTraceNeeded = false; // debug hint + auto trace = [&](auto *file, auto &indexes) { + lld::outs() << "ADLT: " << file->soName << ":\n"; + for (auto &it : indexes) + lld::outs() << it << " "; + lld::outs() << '\n'; + }; for (ELFFileBase *baseFile : ctx->sharedFilesExtended) { - __attribute__((unused)) auto *soFile = cast>(baseFile); - assert(!soFile->programHeaderIndexes.empty()); + auto *soFile = cast>(baseFile); + auto &indexes = soFile->programHeaderIndexes; + assert(!indexes.empty()); + if (adltTraceNeeded) + trace(soFile, indexes); } } -- Gitee