[llvm] [BOLT] ICF: Use nameStartsWith instead of getName (PR #206999)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 08:11:20 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: DmitriiMartynov

<details>
<summary>Changes</summary>

The getName method returns the name of the first symbol for a given BinaryData. If a symbol is associated with the same address as a vtable symbol, the ICF check for vtable mangled names may behave unexpectedly. The correct approach is to use nameStartsWith, which checks all symbols associated with the BinaryData.

---
Full diff: https://github.com/llvm/llvm-project/pull/206999.diff


2 Files Affected:

- (modified) bolt/lib/Passes/IdenticalCodeFolding.cpp (+2-2) 
- (modified) bolt/test/safe-icf-relative-vtable.cpp (+2-3) 


``````````diff
diff --git a/bolt/lib/Passes/IdenticalCodeFolding.cpp b/bolt/lib/Passes/IdenticalCodeFolding.cpp
index cebb7638fa7c6..18c901e45116f 100644
--- a/bolt/lib/Passes/IdenticalCodeFolding.cpp
+++ b/bolt/lib/Passes/IdenticalCodeFolding.cpp
@@ -384,8 +384,8 @@ namespace bolt {
 void IdenticalCodeFolding::initVTableReferences(const BinaryContext &BC) {
   for (const auto &[Address, Data] : BC.getBinaryData()) {
     // Filter out all symbols that are not vtables.
-    if (!Data->getName().starts_with("_ZTV") && // vtable
-        !Data->getName().starts_with("_ZTCN"))  // construction vtable
+    if (!Data->nameStartsWith("_ZTV") && // vtable
+        !Data->nameStartsWith("_ZTCN"))  // construction vtable
       continue;
     for (uint64_t I = Address, End = I + Data->getSize(); I < End;
          I += VTableAddressGranularity)
diff --git a/bolt/test/safe-icf-relative-vtable.cpp b/bolt/test/safe-icf-relative-vtable.cpp
index 59ddcc656a5d1..16a1ffa16e5e6 100644
--- a/bolt/test/safe-icf-relative-vtable.cpp
+++ b/bolt/test/safe-icf-relative-vtable.cpp
@@ -5,10 +5,9 @@
 // RUN: %clang %cxxflags -o %t.so %s -Wl,-q -fno-rtti
 // RUN: llvm-bolt %t.so -o %t.bolt --no-threads --icf=safe \
 // RUN:   --debug-only=bolt-icf 2>&1 | FileCheck %s
-
-// RUN: %clang %cxxflags -o %t.so %s -Wl,-q -fno-rtti \
+// RUN: %clang %cxxflags -o %t.exp.so %s -Wl,-q -fno-rtti \
 // RUN:   -fexperimental-relative-c++-abi-vtables
-// RUN: llvm-bolt %t.so -o %t.bolt --no-threads --icf=safe \
+// RUN: llvm-bolt %t.exp.so -o %t.bolt --no-threads --icf=safe \
 // RUN:   --debug-only=bolt-icf 2>&1 | FileCheck %s
 
 // CHECK: folding {{.*bar.*}} into {{.*foo.*}}

``````````

</details>


https://github.com/llvm/llvm-project/pull/206999


More information about the llvm-commits mailing list