Skip to content

Commit 8d77b13

Browse files
committed
[mlir] Workaround for export lib generation on Windows for mlir_arm_sme_abi_stubs
Using mlir smake in downstream project faild with error ``` CMake Error at D:/projs/llvm/llvm-install/lib/cmake/mlir/MLIRTargets.cmake:2537 (message): The imported target "mlir_arm_sme_abi_stubs" references the file "D:/projs/llvm/llvm-install/lib/mlir_arm_sme_abi_stubs.lib" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "D:/projs/llvm/llvm-install/lib/cmake/mlir/MLIRTargets.cmake" but not all the files it references. Call Stack (most recent call first): D:/projs/llvm/llvm-install/lib/cmake/mlir/MLIRConfig.cmake:37 (include) mlir/CMakeLists.txt:5 (find_package) ``` Windows cmake needs export libaries but it seems they are only being generated if you have at least one exported symbol. Add a dummy symbol to lib (export macros is copied from other mlir runnner libs).
1 parent 55f067f commit 8d77b13

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

mlir/lib/ExecutionEngine/ArmSMEStubs.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
#include <cstdint>
1111
#include <iostream>
1212

13+
#ifdef _WIN32
14+
#ifndef MLIR_RUNNERUTILS_EXPORT
15+
#ifdef mlir_arm_sme_abi_stubs_EXPORTS
16+
// We are building this library
17+
#define MLIR_ARNSMEABISTUBS_EXPORT __declspec(dllexport)
18+
#else
19+
// We are using this library
20+
#define MLIR_ARNSMEABISTUBS_EXPORT __declspec(dllimport)
21+
#endif // mlir_runner_utils_EXPORTS
22+
#endif // MLIR_RUNNERUTILS_EXPORT
23+
#else
24+
#define MLIR_ARNSMEABISTUBS_EXPORT LLVM_ATTRIBUTE_WEAK
25+
#endif // _WIN32
26+
1327
// The actual implementation of these routines is in:
1428
// compiler-rt/lib/builtins/aarch64/sme-abi.S. These stubs allow the current
1529
// ArmSME tests to run without depending on compiler-rt. This works as we don't
@@ -19,7 +33,7 @@
1933

2034
extern "C" {
2135

22-
bool LLVM_ATTRIBUTE_WEAK __aarch64_sme_accessible() {
36+
bool MLIR_ARNSMEABISTUBS_EXPORT __aarch64_sme_accessible() {
2337
// The ArmSME tests are run within an emulator so we assume SME is available.
2438
return true;
2539
}
@@ -29,20 +43,20 @@ struct sme_state {
2943
int64_t x1;
3044
};
3145

32-
sme_state LLVM_ATTRIBUTE_WEAK __arm_sme_state() {
46+
sme_state MLIR_ARNSMEABISTUBS_EXPORT __arm_sme_state() {
3347
std::cerr << "[warning] __arm_sme_state() stubbed!\n";
3448
return sme_state{};
3549
}
3650

37-
void LLVM_ATTRIBUTE_WEAK __arm_tpidr2_restore() {
51+
void MLIR_ARNSMEABISTUBS_EXPORT __arm_tpidr2_restore() {
3852
std::cerr << "[warning] __arm_tpidr2_restore() stubbed!\n";
3953
}
4054

41-
void LLVM_ATTRIBUTE_WEAK __arm_tpidr2_save() {
55+
void MLIR_ARNSMEABISTUBS_EXPORT __arm_tpidr2_save() {
4256
std::cerr << "[warning] __arm_tpidr2_save() stubbed!\n";
4357
}
4458

45-
void LLVM_ATTRIBUTE_WEAK __arm_za_disable() {
59+
void MLIR_ARNSMEABISTUBS_EXPORT __arm_za_disable() {
4660
std::cerr << "[warning] __arm_za_disable() stubbed!\n";
4761
}
4862
}

mlir/lib/ExecutionEngine/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ if(LLVM_ENABLE_PIC)
181181
add_mlir_library(mlir_arm_sme_abi_stubs
182182
SHARED
183183
ArmSMEStubs.cpp)
184+
target_compile_definitions(mlir_arm_sme_abi_stubs PRIVATE mlir_arm_sme_abi_stubs_EXPORTS)
184185

185186
if(MLIR_ENABLE_CUDA_RUNNER)
186187
# Configure CUDA support. Using check_language first allows us to give a

0 commit comments

Comments
 (0)