diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h --- a/llvm/include/llvm/IR/GlobalValue.h +++ b/llvm/include/llvm/IR/GlobalValue.h @@ -491,7 +491,8 @@ /// \c Linkage. The value is defined in module \c FileName. static std::string getGlobalIdentifier(StringRef Name, GlobalValue::LinkageTypes Linkage, - StringRef FileName); + StringRef FileName, + bool PreservePrefix = true); /// Return the modified name for this global value suitable to be /// used as the key for a global lookup (e.g. profile or ThinLTO). diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -131,12 +131,13 @@ std::string GlobalValue::getGlobalIdentifier(StringRef Name, GlobalValue::LinkageTypes Linkage, - StringRef FileName) { + StringRef FileName, + bool PreservePrefix) { // Value names may be prefixed with a binary '1' to indicate // that the backend should not modify the symbols due to any platform // naming convention. Do not include that '1' in the PGO profile name. - if (Name[0] == '\1') + if (!PreservePrefix && Name[0] == '\1') Name = Name.substr(1); std::string NewName = std::string(Name); @@ -155,7 +156,8 @@ std::string GlobalValue::getGlobalIdentifier() const { return getGlobalIdentifier(getName(), getLinkage(), - getParent()->getSourceFileName()); + getParent()->getSourceFileName(), + /*PreservePrefix=*/true); } StringRef GlobalValue::getSection() const { diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -220,7 +220,8 @@ GlobalValue::LinkageTypes Linkage, StringRef FileName, uint64_t Version LLVM_ATTRIBUTE_UNUSED) { - return GlobalValue::getGlobalIdentifier(RawFuncName, Linkage, FileName); + return GlobalValue::getGlobalIdentifier(RawFuncName, Linkage, FileName, + /*PreservePrefix=*/false); } // Strip NumPrefix level of directory name from PathNameStr. If the number of diff --git a/llvm/test/ThinLTO/X86/mangled_symbol.ll b/llvm/test/ThinLTO/X86/mangled_symbol.ll --- a/llvm/test/ThinLTO/X86/mangled_symbol.ll +++ b/llvm/test/ThinLTO/X86/mangled_symbol.ll @@ -7,8 +7,10 @@ ; INTERNALIZED: define internal void @extern_not_mangled ; INTERNALIZED: define internal void @"\01_extern_mangled" +; INTERNALIZED: define internal void @_extern_mangled ; EXPORTED: define void @extern_not_mangled ; EXPORTED: define void @"\01_extern_mangled" +; EXPORTED: define internal void @_extern_mangled target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.11.0" @@ -24,3 +26,8 @@ define void @"\01_extern_mangled"() { ret void } + +; _extern_mangled is different from "\01_extern_mangled" +define void @_extern_mangled() { + ret void +}