From e05f609b61c23846ee21a24a97631d2364f55078 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 16 Apr 2010 22:58:15 +0000 Subject: [PATCH] Add an autoconf check for -retain-symbols-file and conditionalize 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 | 4 ++++ Makefile.rules | 13 ++++++----- autoconf/configure.ac | 3 +++ autoconf/m4/link_options.m4 | 43 +++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Makefile.config.in b/Makefile.config.in index 1b61f0908a8..a3384e7af32 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -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@ diff --git a/Makefile.rules b/Makefile.rules index 9ff6c79b6e5..6e177813148 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -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 diff --git a/autoconf/configure.ac b/autoconf/configure.ac index 76083d27485..49a140cdc4a 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -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). diff --git a/autoconf/m4/link_options.m4 b/autoconf/m4/link_options.m4 index 66036de433d..3442e465674 100644 --- a/autoconf/m4/link_options.m4 +++ b/autoconf/m4/link_options.m4 @@ -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 +]) + -- 2.34.1