@@ -136,7 +136,6 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
136
136
flags=(
137
137
" -L@BREW_PREFIX@/opt/libffi/lib"
138
138
" -L@BREW_PREFIX@/lib"
139
- " -L@LLVM_LIBRARY_DIR@"
140
139
" -Wl,-u,_table_getArgumentSortsForTag"
141
140
" -I" " @BREW_PREFIX@/include"
142
141
)
@@ -158,6 +157,19 @@ else
158
157
set_visibility_hidden=" $LIBDIR /libSetVisibilityHidden.so"
159
158
fi
160
159
160
+ # On macOS, we get libunwind supplied as part of the developer tools in the OS,
161
+ # and so don't need to link it directly. If we instead try to explictly link
162
+ # against the libunwind that's part of Homebrew-supplied LLVM, it's easy to end
163
+ # up in a situation where exceptions thrown in a shared library are not
164
+ # compatible with the unwinding machinery in the main application binary. This
165
+ # then manifests as BAD_ACCESS errors (or similar) when an exception is thrown,
166
+ # _even if the exception should in principle be caught_.
167
+ if [[ " $OSTYPE " == " darwin" * ]]; then
168
+ libunwind=" "
169
+ else
170
+ libunwind=" -lunwind"
171
+ fi
172
+
161
173
# When building the Python AST module, there's no runtime and no main file, so
162
174
# we skip this entire step. The library code is just C++, so we can skip
163
175
# straight to invoking the C++ compiler.
@@ -207,7 +219,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
207
219
start_whole_archive=" -force_load"
208
220
end_whole_archive=" "
209
221
210
- flags+=(" -Wl,-flat_namespace " " -Wl,- undefined" " -Wl,dynamic_lookup" )
222
+ flags+=(" -Wl,-undefined" " -Wl,dynamic_lookup" )
211
223
else
212
224
start_whole_archive=" -Wl,--whole-archive"
213
225
end_whole_archive=" -Wl,--no-whole-archive"
@@ -218,9 +230,13 @@ if [ "$main" = "static" ]; then
218
230
elif [[ " $main " =~ " python" ]]; then
219
231
# Don't link jemalloc when building a python library; it clashes with the
220
232
# pymalloc implementation that Python expects you to use.
221
- all_libraries=(" ${libraries[@]} " " -lgmp" " -lgmpxx" " -lmpfr" " -lpthread" " -ldl" " -lffi" " -lunwind " )
233
+ all_libraries=(" ${libraries[@]} " " -lgmp" " -lgmpxx" " -lmpfr" " -lpthread" " -ldl" " -lffi" " $libunwind " )
222
234
flags+=(" -fPIC" " -shared" " -I${INCDIR} " " -fvisibility=hidden" )
223
235
236
+ if [[ " $OSTYPE " == " darwin" * ]]; then
237
+ flags+=(" -Wl,-flat_namespace" )
238
+ fi
239
+
224
240
read -r -a python_include_flags <<< " $(" ${python_cmd} " -m pybind11 --includes)"
225
241
flags+=(" ${python_include_flags[@]} " )
226
242
@@ -240,11 +256,11 @@ elif [ "$main" = "c" ]; then
240
256
241
257
# Avoid jemalloc for similar reasons as Python; we don't know who is loading
242
258
# this library so don't want to impose it.
243
- all_libraries=(" ${libraries[@]} " " -lgmp" " -lgmpxx" " -lmpfr" " -lpthread" " -ldl" " -lffi" " -lunwind " )
259
+ all_libraries=(" ${libraries[@]} " " -lgmp" " -lgmpxx" " -lmpfr" " -lpthread" " -ldl" " -lffi" " $libunwind " )
244
260
flags+=(" -fPIC" " -shared" " $start_whole_archive " " $LIBDIR /libkllvmcruntime.a" " $end_whole_archive " )
245
261
clangpp_args+=(" -o" " ${output_file} " )
246
262
else
247
- all_libraries=(" ${libraries[@]} " " -lgmp" " -lgmpxx" " -lmpfr" " -lpthread" " -ldl" " -lffi" " -ljemalloc" " -lunwind " )
263
+ all_libraries=(" ${libraries[@]} " " -lgmp" " -lgmpxx" " -lmpfr" " -lpthread" " -ldl" " -lffi" " -ljemalloc" " $libunwind " )
248
264
fi
249
265
250
266
if $link ; then
0 commit comments