@@ -373,6 +373,35 @@ if [ -n "$SAGE_LOCAL" ]; then
373373 # Construct and export LDFLAGS
374374 if [ " $UNAME " = " Darwin" ]; then
375375 LDFLAGS=" -L$SAGE_LOCAL /lib $LDFLAGS "
376+ # On OS X, use the old linker if it is available.
377+ # if "ld-classic" is present in the selected XCode
378+ # toolchain, add "-Wl,-ld_classic" to LDFLAGS (see #36599) unless
379+ # LD is already set, as it will be with conda on macOS. When the
380+ # selected toolchain is in the Xcode app the output of "xcode-select -p"
381+ # is "/Applications/Xcode.app/Contents/Developer", but "ld-classic" is
382+ # not in the subdirectory "usr/bin/" but rather in the subdirectory
383+ # "Toolchains/XcodeDefault.xctoolchain/usr/bin/". (See #37237.)
384+ if [ -z " $LD " ]; then
385+ # Running xcode-select on a system with no toolchain writes an
386+ # error message to stderr, so redirect stderr to /dev/null.
387+ XCODE_PATH=$( /usr/bin/xcode-select -p 2> /dev/null)
388+ if [ -n $XCODE_PATH ]; then
389+ if [ -x " $XCODE_PATH /usr/bin/ld-classic" -o \
390+ -x " $XCODE_PATH /Toolchains/XcodeDefault.xctoolchain/usr/bin/ld-classic" ]; then
391+ # Add -ld_classic only if -ld_classic is not deprecated.
392+ if [ -z " $( ld -ld_classic 2>&1 | grep ' ld_classic is deprecated' ) " ]; then
393+ LDFLAGS=" $LDFLAGS -Wl,-ld_classic"
394+ fi
395+ fi
396+ else
397+ # On a macOS system with no toolchain we don't want this script
398+ # to call gcc because that will also print an error message to
399+ # stderr. We can avoid this by setting AS and LD to their
400+ # default values.
401+ AS=as
402+ LD=ld
403+ fi
404+ fi
376405 fi
377406 if [ " $UNAME " = " Linux" ]; then
378407 LDFLAGS=" -L$SAGE_LOCAL /lib -Wl,-rpath,$SAGE_LOCAL /lib $LDFLAGS "
0 commit comments