This option adds a per-multilib variant that specifies -Os instead of the default.
Signed-off-by: Keith Packard <kei...@keithp.com> --- config-ml.in | 2 +- gcc/Makefile.in | 32 +++++++++++++++++++++++++++----- gcc/configure | 13 +++++++++++++ gcc/configure.ac | 7 +++++++ gcc/doc/install.texi | 10 ++++++++++ 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/config-ml.in b/config-ml.in index 645cac822fd..21345e38bee 100644 --- a/config-ml.in +++ b/config-ml.in @@ -175,7 +175,7 @@ eval scan_arguments "${ac_configure_args}" unset scan_arguments # Only do this if --enable-multilib. -if [ "${enable_multilib}" = yes ]; then +if [ "${enable_multilib}" = yes -o "${enable_multilib_space}" = yes ]; then # Compute whether this is the library's top level directory # (ie: not a multilib subdirectory, and not a subdirectory like newlib/src). diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 059cf2e8f79..7faf6d2fdb0 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2304,25 +2304,47 @@ libgcc.mvars: config.status Makefile specs xgcc$(exeext) mv tmp-libgcc.mvars libgcc.mvars +ifeq (@enable_multilib_space@,yes) +MULTILIB_OPTIONS += Os +MULTILIB_DIRNAMES += space +MULTILIB_MATCHES += Os=Oz + +MULTILIB_OSDIRNAMES_SPACE = $(MULTILIB_OSDIRNAMES)\ + $(if $(findstring =,$(MULTILIB_OSDIRNAMES)),\ + $(foreach OSD,$(MULTILIB_OSDIRNAMES),$(subst =,/Os=,$(OSD))/space),\ + $(if $(MULTILIB_OSDIRNAMES),space,)) +MULTILIB_REQUIRED_SPACE = $(if $(MULTILIB_REQUIRED),Os $(foreach REQ, $(MULTILIB_REQUIRED), $(REQ) $(REQ)/Os),) +MULTILIB_EXCEPTIONS_SPACE = $(foreach EXC, $(MULTILIB_EXCEPTIONS), $(EXC) $(EXC)/Os) +MULTILIB_REUSE_SPACE = $(foreach REU, $(MULTILIB_REUSE), $(REU) $(subst =,/Os=,$(REU))/Os) +MULTILIB_ENABLE = yes +else +MULTILIB_OSDIRNAMES_SPACE = $(MULTILIB_OSDIRNAMES) +MULTILIB_REQUIRED_SPACE = $(MULTILIB_REQUIRED) +MULTILIB_EXCEPTIONS_SPACE = $(MULTILIB_EXCEPTIONS) +MULTILIB_REUSE_SPACE = $(MULTILIB_REUSE) +MULTILIB_ENABLE = @multilib@ +endif + # Use the genmultilib shell script to generate the information the gcc # driver program needs to select the library directory based on the # switches. multilib.h: s-mlib; @true s-mlib: $(srcdir)/genmultilib Makefile if test @enable_multilib@ = yes \ + || test @enable_multilib_space@ = yes \ || test -n "$(MULTILIB_OSDIRNAMES)"; then \ $(SHELL) $(srcdir)/genmultilib \ "$(MULTILIB_OPTIONS)" \ "$(MULTILIB_DIRNAMES)" \ "$(MULTILIB_MATCHES)" \ - "$(MULTILIB_EXCEPTIONS)" \ + "$(MULTILIB_EXCEPTIONS_SPACE)" \ "$(MULTILIB_EXTRA_OPTS)" \ "$(MULTILIB_EXCLUSIONS)" \ - "$(MULTILIB_OSDIRNAMES)" \ - "$(MULTILIB_REQUIRED)" \ + "$(MULTILIB_OSDIRNAMES_SPACE)" \ + "$(MULTILIB_REQUIRED_SPACE)" \ "$(if $(MULTILIB_OSDIRNAMES),,$(MULTIARCH_DIRNAME))" \ - "$(MULTILIB_REUSE)" \ - "@enable_multilib@" \ + "$(MULTILIB_REUSE_SPACE)" \ + "$(MULTILIB_ENABLE)" \ > tmp-mlib.h; \ else \ $(SHELL) $(srcdir)/genmultilib '' '' '' '' '' '' '' '' \ diff --git a/gcc/configure b/gcc/configure index 5acc42c1e4d..3158d0790dd 100755 --- a/gcc/configure +++ b/gcc/configure @@ -856,6 +856,7 @@ DEFAULT_MATCHPD_PARTITIONS with_float with_cpu enable_multiarch +enable_multilib_space enable_multilib coverage_flags valgrind_command @@ -977,6 +978,7 @@ enable_coverage enable_gather_detailed_mem_stats enable_valgrind_annotations enable_multilib +enable_multilib_space enable_multiarch with_stack_clash_protection_guard_size with_matchpd_partitions @@ -1718,6 +1720,7 @@ Optional Features: --enable-valgrind-annotations enable valgrind runtime interaction --enable-multilib enable library support for multiple ABIs + --enable-multilib-space enable extra -Os variant for every multilib ABI --enable-multiarch enable support for multiarch paths --enable-__cxa_atexit enable __cxa_atexit for C++ --enable-decimal-float={no,yes,bid,dpd} @@ -7834,6 +7837,16 @@ fi +# Determine whether or not -Os multilibs are enabled. +# Check whether --enable-multilib-space was given. +if test "${enable_multilib_space+set}" = set; then : + enableval=$enable_multilib_space; +else + enable_multilib_space=no +fi + + + # Determine whether or not multiarch is enabled. # Check whether --enable-multiarch was given. if test "${enable_multiarch+set}" = set; then : diff --git a/gcc/configure.ac b/gcc/configure.ac index 23f4884eff9..f9275409a55 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -848,6 +848,13 @@ AC_ARG_ENABLE(multilib, [], [enable_multilib=yes]) AC_SUBST(enable_multilib) +# Determine whether or not -Os multilibs are enabled. +AC_ARG_ENABLE(multilib-space, +[AS_HELP_STRING([--enable-multilib-space], + [enable extra -Os variant for every multilib ABI])], +[], [enable_multilib_space=no]) +AC_SUBST(enable_multilib_space) + # Determine whether or not multiarch is enabled. AC_ARG_ENABLE(multiarch, [AS_HELP_STRING([--enable-multiarch], diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index b7c14e8b6f0..ee369040932 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1265,6 +1265,16 @@ for aarch64*-*-*, amdgcn*-*-*, arm*-*-*, loongarch*-*-*, riscv*-*-*, sh*-*-* and x86-64-*-linux*. The accepted values and meaning for each target is given below. +@item --enable-multilib-space +Double the set of target libraries built by building two versions of +each specified by the options above, one using -O2 and another using +-Os. During linking, the -O2 variant will be selected by +default. Select the -Os variant by including -Os or -Oz in the linker +command line. Note: because multilib selection only looks for the +presence of compiler flags (unlike options controlling the compiler +optimization level), a subsequent optimization flag other than -Os or +or -Oz will not switch back to the -O2 library versions. + @table @code @item aarch64*-*-* @var{list} is a comma separated list of @code{ilp32}, and @code{lp64} -- 2.45.2