[BOLT] Handle __uniq suffix added by -funique-internal-linkage-names
authorAmir Ayupov <aaupov@fb.com>
Fri, 20 Jan 2023 23:50:59 +0000 (15:50 -0800)
committerAmir Ayupov <aaupov@fb.com>
Sat, 21 Jan 2023 03:23:06 +0000 (19:23 -0800)
In profile matching, if `.__uniq` suffix added for internal linkage
symbols with `-funique-internal-linkage-names` prevents BOLT from
matching to a binary function, try to strip the suffix and perform
fuzzy name matching.

Follow-up to D124117.

Reviewed By: #bolt, maksfb

Differential Revision: https://reviews.llvm.org/D142073

bolt/lib/Profile/DataReader.cpp
bolt/test/X86/lto-name-match.s

index ad4b1b5..b7f6888 100644 (file)
@@ -42,13 +42,11 @@ namespace llvm {
 namespace bolt {
 
 std::optional<StringRef> getLTOCommonName(const StringRef Name) {
-  size_t LTOSuffixPos = Name.find(".lto_priv.");
-  if (LTOSuffixPos != StringRef::npos)
-    return Name.substr(0, LTOSuffixPos + 10);
-  if ((LTOSuffixPos = Name.find(".constprop.")) != StringRef::npos)
-    return Name.substr(0, LTOSuffixPos + 11);
-  if ((LTOSuffixPos = Name.find(".llvm.")) != StringRef::npos)
-    return Name.substr(0, LTOSuffixPos + 6);
+  for (StringRef Suffix : {".__uniq.", ".lto_priv.", ".constprop.", ".llvm."}) {
+    size_t LTOSuffixPos = Name.find(Suffix);
+    if (LTOSuffixPos != StringRef::npos)
+      return Name.substr(0, LTOSuffixPos + Suffix.size());
+  }
   return std::nullopt;
 }
 
index a4dde00..32d2e0a 100644 (file)
@@ -1,5 +1,3 @@
-# REQUIRES: system-linux
-
 # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
 # RUN: link_fdata %s %t.o %t.fdata
 # RUN: llvm-strip --strip-unneeded %t.o
@@ -9,7 +7,7 @@
 ## Check that profile is correctly matched by functions with variable suffixes.
 ## E.g., LTO-generated name foo.llvm.123 should match foo.llvm.*.
 
-# CHECK: 4 out of {{.*}} functions in the binary {{.*}} have non-empty execution profile
+# CHECK: 6 out of {{.*}} functions in the binary {{.*}} have non-empty execution profile
 # CHECK-NOT: profile for {{.*}} objects was ignored
 
        .globl _start
@@ -27,6 +25,14 @@ LL_start_2:
 # FDATA: 1 _start #LL_start_2# 1 foo.lto_priv.321 0 0 1
   call foo.lto_priv.123
 
+LL_start_3:
+# FDATA: 1 _start #LL_start_3# 1 foo.__uniq.321 0 0 1
+  call foo.__uniq.123
+
+LL_start_4:
+# FDATA: 1 _start #LL_start_4# 1 foo.__uniq.654.llvm.321 0 0 1
+  call foo.__uniq.456.llvm.123
+
   call exit
   .size _start, .-_start
 
@@ -47,3 +53,15 @@ foo.constprop.123:
 foo.lto_priv.123:
   ret
   .size foo.lto_priv.123, .-foo.lto_priv.123
+
+  .globl foo.__uniq.123
+  .type foo.__uniq.123,@function
+foo.__uniq.123:
+  ret
+  .size foo.__uniq.123, .-foo.__uniq.123
+
+  .globl foo.__uniq.456.llvm.123
+  .type foo.__uniq.456.llvm.123,@function
+foo.__uniq.456.llvm.123:
+  ret
+  .size foo.__uniq.456.llvm.123, .-foo.__uniq.456.llvm.123