On Sun, Jan 4, 2026 at 10:43 PM Keith Packard <[email protected]> wrote: > > This option adds a per-multilib variant that specifies -Os > instead of the default.
I am not a fan of this; especially how this interacts with --enable-target-optspace or with MULTILIB_OSDIRNAMES or with MULTIARCH_* support. Is there a reason why --enable-target-optspace can't be used with zephyr? Do they want the option to allow for both -Os and -O2 target libraries in the same toolchain? Thanks, Andrew > > Signed-off-by: Keith Packard <[email protected]> > --- > config-ml.in | 2 +- > gcc/Makefile.in | 32 +++++++++++++++++++++++++++----- > gcc/configure.ac | 7 +++++++ > gcc/doc/install.texi | 12 ++++++++++++ > 4 files changed, 47 insertions(+), 6 deletions(-) > > diff --git a/config-ml.in b/config-ml.in > index 9cdcae1191d..8aefaad3cb9 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 917d586e572..1c6115ea64b 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 > > +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.ac b/gcc/configure.ac > index 458f5c99028..e841976e236 100644 > --- a/gcc/configure.ac > +++ b/gcc/configure.ac > @@ -858,6 +858,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 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 >
