diff --git a/clang/test/CodeGen/thinlto-cfi-icall-static-inline-asm.c b/clang/test/CodeGen/thinlto-cfi-icall-static-inline-asm.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/thinlto-cfi-icall-static-inline-asm.c @@ -0,0 +1,20 @@ +// REQUIRES: x86-registered-target + +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -flto=thin -fsanitize=cfi-icall -fsplit-lto-unit -o - %s | llvm-dis - | FileCheck %s + +// CHECK: @a = internal alias {{.*}}@a.[[HASH:[0-9a-f]+]] +static void a(void); + +// CHECK-LABEL: define{{.*}} @b(){{.*}} !type +void b(void) { + // CHECK: store{{.*}} @a.[[HASH]],{{.*}} %f + void (*f)(void) = a; + // CHECK: call void ()* asm sideeffect "leaq a(%rip) + asm volatile("leaq a(%%rip), %0\n\t" + : "=r"(f)); + f(); +} + +// CHECK: define{{.*}} @a.[[HASH]](){{.*}} !type +static void a(void) { +} diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -69,6 +69,15 @@ ImportGV->setName(NewName); ImportGV->setVisibility(GlobalValue::HiddenVisibility); } + + if (Function *F = dyn_cast(&ExportGV)) { + // Create a local alias with the original name to avoid breaking + // references from inline assembly. + GlobalAlias *A = + GlobalAlias::create(F->getValueType(), F->getAddressSpace(), + GlobalValue::InternalLinkage, Name, F, &ExportM); + appendToCompilerUsed(ExportM, A); + } } if (!RenamedComdats.empty())