[llvm] [AArch64] Mangle names of all ARM64EC functions with entry thunks (PR #80996)
Billy Laws via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 06:29:40 PST 2024
https://github.com/bylaws created https://github.com/llvm/llvm-project/pull/80996
This better matches MSVC output in cases where static functions have their addresses taken.
CC: @cjacek @efriedma-quic @mstorsjo
>From d9899057e97cb7f4ebc2f1b8fe1f0d81527e8421 Mon Sep 17 00:00:00 2001
From: Billy Laws <blaws05 at gmail.com>
Date: Sun, 4 Feb 2024 12:51:44 +0000
Subject: [PATCH] [AArch64] Mangle names of all ARM64EC functions with entry
thunks
This better matches MSVC output in cases where static functions have their
addresses taken.
---
llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp | 2 +-
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 3 ++-
.../CodeGen/AArch64/arm64ec-entry-thunks-local-linkage.ll | 6 ++++--
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
index 91b4f18c73c93..0fa53d51142ad 100644
--- a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
@@ -710,7 +710,7 @@ bool AArch64Arm64ECCallLowering::processFunction(
// name (emitting the definition) can grab it from the metadata.
//
// FIXME: Handle functions with weak linkage?
- if (F.hasExternalLinkage() || F.hasWeakLinkage() || F.hasLinkOnceLinkage()) {
+ if (!F.hasLocalLinkage() || F.hasAddressTaken()) {
if (std::optional<std::string> MangledName =
getArm64ECMangledFunctionName(F.getName().str())) {
F.setMetadata("arm64ec_unmangled_name",
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index de247253eb18a..526c37d503b9c 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -1121,7 +1121,8 @@ void AArch64AsmPrinter::emitFunctionEntryLabel() {
TS->emitDirectiveVariantPCS(CurrentFnSym);
}
- if (TM.getTargetTriple().isWindowsArm64EC()) {
+ if (TM.getTargetTriple().isWindowsArm64EC() &&
+ !MF->getFunction().hasInternalLinkage()) {
// For ARM64EC targets, a function definition's name is mangled differently
// from the normal symbol. We emit the alias from the unmangled symbol to
// mangled symbol name here.
diff --git a/llvm/test/CodeGen/AArch64/arm64ec-entry-thunks-local-linkage.ll b/llvm/test/CodeGen/AArch64/arm64ec-entry-thunks-local-linkage.ll
index 00ae34bf4b00f..217f08be05218 100644
--- a/llvm/test/CodeGen/AArch64/arm64ec-entry-thunks-local-linkage.ll
+++ b/llvm/test/CodeGen/AArch64/arm64ec-entry-thunks-local-linkage.ll
@@ -2,7 +2,8 @@
; Validates when local linkage functions get a thunk generated.
-; Being called does not cause a thunk to be generated.
+; Being called does not cause a thunk to be generated or the symbol name to be mangled.
+; CHECK-NOT: "#does_not_have_addr_taken":
; CHECK-NOT: $ientry_thunk$cdecl$v$f;
define internal void @does_not_have_addr_taken(float) nounwind {
ret void
@@ -12,7 +13,8 @@ define void @calls_does_not_have_addr_taken() nounwind {
ret void
}
-; Having an address taken does cause a thunk to be generated.
+; Having an address taken does cause a thunk to be generated and the symbol name to be mangled.
+; CHECK: "#has_addr_taken":
; CHECK: $ientry_thunk$cdecl$v$i8;
define internal void @has_addr_taken(i64) nounwind {
ret void
More information about the llvm-commits
mailing list