diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -948,20 +948,22 @@ /// If the function has multiple names - return one followed /// by "(*#)". /// - /// We should use getPrintName() for diagnostics and use + /// We should use getPrintNameWithNum() for diagnostics and use /// hasName() to match function name against a given string. /// /// NOTE: for disambiguating names of local symbols we use the following /// naming schemes: /// primary: / /// alternative: // - std::string getPrintName() const { + std::string getPrintNameWithNum() const { const size_t NumNames = Symbols.size() + Aliases.size(); return NumNames == 1 ? getOneName().str() : (getOneName().str() + "(*" + std::to_string(NumNames) + ")"); } + std::string getPrintName() const { return getOneName().str(); } + /// The function may have many names. For that reason, we avoid having /// getName() method as most of the time the user needs a different /// interface, such as forEachName(), hasName(), hasNameRegex(), etc. diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -1047,12 +1047,16 @@ << ". Could be a new entry.\n"; } registerName(SymbolSize); - continue; + if (BC->getBinaryFunctions().find(Address) == + BC->getBinaryFunctions().end()) + continue; } else if (PreviousFunction->getSize() == 0 && PreviousFunction->isSymbolValidInScope(Symbol, SymbolSize)) { LLVM_DEBUG(dbgs() << "BOLT-DEBUG: symbol is a function local symbol\n"); registerName(SymbolSize); - continue; + if (BC->getBinaryFunctions().find(Address) == + BC->getBinaryFunctions().end()) + continue; } } @@ -1141,7 +1145,9 @@ BF->setSize(std::max(SymbolSize, BF->getSize())); BC->setBinaryDataSize(Address, BF->getSize()); } - BF->addAlternativeName(UniqueName); + // Avoid adding duplicate symbol name + if (!BF->hasName(UniqueName)) + BF->addAlternativeName(UniqueName); } else { ErrorOr Section = BC->getSectionForAddress(Address); // Skip symbols from invalid sections diff --git a/bolt/test/X86/split-func-icf.s b/bolt/test/X86/split-func-icf.s --- a/bolt/test/X86/split-func-icf.s +++ b/bolt/test/X86/split-func-icf.s @@ -11,13 +11,13 @@ # RUN: llvm-bolt %t.exe -o %t.out -v=1 --print-only=main2.cold.1 --print-disasm 2>&1 | FileCheck %s # CHECK-NOT: unclaimed PC-relative relocations left in data -# CHECK-DAG: BOLT-INFO: marking main2.cold.1(*2) as a fragment of main -# CHECK-DAG: BOLT-INFO: marking main2.cold.1(*2) as a fragment of main2 -# CHECK: Binary Function "main2.cold.1(*2)" after disassembly -# CHECK: End of Function "main2.cold.1(*2)" +# CHECK-DAG: BOLT-INFO: marking main2.cold.1 as a fragment of main +# CHECK-DAG: BOLT-INFO: marking main2.cold.1 as a fragment of main2 +# CHECK: Binary Function "main2.cold.1" after disassembly +# CHECK: End of Function "main2.cold.1" # CHECK-DAG: BOLT-WARNING: Ignoring main2 # CHECK-DAG: BOLT-WARNING: Ignoring main -# CHECK-DAG: BOLT-WARNING: Ignoring main2.cold.1(*2) +# CHECK-DAG: BOLT-WARNING: Ignoring main2.cold.1 # CHECK: BOLT-WARNING: skipped 3 functions due to cold fragments .text .globl main diff --git a/bolt/test/runtime/X86/fdata-escape-chars.ll b/bolt/test/runtime/X86/fdata-escape-chars.ll --- a/bolt/test/runtime/X86/fdata-escape-chars.ll +++ b/bolt/test/runtime/X86/fdata-escape-chars.ll @@ -83,7 +83,7 @@ ; INSTR_CHECK: Exec Count : 1 ; INSTR_CHECK: {{([[:xdigit:]]+)}}: callq "symb whitespace" # Count: 1 ; INSTR_CHECK: {{([[:xdigit:]]+)}}: callq "symb backslash\" # Count: 2 -; INSTR_CHECK: Binary Function "static symb backslash\/1(*2)" +; INSTR_CHECK: Binary Function "static symb backslash\/1" ; INSTR_CHECK: Exec Count : 1 ; INSTR_CHECK: {{([[:xdigit:]]+)}}: callq "symb whitespace" # Count: 1 @@ -97,5 +97,5 @@ ; PREAGR_CHECK-DAG: Exec Count : 4 ; PREAGR_CHECK: Binary Function "symb backslash\" ; PREAGR_CHECK-DAG: Exec Count : 2 -; PREAGR_CHECK: Binary Function "static symb backslash\/1(*2)" +; PREAGR_CHECK: Binary Function "static symb backslash\/1" ; PREAGR_CHECK-DAG: Exec Count : 1