aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac38
-rw-r--r--m4/link_options.m4128
2 files changed, 158 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index 521d7115..a85d304e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,6 +9,7 @@
####################
# m4 includes
m4_include(m4/acx_pthread.m4)
+m4_include(m4/link_options.m4)
####################
# Autoconf/Automake Initialization
@@ -44,17 +45,38 @@ AC_SUBST(MCLD_VERSION)
AC_DEFINE_UNQUOTED([MCLD_VERSION], ["$MCLD_VERSION"])
AH_TEMPLATE([MCLD_VERSION], [MCLINKER version])
-####################
-# Languages
-if test "$build_alias" != "$host_alias"; then
- # To reduce binary size
- CFLAGS="-Os -ffunction-sections -fdata-sections -fvisibility=hidden"
- CXXFLAGS="-Os -ffunction-sections -fdata-sections -fvisibility=hidden"
- LDFLAGS="-Wl,--gc-sections"
-fi
AC_PROG_CC
AC_PROG_CXX
+####################
+# --enable-shrink-binary-size : check whether they want to shrink mclinker size:
+AC_ARG_ENABLE(shrink-binary-size, AS_HELP_STRING(
+ --enable-shrink-binary-size,[Shrink mclinker size (default is NO)]),,enableval="no")
+
+if test ${enableval} = "no" ; then
+ AC_SUBST(ENABLE_SHRINK_BINARY_SIZE,[0])
+else
+ AC_SUBST(ENABLE_SHRINK_BINARY_SIZE,[1])
+fi
+
+if test "$ENABLE_SHRINK_BINARY_SIZE" = "1"; then
+ ####################
+ # Compiler flags for binary size reduction
+ AC_MSG_CHECKING([binary size reduction compiler flags])
+ CXX_FLAG_CHECK(DATA_SECTIONS, [-fdata-sections])
+ CXX_FLAG_CHECK(FUNCTION_SECTIONS, [-ffunction-sections])
+ CXX_FLAG_CHECK(VISIBILITY_INLINES_HIDDEN, [-fvisibility-inlines-hidden])
+ CFLAGS="-Os $CFLAGS $DATA_SECTIONS $FUNCTION_SECTIONS $VISIBILITY_INLINES_HIDDEN"
+ CXXFLAGS="-Os $CXXFLAGS $DATA_SECTIONS $FUNCTION_SECTIONS $VISIBILITY_INLINES_HIDDEN"
+
+ ####################
+ # Linker flags for binary size reduction
+ # (cooperative with -ffunction-sections, -fdata-sections)
+ AC_MSG_CHECKING([binary size reduction linker flags])
+ AC_LINK_USE_GC_SECTIONS([GC_SECTIONS])
+ LDFLAGS="$LDFLAGS $GC_SECTIONS"
+fi
+
AC_PATH_PROG([FLEX],[flex])
AX_PROG_FLEX_VERSION([2.5.35],[],[AC_MSG_ERROR([Require flex 2.5.35 or later])])
AC_PATH_PROG([BISON],[bison])
diff --git a/m4/link_options.m4 b/m4/link_options.m4
new file mode 100644
index 00000000..023cfe21
--- /dev/null
+++ b/m4/link_options.m4
@@ -0,0 +1,128 @@
+#
+# Get the linker version string.
+#
+# This macro is specific to LLVM.
+#
+AC_DEFUN([AC_LINK_GET_VERSION],
+ [AC_CACHE_CHECK([for linker version],[llvm_cv_link_version],
+ [
+ version_string="$(ld -v 2>&1 | head -1)"
+
+ # Check for ld64.
+ if (echo "$version_string" | grep -q "ld64"); then
+ llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\{0,1\}#\1#")
+ else
+ llvm_cv_link_version=$(echo "$version_string" | sed -e "s#[^0-9]*\([0-9.]*\).*#\1#")
+ fi
+ ])
+ AC_DEFINE_UNQUOTED([HOST_LINK_VERSION],"$llvm_cv_link_version",
+ [Linker version detected at compile time.])
+])
+
+#
+# Determine if the system can handle the --gc-sections option being passed to the linker.
+#
+# This macro is specific to LLVM.
+#
+AC_DEFUN([AC_LINK_USE_GC_SECTIONS],
+[AC_CACHE_CHECK([for compiler -Wl,--gc-sections option],[llvm_cv_link_use_gc_sections],
+[ AC_LANG_PUSH([C])
+ oldcflags="$CFLAGS"
+ CFLAGS="$CFLAGS -Wl,--gc-sections"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
+ [llvm_cv_link_use_gc_sections=yes],[llvm_cv_link_use_gc_sections=no])
+ CFLAGS="$oldcflags"
+ AC_LANG_POP([C])
+])
+if test "$llvm_cv_link_use_gc_sections" = yes ; then
+ AC_SUBST($1,[-Wl,--gc-sections])
+ fi
+])
+
+#
+# Determine if the system can handle the -R option being passed to the linker.
+#
+# This macro is specific to LLVM.
+#
+AC_DEFUN([AC_LINK_USE_R],
+[AC_CACHE_CHECK([for compiler -Wl,-R<path> option],[llvm_cv_link_use_r],
+[ AC_LANG_PUSH([C])
+ oldcflags="$CFLAGS"
+ CFLAGS="$CFLAGS -Wl,-R."
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
+ [llvm_cv_link_use_r=yes],[llvm_cv_link_use_r=no])
+ CFLAGS="$oldcflags"
+ AC_LANG_POP([C])
+])
+if test "$llvm_cv_link_use_r" = yes ; then
+ 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.])
+ fi
+])
+
+#
+# Determine if the system can handle the -R option being passed to the linker.
+#
+# This macro is specific to LLVM.
+#
+AC_DEFUN([AC_LINK_EXPORT_DYNAMIC],
+[AC_CACHE_CHECK([for compiler -Wl,-export-dynamic option],
+ [llvm_cv_link_use_export_dynamic],
+[ AC_LANG_PUSH([C])
+ oldcflags="$CFLAGS"
+ CFLAGS="$CFLAGS -Wl,-export-dynamic"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
+ [llvm_cv_link_use_export_dynamic=yes],[llvm_cv_link_use_export_dynamic=no])
+ CFLAGS="$oldcflags"
+ AC_LANG_POP([C])
+])
+if test "$llvm_cv_link_use_export_dynamic" = yes ; then
+ AC_DEFINE([HAVE_LINK_EXPORT_DYNAMIC],[1],[Define if you can use -Wl,-export-dynamic.])
+ fi
+])
+
+#
+# Determine if the system can handle the --version-script option being
+# passed to the linker.
+#
+# This macro is specific to LLVM.
+#
+AC_DEFUN([AC_LINK_VERSION_SCRIPT],
+[AC_CACHE_CHECK([for compiler -Wl,--version-script option],
+ [llvm_cv_link_use_version_script],
+[ 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 "{" > "$tmp/export.map"
+ echo " global: main;" >> "$tmp/export.map"
+ echo " local: *;" >> "$tmp/export.map"
+ echo "};" >> "$tmp/export.map"
+
+ CFLAGS="$CFLAGS -Wl,--version-script=$tmp/export.map"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
+ [llvm_cv_link_use_version_script=yes],[llvm_cv_link_use_version_script=no])
+ rm "$tmp/export.map"
+ rmdir "$tmp"
+ CFLAGS="$oldcflags"
+ AC_LANG_POP([C])
+])
+if test "$llvm_cv_link_use_version_script" = yes ; then
+ AC_SUBST(HAVE_LINK_VERSION_SCRIPT,1)
+ fi
+])
+