[Mlir-commits] [mlir] [mlir] Fix ArmSME ABI stub exports (PR #224629)

Fabrice de Gans llvmlistbot at llvm.org
Fri Sep 18 06:13:40 PDT 2026


https://github.com/Steelskin created https://github.com/llvm/llvm-project/pull/224629

Previously, the `MLIR_ARMSMEABISTUBS_EXPORTED` macro would expand to `__declspec(dllimport)` when building LLVM as a dylib on Windows. This would cause a build failure since it is an incorrect annotation on a function definition.

The intent here is to always export the symbol, so these changes use the `LLVM_ALWAYS_EXPORT` macro, which properly expands to the right attribute depending on the compiler / platform.

The effort to build LLVM as a dylib is tracked in #109483.

>From 8d36efdd222d80c1c23d186f3dd3b81f180b49ac Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <steelskin at gmail.com>
Date: Fri, 18 Sep 2026 14:57:40 +0200
Subject: [PATCH] [mlir] Fix ArmSME ABI stub exports

Previously, the `MLIR_ARMSMEABISTUBS_EXPORTED` macro would expand to
`__declspec(dllimport)` when building LLVM as a dylib on Windows. This
would cause a build failure since it is an incorrect annotation on a
function definition.

The intent here is to always export the symbol, so these changes use
the `LLVM_ALWAYS_EXPORT` macro, which properly expands to the right
attribute depending on the compiler / platform.
---
 mlir/lib/ExecutionEngine/ArmSMEStubs.cpp | 23 ++++-------------------
 mlir/lib/ExecutionEngine/CMakeLists.txt  |  1 -
 2 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/mlir/lib/ExecutionEngine/ArmSMEStubs.cpp b/mlir/lib/ExecutionEngine/ArmSMEStubs.cpp
index 8abd2073494c3..3f0ef52e7c8e8 100644
--- a/mlir/lib/ExecutionEngine/ArmSMEStubs.cpp
+++ b/mlir/lib/ExecutionEngine/ArmSMEStubs.cpp
@@ -10,21 +10,6 @@
 #include <cstdint>
 #include <iostream>
 
-#if (defined(_WIN32) || defined(__CYGWIN__))
-#ifndef MLIR_ARMSMEABISTUBS_EXPORTED
-#ifdef mlir_arm_sme_abi_stubs_EXPORTS
-// We are building this library
-#define MLIR_ARMSMEABISTUBS_EXPORTED __declspec(dllexport)
-#else
-// We are using this library
-#define MLIR_ARMSMEABISTUBS_EXPORTED __declspec(dllimport)
-#endif // mlir_arm_sme_abi_stubs_EXPORTS
-#endif // MLIR_ARMSMEABISTUBS_EXPORTED
-#else
-#define MLIR_ARMSMEABISTUBS_EXPORTED                                           \
-  __attribute__((visibility("default"))) LLVM_ATTRIBUTE_WEAK
-#endif // (defined(_WIN32) || defined(__CYGWIN__))
-
 // The actual implementation of these routines is in:
 // compiler-rt/lib/builtins/aarch64/sme-abi.S. These stubs allow the current
 // ArmSME tests to run without depending on compiler-rt. This works as we don't
@@ -39,20 +24,20 @@ struct sme_state {
   int64_t x1;
 };
 
-sme_state MLIR_ARMSMEABISTUBS_EXPORTED __arm_sme_state() {
+LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_WEAK sme_state __arm_sme_state() {
   std::cerr << "[warning] __arm_sme_state() stubbed!\n";
   return sme_state{};
 }
 
-void MLIR_ARMSMEABISTUBS_EXPORTED __arm_tpidr2_restore() {
+LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_WEAK void __arm_tpidr2_restore() {
   std::cerr << "[warning] __arm_tpidr2_restore() stubbed!\n";
 }
 
-void MLIR_ARMSMEABISTUBS_EXPORTED __arm_tpidr2_save() {
+LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_WEAK void __arm_tpidr2_save() {
   std::cerr << "[warning] __arm_tpidr2_save() stubbed!\n";
 }
 
-void MLIR_ARMSMEABISTUBS_EXPORTED __arm_za_disable() {
+LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_WEAK void __arm_za_disable() {
   std::cerr << "[warning] __arm_za_disable() stubbed!\n";
 }
 }
diff --git a/mlir/lib/ExecutionEngine/CMakeLists.txt b/mlir/lib/ExecutionEngine/CMakeLists.txt
index 3199c88313087..f9403b62425a0 100644
--- a/mlir/lib/ExecutionEngine/CMakeLists.txt
+++ b/mlir/lib/ExecutionEngine/CMakeLists.txt
@@ -271,7 +271,6 @@ if(LLVM_ENABLE_PIC)
     # dlopen-ed.
     DISABLE_PCH_REUSE
   )
-  target_compile_definitions(mlir_arm_sme_abi_stubs PRIVATE mlir_arm_sme_abi_stubs_EXPORTS)
 
   add_mlir_library(mlir_arm_runner_utils
     SHARED



More information about the Mlir-commits mailing list