Add an autoconf check for -retain-symbols-file and conditionalize
authorDan Gohman <gohman@apple.com>
Fri, 16 Apr 2010 22:58:15 +0000 (22:58 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 16 Apr 2010 22:58:15 +0000 (22:58 +0000)
use of that option with it. This eliminates an imprecise "Linux"
test, and should help support old versions of gold.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101560 91177308-0d34-0410-b5e6-96231b3b80d8

Makefile.config.in
Makefile.rules
autoconf/configure.ac
autoconf/m4/link_options.m4

index 1b61f0908a8cefb8cc06bafd2e17ad3d5ff62d01..a3384e7af32f10bdc766f2eab61034032d6e8195 100644 (file)
@@ -337,3 +337,7 @@ ENABLE_LLVMC_DYNAMIC_PLUGINS = 1
 NO_MISSING_FIELD_INITIALIZERS = @NO_MISSING_FIELD_INITIALIZERS@
 # -Wno-variadic-macros
 NO_VARIADIC_MACROS = @NO_VARIADIC_MACROS@
+
+# Flags supported by the linker.
+# bfd ld / gold -retain-symbols-file file
+HAVE_LINK_RETAIN_SYMBOLS_FILE = @HAVE_LINK_RETAIN_SYMBOLS_FILE@
index 9ff6c79b6e5d443ad6f8ac9b894e3f825302af0d..6e177813148585086823c4595ad18306e0fe2eda 100644 (file)
@@ -561,7 +561,7 @@ ifeq ($(HOST_OS),Darwin)
   # Get "4" out of 10.4 for later pieces in the makefile.
   DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
 
-  SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
+  SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined,suppress \
                     -dynamiclib
   ifneq ($(ARCH),ARM)
     SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
@@ -990,13 +990,12 @@ endif
 # Now add the linker command-line options to use the native export file.
 
 ifeq ($(HOST_OS),Darwin)
-LLVMLibsOptions += -Wl,-exported_symbols_list -Wl,$(NativeExportsFile)
+LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
 endif
 
-# This isn't really Linux-specific; it works at least on gold and bfd ld, but
-# there's no convenient way to detect it.
-ifeq ($(HOST_OS),Linux)
-LLVMLibsOptions += -Wl,-retain-symbols-file -Wl,$(NativeExportsFile)
+# gold, bfd ld, etc.
+ifeq ($(HAVE_LINK_RETAIN_SYMBOLS_FILE),1)
+LLVMLibsOptions += -Wl,-retain-symbols-file,$(NativeExportsFile)
 endif
 
 endif
@@ -1297,7 +1296,7 @@ ifeq ($(HOST_OS),Darwin)
 
 # Tiger tools don't support this.
 ifneq ($(DARWIN_MAJVERS),4)
-LD.Flags += -Wl,-exported_symbol -Wl,_main
+LD.Flags += -Wl,-exported_symbol,_main
 endif
 endif
 
index 76083d27485ce33e20ea931204c615fee4cc684b..49a140cdc4a653392a61fc358bc4a7b3200156f4 100644 (file)
@@ -1022,6 +1022,9 @@ AC_LINK_USE_R
 dnl Determine whether the linker supports the -export-dynamic option.
 AC_LINK_EXPORT_DYNAMIC
 
+dnl Determine whether the linker supports the -retain-symbols-file option.
+AC_LINK_RETAIN_SYMBOLS_FILE
+
 dnl Check for libtool and the library that has dlopen function (which must come
 dnl before the AC_PROG_LIBTOOL check in order to enable dlopening libraries with
 dnl libtool).
index 66036de433d3c306b6b453714c6c00a2648ff05d..3442e46567406182516a9eb70f060b752d2a89bc 100644 (file)
@@ -39,3 +39,46 @@ if test "$llvm_cv_link_use_export_dynamic" = yes ; then
   fi
 ])
 
+#
+# Determine if the system can handle the -retain-symbols-file option being
+# passed to the linker.
+#
+# This macro is specific to LLVM.
+#
+AC_DEFUN([AC_LINK_RETAIN_SYMBOLS_FILE],
+[AC_CACHE_CHECK([for compiler -Wl,-retain-symbols-file option],
+                [llvm_cv_link_use_retain_symbols_file],
+[ AC_LANG_PUSH([C])
+  oldcflags="$CFLAGS"
+
+  # The following code is from the autoconf manual,
+  # "11.13: Limitations of Usual Tools".
+  # Create a temporary directory $tmp in $TMPDIR (default /tmp).
+  # Use mktemp if possible; otherwise fall back on mkdir,
+  # with $RANDOM to make collisions less likely.
+  : ${TMPDIR=/tmp}
+  {
+    tmp=`
+      (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
+    ` &&
+    test -n "$tmp" && test -d "$tmp"
+  } || {
+    tmp=$TMPDIR/foo$$-$RANDOM
+    (umask 077 && mkdir "$tmp")
+  } || exit $?
+
+  echo "main" > "$tmp/exports"
+
+  CFLAGS="$CFLAGS -Wl,-retain-symbols-file=$tmp/exports"
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[int main() { return 0; }]])],
+    [llvm_cv_link_use_retain_symbols_file=yes],[llvm_cv_link_use_retain_symbols_file=no])
+  rm "$tmp/exports"
+  rmdir "$tmp"
+  CFLAGS="$oldcflags"
+  AC_LANG_POP([C])
+])
+if test "$llvm_cv_link_use_retain_symbols_file" = yes ; then
+  AC_SUBST(HAVE_LINK_RETAIN_SYMBOLS_FILE,1)
+  fi
+])
+