[PATCH] D94154: Unique Internal Linkage Name suffixes must be demangler friendly

Sriraman Tallam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 5 22:30:54 PST 2021


tmsriram created this revision.
tmsriram added reviewers: dblaikie, hoy.
Herald added a subscriber: hiraditya.
tmsriram requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

-funique-internal-linkage-names appends a hex md5hash suffix to the symbol name which is not demangler friendly, convert it to decimal.

Please see D93747 <https://reviews.llvm.org/D93747> for more context which tries to make linkage names of internal linkage functions to be the uniqueified names.  This causes a problem with gdb because breaking using the demangled function name will not work if the new uniqueified name cannot be demangled.  The problem is the generated suffix which is a mix of integers and letters which do not demangle.  The demangler accepts either all numbers or all letters.  This patch simply converts the hash to decimal.

There is no loss of uniqueness by doing this as the precision is maintained.  The symbol names get longer by a few characters though.


https://reviews.llvm.org/D94154

Files:
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
  llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll


Index: llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
===================================================================
--- llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
+++ llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
@@ -10,5 +10,5 @@
   ret i32 0
 }
 
-; CHECK: @glob.__uniq.6ae72bb15a7d1834b42ae042a58f7a4d = internal global
-; CHECK: define internal i32 @foo.__uniq.6ae72bb15a7d1834b42ae042a58f7a4d()
+; CHECK: @glob.__uniq.142098474322525230676991677820000238157 = internal global
+; CHECK: define internal i32 @foo.__uniq.142098474322525230676991677820000238157()
Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
===================================================================
--- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -27,9 +27,12 @@
   Md5.final(R);
   SmallString<32> Str;
   llvm::MD5::stringifyResult(R, Str);
+  // Convert MD5hash to Decimal. Demangler suffixes can either contain numbers
+  // or characters but not both.
+  APInt IntHash = APInt(128, Str.str(), 16);
   // Prepend "__uniq" before the hash for tools like profilers to understand that
   // this symbol is of internal linkage type.
-  std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
+  std::string ModuleNameHash = (Twine(".__uniq.") + Twine(IntHash.toString(10, false))).str();
   bool Changed = false;
 
   // Append the module hash to all internal linkage functions.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94154.314798.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210106/82e1eeb7/attachment.bin>


More information about the llvm-commits mailing list