Re: [PATCH v2] libstdc++: Do not overwrite module definition files during build [PR126786]

Tomasz Kaminski <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.libstdc++.devel
Message-ID <CAKvuMXAGXhsefHu4i7guU0pcEYtPAahOVYZxGW8PZVSgbkteLw@mail.gmail.com>
On Tue, Aug 18, 2026 at 11:02 AM Jonathan Wakely <[email protected]> wrote:

> As described in the bug report, when compilation of std.cc or
> std.compat.cc fails we overwrite the source file with an empty file, and
> then compile that (so that bootstrap doesn't fail). Then when the module
> definition files are installed, we install the empty file.
>
> We should install the original source, not an empty file. We can create
> an empty file and compile it, but leave the original source untouched so
> that it can still be installed.
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/126786
>         * src/c++23/Makefile.am (empty.cc): New target.
>         (std.lo, std.o, std.compat.lo, std.compat.o): Use empty.cc as
>         fallback instead of overwriting original sources.
>         * src/c++23/Makefile.in: Regenerate.
> ---
>
> v2: Use a makefile target to create empty.cc
>
I really like having a separate target for empty.cc file, it looks much
clearner.
Thanks LGTM.

>
> We could even consider separate empty-std.cc and empty-std.compat.cc
> files, with 'export module std;' in the former and 'export module
> std.compat;' in the latter. That would mean we would actually define
> module init functions in the library, they'd just be no-op functions.
>
>  libstdc++-v3/src/c++23/Makefile.am | 24 ++++++++++++------------
>  libstdc++-v3/src/c++23/Makefile.in | 24 ++++++++++++------------
>  2 files changed, 24 insertions(+), 24 deletions(-)
>
> diff --git a/libstdc++-v3/src/c++23/Makefile.am
> b/libstdc++-v3/src/c++23/Makefile.am
> index 92691c502a94..e09c4bd54da2 100644
> --- a/libstdc++-v3/src/c++23/Makefile.am
> +++ b/libstdc++-v3/src/c++23/Makefile.am
> @@ -54,6 +54,10 @@ std.cc: std.cc.in std-clib.cc.in
>  std.compat.cc: std.compat.cc.in std-clib.cc.in
>         cat $^ > $@
>
> +# Empty file used in case std.cc or std.compat.cc fails to compile.
> +empty.cc:
> +       echo > $@
> +
>  # Also put the interface units in the build-includes bits directory.
>  stamp-modules-bits: $(includebits_DATA)
>         @-mkdir -p $(top_builddir)/include/bits
> @@ -100,33 +104,29 @@ MODULES_FLAGS = -isystem
> ${glibcxx_srcdir}/include/backward -fmodules \
>         -Wno-unknown-pragmas
>
>  # These go into libmodulesconvenience.la and are linked into libstdc++
> -std.lo: std.cc
> +std.lo: std.cc empty.cc
>         if ! $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
> -std.o: std.cc
> +std.o: std.cc empty.cc
>         if ! $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(CXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
> -std.compat.lo: std.compat.cc std.lo
> +std.compat.lo: std.compat.cc std.lo empty.cc
>         if ! $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std.compat module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
> -std.compat.o: std.compat.cc std.o
> +std.compat.o: std.compat.cc std.o empty.cc
>         if ! $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std.compat module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(CXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
>
>  # AM_CXXFLAGS needs to be in each subdirectory so that it can be
> diff --git a/libstdc++-v3/src/c++23/Makefile.in
> b/libstdc++-v3/src/c++23/Makefile.in
> index 0ce93f812d25..f3ea90ce2478 100644
> --- a/libstdc++-v3/src/c++23/Makefile.in
> +++ b/libstdc++-v3/src/c++23/Makefile.in
> @@ -862,6 +862,10 @@ std.cc: std.cc.in std-clib.cc.in
>  std.compat.cc: std.compat.cc.in std-clib.cc.in
>         cat $^ > $@
>
> +# Empty file used in case std.cc or std.compat.cc fails to compile.
> +empty.cc:
> +       echo > $@
> +
>  # Also put the interface units in the build-includes bits directory.
>  stamp-modules-bits: $(includebits_DATA)
>         @-mkdir -p $(top_builddir)/include/bits
> @@ -884,33 +888,29 @@ print.o: print.cc
>         $(CXXCOMPILE) -std=gnu++26 -c $<
>
>  # These go into libmodulesconvenience.la and are linked into libstdc++
> -std.lo: std.cc
> +std.lo: std.cc empty.cc
>         if ! $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
> -std.o: std.cc
> +std.o: std.cc empty.cc
>         if ! $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(CXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
> -std.compat.lo: std.compat.cc std.lo
> +std.compat.lo: std.compat.cc std.lo empty.cc
>         if ! $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std.compat module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(LTCXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
> -std.compat.o: std.compat.cc std.o
> +std.compat.o: std.compat.cc std.o empty.cc
>         if ! $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; then \
>           echo "Cannot compile std.compat module" >&2; \
>           echo "Module initialization function will be missing" >&2; \
> -         echo > $<.tmp && mv $<.tmp $< && \
> -         $(CXXCOMPILE) $(MODULES_FLAGS) -c $< ; \
> +         $(CXXCOMPILE) $(MODULES_FLAGS) -c empty.cc -o $@; \
>         fi
>
>  # Tell versions [3.59,3.63) of GNU make to not export all variables.
> --
> 2.55.0
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.