samitolvanen updated this revision to Diff 360615. samitolvanen added a comment. This revision is now accepted and ready to land.
As we only care about fixing inline assembly references, mangled names are not that important in the first place. This version skips any functions that have unusual characters in their names that would otherwise require quotes, which includes any functions with MSVC compatible name mangling. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104058/new/ https://reviews.llvm.org/D104058 Files: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp llvm/test/ThinLTO/X86/devirt2.ll llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll
Index: llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll =================================================================== --- llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll +++ llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll @@ -1,7 +1,10 @@ +; REQUIRES: x86-registered-target ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s ; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s ; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s +target triple = "x86_64-unknown-linux-gnu" + define [1 x i8*]* @source() { ret [1 x i8*]* @g } Index: llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll =================================================================== --- llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll +++ llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll @@ -1,3 +1,4 @@ +; REQUIRES: x86-registered-target ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s ; RUN: llvm-modextract -b -n 0 -o %t0 %t ; RUN: llvm-modextract -b -n 1 -o %t1 %t @@ -7,6 +8,8 @@ ; RUN: llvm-bcanalyzer -dump %t0 | FileCheck --check-prefix=BCA0 %s ; RUN: llvm-bcanalyzer -dump %t1 | FileCheck --check-prefix=BCA1 %s +target triple = "x86_64-unknown-linux-gnu" + ; ERROR: llvm-modextract: error: module index out of range; bitcode file contains 2 module(s) ; BCA0: <GLOBALVAL_SUMMARY_BLOCK Index: llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll @@ -0,0 +1,22 @@ +; REQUIRES: x86-registered-target +; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o - %s | llvm-modextract -b -n 0 -o - | llvm-dis | FileCheck %s + +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: module asm ".set a,a.[[HASH:[0-9a-f]+]]" + +define void @b() { + %f = alloca void ()*, align 8 + ; CHECK: store{{.*}} @a.[[HASH]],{{.*}} %f + store void ()* @a, void ()** %f, align 8 + ; CHECK: %1 = call void ()* asm sideeffect "leaq a(%rip) + %1 = call void ()* asm sideeffect "leaq a(%rip), $0\0A\09", "=r,~{dirflag},~{fpsr},~{flags}"() + ret void +} + +; CHECK: define{{.*}} @a.[[HASH]](){{.*}} !type +define internal void @a() !type !0 { + ret void +} + +!0 = !{i64 0, !"typeid1"} Index: llvm/test/ThinLTO/X86/devirt2.ll =================================================================== --- llvm/test/ThinLTO/X86/devirt2.ll +++ llvm/test/ThinLTO/X86/devirt2.ll @@ -131,10 +131,12 @@ ; RUN: -r=%t1.o,_ZN1D1mEi, \ ; RUN: -r=%t1.o,test2, \ ; RUN: -r=%t2.o,_ZN1A1nEi,p \ +; RUN: -r=%t2.o,_ZN1A1nEi, \ ; RUN: -r=%t2.o,_ZN1B1fEi,p \ ; RUN: -r=%t2.o,_ZN1C1fEi,p \ ; RUN: -r=%t2.o,_ZN1D1mEi,p \ ; RUN: -r=%t2.o,_ZN1E1mEi,p \ +; RUN: -r=%t2.o,_ZN1E1mEi, \ ; RUN: -r=%t2.o,_ZTV1B, \ ; RUN: -r=%t2.o,_ZTV1C, \ ; RUN: -r=%t2.o,_ZTV1D, \ @@ -167,10 +169,12 @@ ; RUN: -r=%t1.o,_ZN1D1mEi, \ ; RUN: -r=%t1.o,test2, \ ; RUN: -r=%t2.o,_ZN1A1nEi,p \ +; RUN: -r=%t2.o,_ZN1A1nEi, \ ; RUN: -r=%t2.o,_ZN1B1fEi,p \ ; RUN: -r=%t2.o,_ZN1C1fEi,p \ ; RUN: -r=%t2.o,_ZN1D1mEi,p \ ; RUN: -r=%t2.o,_ZN1E1mEi,p \ +; RUN: -r=%t2.o,_ZN1E1mEi, \ ; RUN: -r=%t2.o,_ZTV1B, \ ; RUN: -r=%t2.o,_ZTV1C, \ ; RUN: -r=%t2.o,_ZTV1D, \ Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp =================================================================== --- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -33,6 +33,18 @@ namespace { +// Determine if a promotion alias should be created for a symbol name. +static bool allowPromotionAlias(const std::string &Name) { + // Promotion aliases are used only in inline assembly. It's safe to + // simply skip unusual names. Matches MCAsmInfo::isAcceptableChar(). + for (const char &C : Name) { + if (isAlnum(C) || C == '_' || C == '$' || C == '.' || C == '@') + continue; + return false; + } + return true; +} + // Promote each local-linkage entity defined by ExportM and used by ImportM by // changing visibility and appending the given ModuleId. void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId, @@ -55,6 +67,7 @@ } } + std::string OldName = Name.str(); std::string NewName = (Name + ModuleId).str(); if (const auto *C = ExportGV.getComdat()) @@ -69,6 +82,13 @@ ImportGV->setName(NewName); ImportGV->setVisibility(GlobalValue::HiddenVisibility); } + + if (isa<Function>(&ExportGV) && allowPromotionAlias(OldName)) { + // Create a local alias with the original name to avoid breaking + // references from inline assembly. + std::string Alias = ".set " + OldName + "," + NewName + "\n"; + ExportM.appendModuleInlineAsm(Alias); + } } if (!RenamedComdats.empty())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits