[llvm] Set -rpath-link only if the path is nonempty. (PR #66852)
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 19:51:49 PDT 2023
https://github.com/jlebar created https://github.com/llvm/llvm-project/pull/66852
This cmake rule is used by external clients, who may or may not have
the LLVM_LIBRARY_OUTPUT_INTDIR variable set.
If it is not set, then we pass `-Wl,-rpath-link,` to the compiler. It
turns out that gcc and clang interpret this differently.
* gcc passes `-rpath-link ""` to the linker, which is what we want.
* clang passes `-rpath-link` to the linker. This is not what we want,
because then the linker gobbles the next command-line argument,
whatever it happens to be, and uses it as the -rpath-link target.
Fix this by passing -rpath-link only if we actually have a path we want.
>From 7e82110292a71f1b5ae6ae0f52d6601a72549f19 Mon Sep 17 00:00:00 2001
From: Justin Lebar <justin.lebar at gmail.com>
Date: Tue, 19 Sep 2023 18:45:36 -0700
Subject: [PATCH] Set -rpath-link only if the path is nonempty.
This cmake rule is used by external clients, who may or may not have
the LLVM_LIBRARY_OUTPUT_INTDIR variable set.
If it is not set, then we pass `-Wl,-rpath-link,` to the compiler. It
turns out that gcc and clang interpret this differently.
* gcc passes `-rpath-link ""` to the linker, which is what we want.
* clang passes `-rpath-link` to the linker. This is not what we want,
because then the linker gobbles the next command-line argument,
whatever it happens to be, and uses it as the -rpath-link target.
Fix this by passing -rpath-link only if we actually have a path we want.
---
llvm/cmake/modules/AddLLVM.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 77b4a51b13b8ca9..93011522e498e6e 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -2366,7 +2366,7 @@ function(llvm_setup_rpath name)
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-z,origin ")
endif()
- if(LLVM_LINKER_IS_GNULD)
+ if(LLVM_LINKER_IS_GNULD AND NOT ${LLVM_LIBRARY_OUTPUT_INTDIR} STREQUAL "")
# $ORIGIN is not interpreted at link time by ld.bfd
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ")
More information about the llvm-commits
mailing list