Test whether ld flags exist before using them
authorIan Lynagh <igloo@earth.li>
Sun, 27 Nov 2011 13:25:51 +0000 (13:25 +0000)
committerIan Lynagh <igloo@earth.li>
Sun, 27 Nov 2011 13:33:43 +0000 (13:33 +0000)
Some platforms use linkers that don't support the --hash-size=31 and
--reduce-memory-overheads flags.

aclocal.m4
configure.ac
distrib/configure.ac.in

index f6f1f2b..4d65e4e 100644 (file)
@@ -426,8 +426,16 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
     fi
 
     # Reduce memory usage when linking. See trac #5240.
-    $3="$$3 -Wl,--hash-size=31 -Wl,--reduce-memory-overheads"
-    $4="$$4     --hash-size=31     --reduce-memory-overheads"
+    if test -n "$LdHashSize31"
+    then
+        $3="$$3 -Wl,$LdHashSize31"
+        $4="$$4     $LdHashSize31"
+    fi
+    if test -n "$LdReduceMemoryOverheads"
+    then
+        $3="$$3 -Wl,$LdReduceMemoryOverheads"
+        $4="$$4     $LdReduceMemoryOverheads"
+    fi
 
     rm -f conftest.c conftest.o
     AC_MSG_RESULT([done])
@@ -774,30 +782,57 @@ AC_SUBST(Alex3)
 ])
 
 
-# FP_PROG_LD_X
-# ------------
-# Sets the output variable LdXFlag to -x if ld supports this flag, otherwise the
-# variable's value is empty.
-AC_DEFUN([FP_PROG_LD_X],
+# FP_PROG_LD_FLAG
+# ---------------
+# Sets the output variable $2 to $1 if ld supports the $1 flag.
+# Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_FLAG],
 [
-AC_CACHE_CHECK([whether ld understands -x], [fp_cv_ld_x],
+AC_CACHE_CHECK([whether ld understands $1], [fp_cv_$2],
 [echo 'foo() {}' > conftest.c
 ${CC-cc} -c conftest.c
-if ${LdCmd} -r -x -o conftest2.o conftest.o > /dev/null 2>&1; then
-   fp_cv_ld_x=yes
+if ${LdCmd} -r $1 -o conftest2.o conftest.o > /dev/null 2>&1; then
+   fp_cv_$2=$1
 else
-   fp_cv_ld_x=no
+   fp_cv_$2=
 fi
 rm -rf conftest*])
-if test "$fp_cv_ld_x" = yes; then
-  LdXFlag=-x
-else
-  LdXFlag=
-fi
+$2=$fp_cv_$2
+])# FP_PROG_LD_FLAG
+
+
+# FP_PROG_LD_X
+# ------------
+# Sets the output variable LdXFlag to -x if ld supports this flag.
+# Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_X],
+[
+FP_PROG_LD_FLAG([-x],[LdXFlag])
 AC_SUBST([LdXFlag])
 ])# FP_PROG_LD_X
 
 
+# FP_PROG_LD_HashSize31
+# ------------
+# Sets the output variable LdHashSize31 to --hash-size=31 if ld supports
+# this flag. Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_HashSize31],
+[
+FP_PROG_LD_FLAG([--hash-size=31],[LdHashSize31])
+])# FP_PROG_LD_HashSize31
+
+
+# FP_PROG_LD_ReduceMemoryOverheads
+# ------------
+# Sets the output variable LdReduceMemoryOverheads to
+# --reduce-memory-overheads if ld supports this flag.
+# Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_ReduceMemoryOverheads],
+[
+FP_PROG_LD_FLAG([--reduce-memory-overheads],[LdReduceMemoryOverheads])
+])# FP_PROG_LD_ReduceMemoryOverheads
+
+
 # FP_PROG_LD_BUILD_ID
 # ------------
 
index 3433381..475f734 100644 (file)
@@ -424,6 +424,9 @@ dnl ** look to see if we have a C compiler using an llvm back end.
 dnl
 FP_CC_LLVM_BACKEND
 
+FP_PROG_LD_HashSize31
+FP_PROG_LD_ReduceMemoryOverheads
+
 FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
 FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAGE1],[CONF_LD_LINKER_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
index 8af06d2..a9fc134 100644 (file)
@@ -56,6 +56,9 @@ FIND_GCC()
 FP_GCC_VERSION
 AC_PROG_CPP
 
+FP_PROG_LD_HashSize31
+FP_PROG_LD_ReduceMemoryOverheads
+
 #
 dnl ** Check gcc version and flags we need to pass it **
 #