From 7b67fe22194ba1d8901d3c216192a4710b13dfb6 Mon Sep 17 00:00:00 2001 From: likholatovevgeny Date: Mon, 20 May 2024 17:10:07 +0300 Subject: [PATCH] Added printing info about duplicates with --adlt-trace flag. Signed-off-by: likholatovevgeny --- lld/ELF/Writer.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 6743de95cd2f..bd7ad685c436 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -558,6 +558,7 @@ static struct AdltWriter { template void trackPhdr(OutputSection *sec, PhdrEntry *phdr); template void traceRelocs(); template void tracePhdrs(); + template void traceDuplicates(); } adltWriter; } // namespace @@ -674,6 +675,33 @@ template void AdltWriter::tracePhdrs() { } } +template void AdltWriter::traceDuplicates() { + SmallVector*, Symbol*>, 0> duplicates; + lld::outs() << "[ADLT] Duplicate symbols:\n"; + for (auto cachedName : ctx->adlt.duplicatedSymNames) { + StringRef name = cachedName.val(); + for (auto *file : ctx->sharedFilesExtended) + if (auto *soFile = cast>(file)) { + StringRef newName = soFile->addAdltPostfix(name); + Symbol *sym = elf::symtab->find(newName); + if (sym != nullptr) + duplicates.push_back({soFile, sym}); + } + + lld::outs() << "[ADLT] " << name << ":\n"; + lld::outs() << "Shared files indexes: "; + for (auto it : duplicates) + lld::outs() << it.first->orderIdx << " "; + lld::outs() << "\n"; + + for (auto it : duplicates) + lld::outs() << it.first->orderIdx << ": " + << it.second->getOutputSection()->name << "\t" + << it.first->soName << "\n"; + duplicates.clear(); + } +} + StringRef AdltWriter::phdrTypeToStr(uint32_t p_type) { switch (p_type) { case PT_PHDR: @@ -2347,6 +2375,7 @@ template void Writer::finalizeSections() { adltWriter.checkPhdrs(); adltWriter.checkRelocs(); if (config->adltTrace) { + adltWriter.traceDuplicates(); adltWriter.tracePhdrs(); adltWriter.traceRelocs(); } -- Gitee