Skip to content

Commit 0ec3daf

Browse files
authored
Link libunwind properly on macos (#1093)
On macOS, we need to look for `libunwind` as an LLVM library, rather than a system-installed dependency. This means adding some additional logic to the logic that assembles compiler flags when invoking `clang`; we can't directly look for `@BREW_PREFIX@/opt/llvm/...` because we don't necessarily know what formula version the user has installed.
1 parent 836301a commit 0ec3daf

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

bin/llvm-kompile-clang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
136136
flags=(
137137
"-L@BREW_PREFIX@/opt/libffi/lib"
138138
"-L@BREW_PREFIX@/lib"
139+
"-L@LLVM_LIBRARY_DIR@"
139140
"-Wl,-u,_table_getArgumentSortsForTag"
140141
"-I" "@BREW_PREFIX@/include"
141142
)

cmake/FindLLVM.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ find_program(LLDB lldb
2929
PATHS ${LLVM_TOOLS_BINARY_DIR}
3030
NO_DEFAULT_PATH)
3131

32+
execute_process(
33+
COMMAND "${LLVM_TOOLS_BINARY_DIR}/llvm-config" "--libdir"
34+
OUTPUT_VARIABLE LLVM_LIBRARY_DIR
35+
OUTPUT_STRIP_TRAILING_WHITESPACE)
36+
3237
if(NOT OPT)
3338
message(FATAL_ERROR "Could not find an opt binary. Is llvm installed on your PATH?")
3439
endif()

nix/llvm-backend.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ stdenv.mkDerivation {
4242
--replace '"-ltinfo"' '"-L${ncurses}/lib" "-ltinfo"' \
4343
--replace '"-lunwind"' '"-L${libunwind}/lib" "-lunwind"' \
4444
--replace '"-L@BREW_PREFIX@/opt/libffi/lib"' ' ' \
45+
--replace '"-L@LLVM_LIBRARY_DIR@"' ' ' \
4546
--replace '-L@BREW_PREFIX@/lib' '-L${libcxx}/lib' \
4647
--replace '-I "$(dirname "$0")"/../include/kllvm' \
4748
'-I "$(dirname "$0")"/../include/kllvm -I ${boost.dev}/include -I ${fmt.dev}/include'

0 commit comments

Comments
 (0)