[Mlir-commits] [llvm] [mlir] fix linking on riscv64 (PR #74167)

Vincent Palatin llvmlistbot at llvm.org
Fri Dec 1 18:59:06 PST 2023


https://github.com/vpalatin created https://github.com/llvm/llvm-project/pull/74167

As libatomic is not included in libgcc_s, when building on riscv64
(on Ubuntu 22.04) using rtlib set to libgcc and gnu ld as the linker,
the linking of a few utilities fails on some __atomic_X symbols provided by libatomic.

For dsymutils, actually reviews.llvm.org/D137799 has commented out the line potentially adding a
`-latomic` when linking by using the LLVM_ATOMIC_LIB variable without providing any reason. Revert this piece of the change.

For several libMLIR consumers, add the LLVM_ATOMIC_LIB variable where needed. 

>From e68c832491d193bc594f42591b0e851f609aa3bd Mon Sep 17 00:00:00 2001
From: Vincent Palatin <vpalatin at rivosinc.com>
Date: Thu, 23 Nov 2023 06:33:07 -0800
Subject: [PATCH 1/2] [dsymutil] fix linking on riscv64

As libatomic is not included in libgcc_s, when building on riscv64
(on Ubuntu 22.04) using rtlib set to libgcc and gnu ld as the linker,
the linking of dsymutil fails on some __atomic_X symbols provided by libatomic.

reviews.llvm.org/D137799 has commented out the line potentially adding a
`-latomic` when linking by using the LLVM_ATOMIC_LIB variable without
providing any reason. Revert this piece of the change.
---
 llvm/tools/dsymutil/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tools/dsymutil/CMakeLists.txt b/llvm/tools/dsymutil/CMakeLists.txt
index c612bfd9150c47f..de1da71a64dc124 100644
--- a/llvm/tools/dsymutil/CMakeLists.txt
+++ b/llvm/tools/dsymutil/CMakeLists.txt
@@ -44,4 +44,4 @@ if(APPLE AND NOT LLVM_TOOL_LLVM_DRIVER_BUILD)
   target_link_libraries(dsymutil PRIVATE "-framework CoreFoundation")
 endif(APPLE AND NOT LLVM_TOOL_LLVM_DRIVER_BUILD)
 
-# target_link_libraries(dsymutil PRIVATE ${LLVM_ATOMIC_LIB})
+target_link_libraries(dsymutil PRIVATE ${LLVM_ATOMIC_LIB})

>From 8750334ac04381bab54891cf1de97a67e101a90b Mon Sep 17 00:00:00 2001
From: Vincent Palatin <vpalatin at rivosinc.com>
Date: Thu, 23 Nov 2023 09:58:24 -0800
Subject: [PATCH 2/2] [mlir] fix linking on riscv64

As libatomic is not included in libgcc_s, when building on riscv64
(on Ubuntu 22.04) using rtlib set to libgcc and gnu ld as the linker,
the linking of several libMLIR consumers fails on some __atomic_X
symbols provided by libatomic.

Add the LLVM_ATOMIC_LIB variable potentially adding a `-latomic` when linking.
---
 mlir/lib/Pass/CMakeLists.txt                     | 2 ++
 mlir/lib/Tools/lsp-server-support/CMakeLists.txt | 2 ++
 mlir/tools/mlir-shlib/CMakeLists.txt             | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/mlir/lib/Pass/CMakeLists.txt b/mlir/lib/Pass/CMakeLists.txt
index 5ca9b4163bb8a8f..d2628aaa7274ec4 100644
--- a/mlir/lib/Pass/CMakeLists.txt
+++ b/mlir/lib/Pass/CMakeLists.txt
@@ -16,4 +16,6 @@ add_mlir_library(MLIRPass
   LINK_LIBS PUBLIC
   MLIRAnalysis
   MLIRIR
+  PRIVATE
+  ${LLVM_ATOMIC_LIB}
   )
diff --git a/mlir/lib/Tools/lsp-server-support/CMakeLists.txt b/mlir/lib/Tools/lsp-server-support/CMakeLists.txt
index 48a96016b792fce..8f7e26340067f1e 100644
--- a/mlir/lib/Tools/lsp-server-support/CMakeLists.txt
+++ b/mlir/lib/Tools/lsp-server-support/CMakeLists.txt
@@ -10,4 +10,6 @@ add_mlir_library(MLIRLspServerSupportLib
 
   LINK_LIBS PUBLIC
   MLIRSupport
+  PRIVATE
+  ${LLVM_ATOMIC_LIB}
   )
diff --git a/mlir/tools/mlir-shlib/CMakeLists.txt b/mlir/tools/mlir-shlib/CMakeLists.txt
index 32fe833cee4ea78..59e0f7078288355 100644
--- a/mlir/tools/mlir-shlib/CMakeLists.txt
+++ b/mlir/tools/mlir-shlib/CMakeLists.txt
@@ -39,6 +39,8 @@ if(LLVM_BUILD_LLVM_DYLIB)
     ${_OBJECTS}
     LINK_LIBS
     ${_DEPS}
+    PRIVATE
+    ${LLVM_ATOMIC_LIB}
 
     LINK_COMPONENTS
     ${mlir_llvm_link_components}



More information about the Mlir-commits mailing list