blob: 57da4a0d926998a1db92b428005b339b2dcb5c9c [file] [log] [blame]
Nick Lewycky18f99072009-03-05 08:20:21 +00001#
Daniel Dunbaree0f32d2010-08-11 23:53:59 +00002# Get the linker version string.
3#
4# This macro is specific to LLVM.
5#
6AC_DEFUN([AC_LINK_GET_VERSION],
7 [AC_CACHE_CHECK([for linker version],[llvm_cv_link_version],
8 [
9 version_string="$(ld -v 2>&1 | head -1)"
10
11 # Check for ld64.
12 if (echo "$version_string" | grep -q "ld64"); then
Charles Davis8b376372012-02-28 02:55:41 +000013 llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\{0,1\}#\1#")
Daniel Dunbaree0f32d2010-08-11 23:53:59 +000014 else
15 llvm_cv_link_version=$(echo "$version_string" | sed -e "s#[^0-9]*\([0-9.]*\).*#\1#")
16 fi
17 ])
18 AC_DEFINE_UNQUOTED([HOST_LINK_VERSION],"$llvm_cv_link_version",
19 [Linker version detected at compile time.])
20])
21
22#
Nick Lewycky18f99072009-03-05 08:20:21 +000023# Determine if the system can handle the -R option being passed to the linker.
24#
25# This macro is specific to LLVM.
26#
27AC_DEFUN([AC_LINK_USE_R],
28[AC_CACHE_CHECK([for compiler -Wl,-R<path> option],[llvm_cv_link_use_r],
29[ AC_LANG_PUSH([C])
30 oldcflags="$CFLAGS"
31 CFLAGS="$CFLAGS -Wl,-R."
Dan Gohman39ed6782010-04-25 00:12:20 +000032 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
Nick Lewycky18f99072009-03-05 08:20:21 +000033 [llvm_cv_link_use_r=yes],[llvm_cv_link_use_r=no])
34 CFLAGS="$oldcflags"
35 AC_LANG_POP([C])
36])
37if test "$llvm_cv_link_use_r" = yes ; then
38 AC_DEFINE([HAVE_LINK_R],[1],[Define if you can use -Wl,-R. to pass -R. to the linker, in order to add the current directory to the dynamic linker search path.])
39 fi
40])
41
42#
43# Determine if the system can handle the -R option being passed to the linker.
44#
45# This macro is specific to LLVM.
46#
47AC_DEFUN([AC_LINK_EXPORT_DYNAMIC],
48[AC_CACHE_CHECK([for compiler -Wl,-export-dynamic option],
49 [llvm_cv_link_use_export_dynamic],
50[ AC_LANG_PUSH([C])
51 oldcflags="$CFLAGS"
52 CFLAGS="$CFLAGS -Wl,-export-dynamic"
Dan Gohman39ed6782010-04-25 00:12:20 +000053 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
Nick Lewycky18f99072009-03-05 08:20:21 +000054 [llvm_cv_link_use_export_dynamic=yes],[llvm_cv_link_use_export_dynamic=no])
55 CFLAGS="$oldcflags"
56 AC_LANG_POP([C])
57])
58if test "$llvm_cv_link_use_export_dynamic" = yes ; then
59 AC_DEFINE([HAVE_LINK_EXPORT_DYNAMIC],[1],[Define if you can use -Wl,-export-dynamic.])
60 fi
61])
62
Dan Gohmane05f6092010-04-16 22:58:15 +000063#
Dan Gohmanda612d62010-06-01 14:56:56 +000064# Determine if the system can handle the --version-script option being
Dan Gohmane05f6092010-04-16 22:58:15 +000065# passed to the linker.
66#
67# This macro is specific to LLVM.
68#
Dan Gohmanda612d62010-06-01 14:56:56 +000069AC_DEFUN([AC_LINK_VERSION_SCRIPT],
70[AC_CACHE_CHECK([for compiler -Wl,--version-script option],
71 [llvm_cv_link_use_version_script],
Dan Gohmane05f6092010-04-16 22:58:15 +000072[ AC_LANG_PUSH([C])
73 oldcflags="$CFLAGS"
74
75 # The following code is from the autoconf manual,
76 # "11.13: Limitations of Usual Tools".
77 # Create a temporary directory $tmp in $TMPDIR (default /tmp).
78 # Use mktemp if possible; otherwise fall back on mkdir,
79 # with $RANDOM to make collisions less likely.
80 : ${TMPDIR=/tmp}
81 {
82 tmp=`
83 (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
84 ` &&
85 test -n "$tmp" && test -d "$tmp"
86 } || {
87 tmp=$TMPDIR/foo$$-$RANDOM
88 (umask 077 && mkdir "$tmp")
89 } || exit $?
90
Dan Gohmanda612d62010-06-01 14:56:56 +000091 echo "{" > "$tmp/export.map"
92 echo " global: main;" >> "$tmp/export.map"
93 echo " local: *;" >> "$tmp/export.map"
94 echo "};" >> "$tmp/export.map"
Dan Gohmane05f6092010-04-16 22:58:15 +000095
Dan Gohmanda612d62010-06-01 14:56:56 +000096 CFLAGS="$CFLAGS -Wl,--version-script=$tmp/export.map"
Dan Gohman39ed6782010-04-25 00:12:20 +000097 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
Dan Gohman943005e2010-06-01 16:22:27 +000098 [llvm_cv_link_use_version_script=yes],[llvm_cv_link_use_version_script=no])
Dan Gohmanda612d62010-06-01 14:56:56 +000099 rm "$tmp/export.map"
Dan Gohmane05f6092010-04-16 22:58:15 +0000100 rmdir "$tmp"
101 CFLAGS="$oldcflags"
102 AC_LANG_POP([C])
103])
Dan Gohmanda612d62010-06-01 14:56:56 +0000104if test "$llvm_cv_link_use_version_script" = yes ; then
105 AC_SUBST(HAVE_LINK_VERSION_SCRIPT,1)
Dan Gohmane05f6092010-04-16 22:58:15 +0000106 fi
107])
108