This option adds a per-multilib variant that specifies -Os
instead of the default. The configure option accepts three possible values:
no: Don't add -Os variants (default)
except: Add -Os variants without otherwise changing CXXFLAGS
yes: Add -Os variants and add -fno-exceptions and
-fno-asynchronous-unwind-tables to CXXFLAGS for them.
Signed-off-by: Keith Packard <[email protected]>
---
config-ml.in | 17 +++++++++++++----
config/multi.m4 | 19 +++++++++++++++++++
configure.ac | 6 ++++++
gcc/Makefile.in | 32 +++++++++++++++++++++++++++-----
gcc/configure.ac | 10 ++++++++++
gcc/doc/install.texi | 12 ++++++++++++
6 files changed, 87 insertions(+), 9 deletions(-)
diff --git a/config-ml.in b/config-ml.in
index 9cdcae1191d..60439b4ed39 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 -o
"${enable_multilib_space}" = except ]; then
# Compute whether this is the library's top level directory
# (ie: not a multilib subdirectory, and not a subdirectory like newlib/src).
@@ -495,7 +495,12 @@ multidirs=`echo "$multidirs" | sed -e 's/^[ ][ ]*//' -e
's/[ ][ ]*$//' -e 's/[ ]
# Add code to library's top level makefile to handle building the multilib
# subdirs.
-cat > Multi.tem <<\EOF
+cat > Multi.tem << EOF
+
+enable_multilib_space=${enable_multilib_space}
+EOF
+
+cat >> Multi.tem <<\EOF
PWD_COMMAND=$${PWDCMD-pwd}
@@ -514,6 +519,10 @@ multi-do:
else \
if [ -d ../$${dir}/$${lib} ]; then \
flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \
+ cxxflags="$${flags}"; \
+ if test "$(enable_multilib_space)" = "yes"; then \
+ case "$$i" in *@Os*) cxxflags="$${flags} -fno-exceptions
-fno-asynchronous-unwind-tables"; ;; esac ; \
+ fi; \
libsuffix_=`$${compiler} $${flags} --print-multi-os-directory`;
\
if (cd ../$${dir}/$${lib}; $(MAKE) $(subst \
-B$(build_tooldir)/lib/, \
@@ -529,9 +538,9 @@ multi-do:
GOCFLAGS="$(GOCFLAGS) $${flags}" \
GDCFLAGS="$(GDCFLAGS) $${flags}" \
A68FLAGS="$(A68FLAGS) $${flags}" \
- CXXFLAGS="$(CXXFLAGS) $${flags}" \
+ CXXFLAGS="$(CXXFLAGS) $${cxxflags}" \
LIBCFLAGS="$(LIBCFLAGS) $${flags}" \
- LIBCXXFLAGS="$(LIBCXXFLAGS) $${flags}" \
+ LIBCXXFLAGS="$(LIBCXXFLAGS) $${cxxflags}" \
LDFLAGS="$(LDFLAGS) $${flags}" \
MULTIFLAGS="$${flags}" \
DESTDIR="$(DESTDIR)" \
diff --git a/config/multi.m4 b/config/multi.m4
index 10680a5b32b..3ef6657a5be 100644
--- a/config/multi.m4
+++ b/config/multi.m4
@@ -22,6 +22,25 @@ AC_ARG_ENABLE(multilib,
esac],
[multilib=yes])
+# Determine whether or not -Os multilibs are enabled.
+#
+# no: Do not add -Os libs
+# except: Add -Os libs, C++ libs will leave exceptions and unwind options alone
+# yes: Add -Os libs, C++ libs will disable exceptions and unwinding
+#
+AC_ARG_ENABLE(multilib-space,
+[AS_HELP_STRING([--enable-multilib-space=yes,no,except],
+ [enable extra -Os variant for every multilib ABI])],
+[case "$enableval" in
+ yes|except|no) ;;
+ *) AC_MSG_ERROR([bad value $enableval for multilib-space option]) ;;
+ esac;
+ case "$enable_multilib_space"":$enable_target_optspace" in
+ no:*|*:no) ;;
+ *:yes) AC_MSG_ERROR([Cannot combine --enable-multilib-space with
--enable-target-optspace]) ;;
+ esac],
+ [enable_multilib_space=no])
+
# We may get other options which we leave undocumented:
# --with-target-subdir, --with-multisrctop, --with-multisubdir
# See config-ml.in if you want the gory details.
diff --git a/configure.ac b/configure.ac
index 5edd041bf64..5056b32ccf4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3825,6 +3825,12 @@ case
"$target:$have_compiler:$host:$target:$enable_multilib" in
;;
esac
+case "${enable_multilib_space}:${enable_target_optspace}" in
+yes:yes|except:yes)
+ AC_MSG_ERROR([Cannot combine --enable-multilib-space with
--enable-target-optspace])
+ ;;
+esac
+
# Default to --enable-multilib.
if test x${enable_multilib} = x ; then
target_configargs="--enable-multilib ${target_configargs}"
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 917d586e572..79faa00945d 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2510,25 +2510,47 @@ libgcc.mvars: config.status Makefile specs xgcc$(exeext)
mv tmp-libgcc.mvars libgcc.mvars
+ifneq (@enable_multilib_space@,no)
+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@ != no \
|| 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.ac b/gcc/configure.ac
index 458f5c99028..c4247dcbe4a 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -858,6 +858,16 @@ 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=yes,no,except],
+ [enable extra -Os variant for every multilib ABI])],
+[case "$enableval" in
+ yes|no|except) ;;
+ *) AC_MSG_ERROR([bad value $enableval for multilib-space option]) ;;
+ esac],
+ [enable_multilib_space=no])
+
# 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 0563ff11807..6145db6e63f 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1338,6 +1338,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.51.0