From c0d954a068a1896f2673f2fadec72bb01a243aaa Mon Sep 17 00:00:00 2001 From: Rafael Auler Date: Mon, 17 Oct 2022 19:01:46 -0700 Subject: [PATCH] [BOLT] Ignore duplicate global symbols We noticed some binaries with duplicated global symbol entries (same name, address and size). Ignore them as it is possibly a bug in the linker, and continue processing, unless the symbol has a different size or address. Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D136122 --- bolt/lib/Rewrite/RewriteInstance.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index a6334a6a6d7f..ac83b6dd95d8 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -966,7 +966,19 @@ void RewriteInstance::discoverFileObjects() { if (Name.empty()) { UniqueName = "ANONYMOUS." + std::to_string(AnonymousId++); } else if (cantFail(Symbol.getFlags()) & SymbolRef::SF_Global) { - assert(!BC->getBinaryDataByName(Name) && "global name not unique"); + if (const BinaryData *BD = BC->getBinaryDataByName(Name)) { + if (BD->getSize() == ELFSymbolRef(Symbol).getSize() && + BD->getAddress() == Address) { + if (opts::Verbosity > 1) + errs() << "BOLT-WARNING: ignoring duplicate global symbol " << Name + << "\n"; + // Ignore duplicate entry - possibly a bug in the linker + continue; + } + errs() << "BOLT-ERROR: bad input binary, global symbol \"" << Name + << "\" is not unique\n"; + exit(1); + } UniqueName = Name; } else { // If we have a local file name, we should create 2 variants for the