[llvm] [IR] Use EXPORTAS for ARM64EC mangled symbols with dllexport attribute. (PR #81940)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 16:01:21 PST 2024
https://github.com/cjacek updated https://github.com/llvm/llvm-project/pull/81940
>From 3f595145ce2e3e07dde16712b7e479bbb3067ed8 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 1/2] [IR] Use EXPORTAS for ARM64EC mangled symbols with
dllexport attribute.
---
llvm/lib/IR/Mangler.cpp | 9 +++++-
llvm/test/CodeGen/AArch64/dllexport.ll | 39 ++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp
index 3acac2c3e3db16..af9fd669aabc97 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,11 @@ void llvm::emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
} else {
Mangler.getNameWithPrefix(OS, GV, false);
}
+ if (TT.isWindowsArm64EC()) {
+ 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..5f2628619dcc3d 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-NOT-EC: -export:f
+; CHECK-GNU-NOT-EC: -export:#f,EXPORTAS,f
+; CHECK-GNU-EC: .ascii " -export:#g,EXPORTAS,g
+; CHECK-GNU-EC: .ascii " -export:#h,EXPORTAS,h
+; CHECK-GNU-NOT-EC: -export:i
+; CHECK-GNU-NOT-EC: -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-NOT-EC: /EXPORT:f
+; CHECK-MSVC-NOT-EC: /EXPORT:#f,EXPORTAS,f
+; CHECK-MSVC-EC: .ascii " /EXPORT:#g,EXPORTAS,g"
+; CHECK-MSVC-EC: .ascii " /EXPORT:#h,EXPORTAS,h"
+; CHECK-MSVC-NOT-EC: /EXPORT:i
+; CHECK-MSVC-NOT-EC: /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"
>From 4b56f9af99d8656a3c02abe4aaf2f9e1ca50bed2 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Fri, 16 Feb 2024 01:00:45 +0100
Subject: [PATCH 2/2] Fix tests
---
llvm/test/CodeGen/AArch64/dllexport.ll | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/test/CodeGen/AArch64/dllexport.ll b/llvm/test/CodeGen/AArch64/dllexport.ll
index 5f2628619dcc3d..580fb5fd9e79ee 100644
--- a/llvm/test/CodeGen/AArch64/dllexport.ll
+++ b/llvm/test/CodeGen/AArch64/dllexport.ll
@@ -74,12 +74,12 @@ define weak_odr dllexport void @l() {
; CHECK-MSVC: .ascii " /EXPORT:t"
; CHECK-MSVC: .ascii " /EXPORT:u"
-; CHECK-GNU-NOT-EC: -export:f
-; CHECK-GNU-NOT-EC: -export:#f,EXPORTAS,f
+; 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-NOT-EC: -export:i
-; CHECK-GNU-NOT-EC: -export:#i,EXPORTAS,i
+; 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"
@@ -92,12 +92,12 @@ define weak_odr dllexport void @l() {
; CHECK-GNU-EC: .ascii " -export:s"
; CHECK-GNU-EC: .ascii " -export:t"
; CHECK-GNU-EC: .ascii " -export:u"
-; CHECK-MSVC-NOT-EC: /EXPORT:f
-; CHECK-MSVC-NOT-EC: /EXPORT:#f,EXPORTAS,f
+; 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-NOT-EC: /EXPORT:i
-; CHECK-MSVC-NOT-EC: /EXPORT:#i,EXPORTAS,i
+; 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"
More information about the llvm-commits
mailing list