samitolvanen created this revision. Herald added subscribers: ormris, steven_wu, hiraditya, inglorion. samitolvanen requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits.
Create an internal alias with the original name for static functions that are renamed in promoteInternals to avoid breaking inline assembly references to them. Link: https://github.com/ClangBuiltLinux/linux/issues/1354 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D104058 Files: clang/test/CodeGen/thinlto-cfi-icall-static-inline-asm.c llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp =================================================================== --- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -69,6 +69,15 @@ ImportGV->setName(NewName); ImportGV->setVisibility(GlobalValue::HiddenVisibility); } + + if (Function *F = dyn_cast<Function>(&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()) Index: clang/test/CodeGen/thinlto-cfi-icall-static-inline-asm.c =================================================================== --- /dev/null +++ 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) { +}
Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp =================================================================== --- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -69,6 +69,15 @@ ImportGV->setName(NewName); ImportGV->setVisibility(GlobalValue::HiddenVisibility); } + + if (Function *F = dyn_cast<Function>(&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()) Index: clang/test/CodeGen/thinlto-cfi-icall-static-inline-asm.c =================================================================== --- /dev/null +++ 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) { +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits