Skip to content

Commit

Permalink
configure: Make sure we try all possible linkers
Browse files Browse the repository at this point in the history
Previously if we had both ld.lld and ld.gold installed but a gcc which
didn't support -fuse-ld=lld we would fail when trying ld.lld and fall
immediately back to plain ld. Now we will try ld.gold as well. This was
brought to light by #14280, where using ld.bfd resulted in a broken
stage2 compiler.

Test Plan: Configure

Reviewers: angerman, hvr, austin

Reviewed By: angerman

Subscribers: rwbarton, thomie, erikd

GHC Trac Issues: #14280

Differential Revision: https://phabricator.haskell.org/D4038
  • Loading branch information
bgamari committed Sep 27, 2017
1 parent 03009aa commit a10729f
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2331,28 +2331,51 @@ AC_DEFUN([FIND_LD],[
[],
[enable_ld_override=yes])
if test "x$enable_ld_override" = "xyes"; then
TmpLd="$LD" # In case the user set LD
AC_CHECK_TARGET_TOOLS([TmpLd], [ld.lld ld.gold ld])
out=`$TmpLd --version`
case $out in
"GNU ld"*) FP_CC_LINKER_FLAG_TRY(bfd, $2) ;;
"GNU gold"*) FP_CC_LINKER_FLAG_TRY(gold, $2) ;;
"LLD"*) FP_CC_LINKER_FLAG_TRY(lld, $2) ;;
*) AC_MSG_NOTICE([unknown linker version $out]) ;;
esac
if test "z$$2" = "z"; then
AC_MSG_NOTICE([unable to convince '$CC' to use linker '$TmpLd'])
find_ld() {
# Make sure the user didn't specify LD manually.
if test "z$LD" != "z"; then
AC_CHECK_TARGET_TOOL([LD], [ld])
else
LD="$TmpLd"
return
fi
else
# Manually iterate over possible names since we want to ensure that, e.g.,
# if ld.lld is installed but gcc doesn't support -fuse-ld=lld, that we
# then still try ld.gold and -fuse-ld=gold.
for possible_ld in ld.lld ld.gold ld; do
TmpLd="" # In case the user set LD
AC_CHECK_TARGET_TOOL([TmpLd], [$possible_ld])
if test "x$TmpLd" = "x"; then continue; fi
out=`$TmpLd --version`
case $out in
"GNU ld"*) FP_CC_LINKER_FLAG_TRY(bfd, $2) ;;
"GNU gold"*) FP_CC_LINKER_FLAG_TRY(gold, $2) ;;
"LLD"*) FP_CC_LINKER_FLAG_TRY(lld, $2) ;;
*) AC_MSG_NOTICE([unknown linker version $out]) ;;
esac
if test "z$$2" = "z"; then
AC_MSG_NOTICE([unable to convince '$CC' to use linker '$TmpLd'])
# a terrible hack to prevent autoconf from caching the previous
# AC_CHECK_TARGET_TOOL result since next time we'll be looking
# for another ld variant.
$as_unset ac_cv_prog_ac_ct_TmpLd
else
LD="$TmpLd"
return
fi
done
# Fallback
AC_CHECK_TARGET_TOOL([LD], [ld])
fi
}
if test "x$enable_ld_override" = "xyes"; then
find_ld
else
AC_CHECK_TARGET_TOOL([LD], [ld])
fi
CHECK_LD_COPY_BUG([$1])
CHECK_LD_COPY_BUG([$1])
])

# LocalWords: fi

0 comments on commit a10729f

Please sign in to comment.