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 | 12 ++++++++++++ 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/config-ml.in b/config-ml.in index 7934a1ddf4b..c01fe4741c2 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 9ca389a9c61..c2263fae1d5 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2470,25 +2470,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 = @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 063b9ce6701..08d23c0ccb6 100755 --- a/gcc/configure +++ b/gcc/configure @@ -859,6 +859,7 @@ DEFAULT_MATCHPD_PARTITIONS with_float with_cpu enable_multiarch +enable_multilib_space enable_multilib coverage_flags valgrind_command @@ -980,6 +981,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 @@ -1723,6 +1725,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} @@ -7860,6 +7863,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 3243472680c..0ab6a6a6858 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -864,6 +864,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 b5509ff0c86..49523a2bac1 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1324,6 +1324,18 @@ for aarch64*-*-*, amdgcn*-*-*, arm*-*-*, loongarch*-*-*, nvptx-*, 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 @option{-O2 }and +another using @option{-Os}. During linking, the @option{-O2} variant +will be selected by default. Select the @option{-Os} variant by +including @option{-Os} or @option{-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 @option{-Os} or or +@option{-Oz} will not switch back to the @option{-O2} library +versions. + @table @code @item aarch64*-*-* @var{list} is a comma separated list of @code{ilp32}, and @code{lp64} -- 2.49.0