Re: [PATCH] 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 | <CAKvuMXDL=v7Zca8zmxYxUCKuU5WOnJXetOC9UdpE49KwBG39HA@mail.gmail.com> |
On Tue, Aug 18, 2026 at 10:46 AM Jonathan Wakely <[email protected]> wrote: > On Tue, 18 Aug 2026 at 09:20, Tomasz Kaminski <[email protected]> wrote: > > > > > > > > On Mon, Aug 17, 2026 at 10:27 PM 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 (std.lo, std.compat.lo): Do not > >> overwrite original sources in error-recovery steps. > >> * src/c++23/Makefile.in: Regenerate. > >> --- > >> > >> Tested x86_64-linux. > >> > >> Also checked by injecting errors into std.cc.in and std.compat.cc.in to > >> ensure that the build completes as expected. > >> > >> libstdc++-v3/src/c++23/Makefile.am | 12 ++++-------- > >> libstdc++-v3/src/c++23/Makefile.in | 12 ++++-------- > >> 2 files changed, 8 insertions(+), 16 deletions(-) > >> > >> diff --git a/libstdc++-v3/src/c++23/Makefile.am > b/libstdc++-v3/src/c++23/Makefile.am > >> index 92691c502a94..87c0108b52d0 100644 > >> --- a/libstdc++-v3/src/c++23/Makefile.am > >> +++ b/libstdc++-v3/src/c++23/Makefile.am > >> @@ -104,29 +104,25 @@ std.lo: std.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 $< ; \ > >> + echo > x$< && $(LTCXXCOMPILE) $(MODULES_FLAGS) -c x$< -o $@; \ > > > > Any reason for switching the name of the helper file from std.cc.tmp to > xstd.cc? > > That's not what the patch does. > > The code that's on trunk now writes to a new file called std.cc.tmp > but then moves that to std.cc > That means the file has the correct .cc extension, so will be treated > as C++ source by g++. If it was called std.cc.tmp it would assume it's > a library or object file to be passed to the linker: > > $ g++ std.cc.tmp -c > g++: warning: std.cc.tmp: linker input file unused because linking not done > We could pass -x c++ to override the extension-based selector, but I think it is better to use the same compilation flags. > > So I'm switching the name of the helper file from std.cc to xstd.cc > and std.compat.cc to xstd.compat.cc, which avoids overwriting the > original std.cc and std.compat.cc files, which is the point of the > patch. > > > I think the later is more likely to conflict with something, so would > preffer to use $<.tmp > > here. Or is this common practice for these makefiles? > > Using a .tmp extension won't work. > > It could be tmp-std.cc or empty-std.cc or something like that, but > whatever change we make needs to be a prefix not a suffix. > "empty-" prefix sounds better to me. > > >> > >> fi > >> std.o: std.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 $< ; \ > >> + echo > x$< && $(CXXCOMPILE) $(MODULES_FLAGS) -c x$< -o $@; \ > >> fi > >> std.compat.lo: std.compat.cc std.lo > >> 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 $< ; \ > >> + echo > x$< && $(LTCXXCOMPILE) $(MODULES_FLAGS) -c x$< -o $@; \ > >> fi > >> std.compat.o: std.compat.cc std.o > >> 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 $< ; \ > >> + echo > x$< && $(CXXCOMPILE) $(MODULES_FLAGS) -c x$< -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..63e5cb4e2a1c 100644 > >> --- a/libstdc++-v3/src/c++23/Makefile.in > >> +++ b/libstdc++-v3/src/c++23/Makefile.in > >> @@ -888,29 +888,25 @@ std.lo: std.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 $< ; \ > >> + echo > x$< && $(LTCXXCOMPILE) $(MODULES_FLAGS) -c x$< -o $@; \ > >> fi > >> std.o: std.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 $< ; \ > >> + echo > x$< && $(CXXCOMPILE) $(MODULES_FLAGS) -c x$< -o $@; \ > >> fi > >> std.compat.lo: std.compat.cc std.lo > >> 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 $< ; \ > >> + echo > x$< && $(LTCXXCOMPILE) $(MODULES_FLAGS) -c x$< -o $@; \ > >> fi > >> std.compat.o: std.compat.cc std.o > >> 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 $< ; \ > >> + echo > x$< && $(CXXCOMPILE) $(MODULES_FLAGS) -c x$< -o $@; \ > >> fi > >> > >> # Tell versions [3.59,3.63) of GNU make to not export all variables. > >> -- > >> 2.55.0 > >> > >