[llvm] [IR] Use EXPORTAS for ARM64EC mangled symbols with dllexport attribute. (PR #81940)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 29 07:04:45 PDT 2024
https://github.com/cjacek updated https://github.com/llvm/llvm-project/pull/81940
>From c7a34699625cc4ab7209bc3999dde98b1a77ea31 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Mon, 5 Feb 2024 22:04:23 +0100
Subject: [PATCH] [IR] Use EXPORTAS for ARM64EC mangled symbols with dllexport
attribute.
---
llvm/lib/IR/Mangler.cpp | 14 ++++++++-
llvm/test/CodeGen/AArch64/dllexport.ll | 39 ++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp
index 3acac2c3e3db16..c4e8f005d6c8a9 100644
--- a/llvm/lib/IR/Mangler.cpp
+++ b/llvm/lib/IR/Mangler.cpp
@@ -18,8 +18,10 @@
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
+#include "llvm/Object/COFF.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
+
using namespace llvm;
namespace {
@@ -192,7 +194,7 @@ void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
// Check if the name needs quotes to be safe for the linker to interpret.
static bool canBeUnquotedInDirective(char C) {
- return isAlnum(C) || C == '_' || C == '@';
+ return isAlnum(C) || C == '_' || C == '@' || C == '#';
}
static bool canBeUnquotedInDirective(StringRef Name) {
@@ -233,6 +235,16 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
} else {
Mangler.getNameWithPrefix(OS, GV, false);
}
+ if (TT.isWindowsArm64EC()) {
+ // Use EXPORTAS for mangled ARM64EC symbols.
+ // FIXME: During LTO, we're invoked prior to the EC lowering pass,
+ // so symbols are not yet mangled. Emitting the unmangled name
+ // typically functions correctly; the linker can resolve the export
+ // with the demangled alias.
+ if (std::optional<std::string> demangledName =
+ object::getArm64ECDemangledFunctionName(GV->getName()))
+ OS << ",EXPORTAS," << *demangledName;
+ }
if (NeedQuotes)
OS << "\"";
diff --git a/llvm/test/CodeGen/AArch64/dllexport.ll b/llvm/test/CodeGen/AArch64/dllexport.ll
index 81ba674a0dedc1..580fb5fd9e79ee 100644
--- a/llvm/test/CodeGen/AArch64/dllexport.ll
+++ b/llvm/test/CodeGen/AArch64/dllexport.ll
@@ -1,5 +1,7 @@
; RUN: llc -mtriple aarch64-windows-gnu -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-GNU
; RUN: llc -mtriple aarch64-windows-msvc -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-MSVC
+; RUN: llc -mtriple arm64ec-windows-gnu -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-GNU-EC
+; RUN: llc -mtriple arm64ec-windows-msvc -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-MSVC-EC
define void @f() {
ret void
@@ -71,3 +73,40 @@ define weak_odr dllexport void @l() {
; CHECK-MSVC: .ascii " /EXPORT:s"
; CHECK-MSVC: .ascii " /EXPORT:t"
; CHECK-MSVC: .ascii " /EXPORT:u"
+
+; CHECK-GNU-EC-NOT: -export:f
+; CHECK-GNU-EC-NOT: -export:#f,EXPORTAS,f
+; CHECK-GNU-EC: .ascii " -export:#g,EXPORTAS,g
+; CHECK-GNU-EC: .ascii " -export:#h,EXPORTAS,h
+; CHECK-GNU-EC-NOT: -export:i
+; CHECK-GNU-EC-NOT: -export:#i,EXPORTAS,i
+; CHECK-GNU-EC: .ascii " -export:#j,EXPORTAS,j"
+; CHECK-GNU-EC: .ascii " -export:#k,EXPORTAS,k"
+; CHECK-GNU-EC: .ascii " -export:#l,EXPORTAS,l"
+; CHECK-GNU-EC: .ascii " -export:m,data"
+; CHECK-GNU-EC: .ascii " -export:n,data"
+; CHECK-GNU-EC: .ascii " -export:o,data"
+; CHECK-GNU-EC: .ascii " -export:p,data"
+; CHECK-GNU-EC: .ascii " -export:q,data"
+; CHECK-GNU-EC: .ascii " -export:r"
+; CHECK-GNU-EC: .ascii " -export:s"
+; CHECK-GNU-EC: .ascii " -export:t"
+; CHECK-GNU-EC: .ascii " -export:u"
+; CHECK-MSVC-EC-NOT: /EXPORT:f
+; CHECK-MSVC-EC-NOT: /EXPORT:#f,EXPORTAS,f
+; CHECK-MSVC-EC: .ascii " /EXPORT:#g,EXPORTAS,g"
+; CHECK-MSVC-EC: .ascii " /EXPORT:#h,EXPORTAS,h"
+; CHECK-MSVC-EC-NOT: /EXPORT:i
+; CHECK-MSVC-EC-NOT: /EXPORT:#i,EXPORTAS,i
+; CHECK-MSVC-EC: .ascii " /EXPORT:#j,EXPORTAS,j"
+; CHECK-MSVC-EC: .ascii " /EXPORT:#k,EXPORTAS,k"
+; CHECK-MSVC-EC: .ascii " /EXPORT:#l,EXPORTAS,l"
+; CHECK-MSVC-EC: .ascii " /EXPORT:m,DATA"
+; CHECK-MSVC-EC: .ascii " /EXPORT:n,DATA"
+; CHECK-MSVC-EC: .ascii " /EXPORT:o,DATA"
+; CHECK-MSVC-EC: .ascii " /EXPORT:p,DATA"
+; CHECK-MSVC-EC: .ascii " /EXPORT:q,DATA"
+; CHECK-MSVC-EC: .ascii " /EXPORT:r"
+; CHECK-MSVC-EC: .ascii " /EXPORT:s"
+; CHECK-MSVC-EC: .ascii " /EXPORT:t"
+; CHECK-MSVC-EC: .ascii " /EXPORT:u"
More information about the llvm-commits
mailing list