aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWenHan Gu <Wenhan.gu@mediatek.com>2013-12-09 11:25:20 +0800
committerLogan Chien <tzuhsiang.chien@gmail.com>2013-12-22 22:11:20 +0800
commitf3efa7fcda8e02adc4168a6cc65e078e293d8bd3 (patch)
treec4da8924f73886f46d8165456f7983029a3b415a
parentdcdd8fc8019d09ac30bf2d97640f0c31f9cca3a2 (diff)
downloadllvm-f3efa7fcda8e02adc4168a6cc65e078e293d8bd3.tar.gz
[ndk][conf] Shrink binary sizes when cross-compiling.
[1bb7be3] WenHan Gu <Wenhan.gu@mediatek.com> Shrink binary sizes when cross-compiling. [6230037] Ray Donnelly <mingw.android@gmail.com> Fixes for "Shrink binary sizes when cross-compiling." [43153c9] Ray Donnelly <mingw.android@gmail.com> Fix config comment about -Wl,--gc-sections. Cherry-picked and squashed from release_33 branch. Regenerated with ./autoconf/AutoRegen.sh. Change-Id: I7085a24bbee9cbc78fd977cee853c8da37346524
-rw-r--r--Makefile4
-rw-r--r--autoconf/configure.ac18
-rw-r--r--autoconf/m4/link_options.m420
-rwxr-xr-xconfigure128
-rw-r--r--tools/Makefile4
-rw-r--r--tools/llvm-shlib/Makefile16
6 files changed, 184 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 09243dd6de6..b84553a70c1 100644
--- a/Makefile
+++ b/Makefile
@@ -284,3 +284,7 @@ else # Building "Apple-style."
# Look for the string "Apple-style" in utils/buildit/build_llvm.
include $(shell find . -name GNUmakefile) # Building "Apple-style."
endif # Building "Apple-style."
+
+ifeq ($(LLVM_CROSS_COMPILING),1)
+ DIRS := $(filter-out unittests, $(DIRS))
+endif
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index df25b07994a..2cd2b91cbd8 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -971,6 +971,9 @@ case "$withval" in
esac ;;
*) optimize_option="$withval" ;;
esac
+if test "$LLVM_CROSS_COMPILING" = "1"; then
+ optimize_option="$optimize_option -Os"
+fi
AC_SUBST(OPTIMIZE_OPTION,$optimize_option)
AC_MSG_RESULT([$optimize_option])
@@ -983,6 +986,15 @@ case "$withval" in
default) EXTRA_OPTIONS= ;;
*) EXTRA_OPTIONS=$withval ;;
esac
+
+dnl 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])
+
+EXTRA_OPTIONS="$EXTRA_OPTIONS $DATA_SECTIONS $FUNCTION_SECTIONS $VISIBILITY_INLINES_HIDDEN"
+
AC_SUBST(EXTRA_OPTIONS,$EXTRA_OPTIONS)
dnl Specify extra linker build options
@@ -994,6 +1006,12 @@ case "$withval" in
default) EXTRA_LD_OPTIONS= ;;
*) EXTRA_LD_OPTIONS=$withval ;;
esac
+
+dnl 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])
+EXTRA_LD_OPTIONS="$EXTRA_LD_OPTIONS $GC_SECTIONS"
+
AC_SUBST(EXTRA_LD_OPTIONS,$EXTRA_LD_OPTIONS)
dnl Allow specific bindings to be specified for building (or not)
diff --git a/autoconf/m4/link_options.m4 b/autoconf/m4/link_options.m4
index b58d61745f9..e07baeb1dbc 100644
--- a/autoconf/m4/link_options.m4
+++ b/autoconf/m4/link_options.m4
@@ -20,6 +20,26 @@ AC_DEFUN([AC_LINK_GET_VERSION],
])
#
+# 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.
diff --git a/configure b/configure
index bc11c3b3bcb..79528a4e860 100755
--- a/configure
+++ b/configure
@@ -715,7 +715,11 @@ LLVM_ENUM_ASM_PRINTERS
LLVM_ENUM_ASM_PARSERS
LLVM_ENUM_DISASSEMBLERS
OPTIMIZE_OPTION
+DATA_SECTIONS
+FUNCTION_SECTIONS
+VISIBILITY_INLINES_HIDDEN
EXTRA_OPTIONS
+GC_SECTIONS
EXTRA_LD_OPTIONS
CLANG_SRC_ROOT
BINUTILS_INCDIR
@@ -5846,6 +5850,9 @@ case "$withval" in
esac ;;
*) optimize_option="$withval" ;;
esac
+if test "$LLVM_CROSS_COMPILING" = "1"; then
+ optimize_option="$optimize_option -Os"
+fi
OPTIMIZE_OPTION=$optimize_option
{ echo "$as_me:$LINENO: result: $optimize_option" >&5
@@ -5863,6 +5870,18 @@ case "$withval" in
default) EXTRA_OPTIONS= ;;
*) EXTRA_OPTIONS=$withval ;;
esac
+
+{ echo "$as_me:$LINENO: checking binary size reduction compiler flags" >&5
+echo $ECHO_N "checking binary size reduction compiler flags... $ECHO_C" >&6; }
+DATA_SECTIONS=`$CXX -Werror -fdata-sections -fsyntax-only -xc /dev/null 2>/dev/null && echo -fdata-sections`
+
+FUNCTION_SECTIONS=`$CXX -Werror -ffunction-sections -fsyntax-only -xc /dev/null 2>/dev/null && echo -ffunction-sections`
+
+VISIBILITY_INLINES_HIDDEN=`$CXX -Werror -fvisibility-inlines-hidden -fsyntax-only -xc /dev/null 2>/dev/null && echo -fvisibility-inlines-hidden`
+
+
+EXTRA_OPTIONS="$EXTRA_OPTIONS $DATA_SECTIONS $FUNCTION_SECTIONS $VISIBILITY_INLINES_HIDDEN"
+
EXTRA_OPTIONS=$EXTRA_OPTIONS
@@ -5878,6 +5897,99 @@ case "$withval" in
default) EXTRA_LD_OPTIONS= ;;
*) EXTRA_LD_OPTIONS=$withval ;;
esac
+
+{ echo "$as_me:$LINENO: checking binary size reduction linker flags" >&5
+echo $ECHO_N "checking binary size reduction linker flags... $ECHO_C" >&6; }
+{ echo "$as_me:$LINENO: checking for compiler -Wl,--gc-sections option" >&5
+echo $ECHO_N "checking for compiler -Wl,--gc-sections option... $ECHO_C" >&6; }
+if test "${llvm_cv_link_use_gc_sections+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ oldcflags="$CFLAGS"
+ CFLAGS="$CFLAGS -Wl,--gc-sections"
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_link") 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
+ { (case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ llvm_cv_link_use_gc_sections=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ llvm_cv_link_use_gc_sections=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ CFLAGS="$oldcflags"
+ ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+fi
+{ echo "$as_me:$LINENO: result: $llvm_cv_link_use_gc_sections" >&5
+echo "${ECHO_T}$llvm_cv_link_use_gc_sections" >&6; }
+if test "$llvm_cv_link_use_gc_sections" = yes ; then
+ GC_SECTIONS=-Wl,--gc-sections
+
+ fi
+
+EXTRA_LD_OPTIONS="$EXTRA_LD_OPTIONS $GC_SECTIONS"
+
EXTRA_LD_OPTIONS=$EXTRA_LD_OPTIONS
@@ -10590,7 +10702,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
-#line 10593 "configure"
+#line 10705 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -23161,7 +23273,11 @@ LLVM_ENUM_ASM_PRINTERS!$LLVM_ENUM_ASM_PRINTERS$ac_delim
LLVM_ENUM_ASM_PARSERS!$LLVM_ENUM_ASM_PARSERS$ac_delim
LLVM_ENUM_DISASSEMBLERS!$LLVM_ENUM_DISASSEMBLERS$ac_delim
OPTIMIZE_OPTION!$OPTIMIZE_OPTION$ac_delim
+DATA_SECTIONS!$DATA_SECTIONS$ac_delim
+FUNCTION_SECTIONS!$FUNCTION_SECTIONS$ac_delim
+VISIBILITY_INLINES_HIDDEN!$VISIBILITY_INLINES_HIDDEN$ac_delim
EXTRA_OPTIONS!$EXTRA_OPTIONS$ac_delim
+GC_SECTIONS!$GC_SECTIONS$ac_delim
EXTRA_LD_OPTIONS!$EXTRA_LD_OPTIONS$ac_delim
CLANG_SRC_ROOT!$CLANG_SRC_ROOT$ac_delim
BINUTILS_INCDIR!$BINUTILS_INCDIR$ac_delim
@@ -23238,10 +23354,6 @@ LLVM_ETCDIR!$LLVM_ETCDIR$ac_delim
LLVM_INCLUDEDIR!$LLVM_INCLUDEDIR$ac_delim
LLVM_INFODIR!$LLVM_INFODIR$ac_delim
LLVM_MANDIR!$LLVM_MANDIR$ac_delim
-LLVM_CONFIGTIME!$LLVM_CONFIGTIME$ac_delim
-BINDINGS_TO_BUILD!$BINDINGS_TO_BUILD$ac_delim
-ALL_BINDINGS!$ALL_BINDINGS$ac_delim
-OCAML_LIBDIR!$OCAML_LIBDIR$ac_delim
_ACEOF
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -23283,6 +23395,10 @@ _ACEOF
ac_delim='%!_!# '
for ac_last_try in false false false false false :; do
cat >conf$$subs.sed <<_ACEOF
+LLVM_CONFIGTIME!$LLVM_CONFIGTIME$ac_delim
+BINDINGS_TO_BUILD!$BINDINGS_TO_BUILD$ac_delim
+ALL_BINDINGS!$ALL_BINDINGS$ac_delim
+OCAML_LIBDIR!$OCAML_LIBDIR$ac_delim
ENABLE_VISIBILITY_INLINES_HIDDEN!$ENABLE_VISIBILITY_INLINES_HIDDEN$ac_delim
RPATH!$RPATH$ac_delim
RDYNAMIC!$RDYNAMIC$ac_delim
@@ -23291,7 +23407,7 @@ LIBOBJS!$LIBOBJS$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 6; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 10; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/tools/Makefile b/tools/Makefile
index 0b0d8065ec0..9e6f388f8b1 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -39,6 +39,10 @@ ifeq ($(USE_INTEL_JITEVENTS), 1)
PARALLEL_DIRS += llvm-jitlistener
endif
+ifeq ($(LLVM_CROSS_COMPILING),1)
+ PARALLEL_DIRS := llc le32-none-ndk-translate
+endif
+
# Let users override the set of tools to build from the command line.
ifdef ONLY_TOOLS
OPTIONAL_PARALLEL_DIRS :=
diff --git a/tools/llvm-shlib/Makefile b/tools/llvm-shlib/Makefile
index 92f3132ff53..2a1fe25cae4 100644
--- a/tools/llvm-shlib/Makefile
+++ b/tools/llvm-shlib/Makefile
@@ -36,6 +36,22 @@ SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a
IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives))
LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
+ifeq ($(LLVM_CROSS_COMPILING),1)
+ # Don't link these for saving binary size about 1MB
+ LLVMLibsOptions := $(filter-out -lLLVMArchive, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMDebugInfo, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMExecutionEngine, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMInstrumentation, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMInterpreter, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMipo, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMJIT, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMLinker, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMMCDisassembler, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMMCJIT, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMRuntimeDyld, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMVectorize, $(LLVMLibsOptions))
+ LLVMLibsOptions := $(filter-out -lLLVMWrap, $(LLVMLibsOptions))
+endif
LLVMLibsPaths := $(IncludeInLibLlvm)
$(LibName.SO): $(LLVMLibsPaths)