https://gcc.gnu.org/g:9d3338579f6448dcffa6f0b818c45374f925f3d5
commit r17-5416-g9d3338579f6448dcffa6f0b818c45374f925f3d5 Author: Zhongteng Gui <[email protected]> Date: Sat Oct 10 01:17:17 2026 +0800 lto, mingw: Do not export symbols from some frontends [PR115300] This patch works around bootstrapping on x86_64-w64-mingw32 targets with bootstrap-lto-lean and --enable-plugin enabled. Note that i686-w64-mingw32 targets still fail with bootstrap-lto-lean even without --enable-plugin due to a segfault in lto1.exe. --enable-plugin adds -Wl,--export-all-symbols and -Wl,[email protected] to PLUGINLIBS on MinGW hosts, so that a plugin can resolve back into the compiler it is loaded by. These options are also passed to frontends that do not install compiler-proper import libraries. With bootstrap-lto-lean, their PE export tables can exceed the 16-bit ordinal limit and some LTO symbols cannot be exported with their resulting types. Use the MinGW host makefile fragment to omit the plugin export options when linking gnat1, f951, lto1, lto-dump, cc1obj, and cc1objplus. This keeps the target-specific handling out of the language-independent makefiles. Unlike the executables, libgccjit still needs its public import library. Generate a PE definition file from the existing libgccjit export list, disable automatic exports, and keep --out-implib for the public API. cc1 and cc1plus also still need to export their public APIs, so add -fno-lto to their MinGW link flags when bootstrap-lto-lean provides -ffat-lto-objects. Add -ffat-lto-objects to the bootstrap-lto-lean configuration for MinGW targets so that cc1 and cc1plus can be linked with LTO objects. PR lto/115300 config/ChangeLog: * bootstrap-lto-lean.mk (STAGE3_CFLAGS): Add -ffat-lto-objects for mingw targets. (STAGEfeedback_CFLAGS): Likewise. gcc/ChangeLog: * config/i386/x-mingw32: Avoid exporting compiler-internal symbols from frontends without a plugin API. Add -fno-lto when linking cc1 and cc1plus with fat LTO objects. gcc/jit/ChangeLog: * Make-lang.in (LIBGCCJIT_DEF_FILE): New variable, dynamically generated from libgccjit.exports. (LIBGCCJIT_EXTRA_OPTS): Add LIBGCCJIT_DEF_FILE and disable automatic exports. (libgccjit): Add LIBGCCJIT_DEF_FILE to the link dependencies. (jit.mostlyclean): Remove LIBGCCJIT_DEF_FILE and its temporary file. Signed-off-by: Zhongteng Gui <[email protected]> Signed-off-by: Jonathan Yong <[email protected]> Diff: --- config/bootstrap-lto-lean.mk | 4 ++++ gcc/config/i386/x-mingw32 | 9 +++++++++ gcc/jit/Make-lang.in | 14 +++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/config/bootstrap-lto-lean.mk b/config/bootstrap-lto-lean.mk index 42cb3394c70b..5f3d2b56fbfc 100644 --- a/config/bootstrap-lto-lean.mk +++ b/config/bootstrap-lto-lean.mk @@ -5,6 +5,10 @@ STAGE3_CFLAGS += -flto=jobserver override STAGEtrain_CFLAGS := $(filter-out -flto=jobserver,$(STAGEtrain_CFLAGS)) STAGEtrain_GENERATOR_CFLAGS += -flto=jobserver STAGEfeedback_CFLAGS += -flto=jobserver +ifneq (,$(findstring mingw,$(host_os))) +STAGE3_CFLAGS += -ffat-lto-objects +STAGEfeedback_CFLAGS += -ffat-lto-objects +endif # assumes the host supports the linker plugin LTO_AR = $$r/$(HOST_SUBDIR)/prev-gcc/gcc-ar$(exeext) -B$$r/$(HOST_SUBDIR)/prev-gcc/ diff --git a/gcc/config/i386/x-mingw32 b/gcc/config/i386/x-mingw32 index 3ac2ba57631c..e5062047bcf9 100644 --- a/gcc/config/i386/x-mingw32 +++ b/gcc/config/i386/x-mingw32 @@ -24,6 +24,15 @@ local_includedir=$(libsubdir)/$(unlibsubdir)/..`echo $(exec_prefix) | sed -e 's| # Add Windows socket library. LIBS += -lws2_32 +ifeq ($(plugin_implib),yes) +# Avoid exporting compiler-internal symbols from frontends without a plugin API. +gnat1$(exeext) f951$(exeext) lto1$(exeext) lto-dump$(exeext) \ +cc1obj$(exeext) cc1objplus$(exeext) $(LIBGCCJIT_FILENAME): PLUGINLIBS = + +ALL_LINKERFLAGS += $(if $(filter cc1$(exeext) cc1plus$(exeext),$@),\ + $(if $(filter -ffat-lto-objects,$(ALL_CXXFLAGS)),-fno-lto)) +endif + # On MinGW, we use "%IA64d" to print 64-bit integers, and the format-checking # code does not handle that, so we have to disable checking here. WERROR_FLAGS += -Wno-format diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in index cdcf19c933c3..5eeea22e180f 100644 --- a/gcc/jit/Make-lang.in +++ b/gcc/jit/Make-lang.in @@ -165,8 +165,16 @@ JIT_LDFLAGS = $(LDFLAGS) endif ifneq (,$(findstring mingw,$(target))) +LIBGCCJIT_DEF_FILE = libgccjit.def + # Create import library -LIBGCCJIT_EXTRA_OPTS = -Wl,--out-implib,$(LIBGCCJIT_IMPORT_LIB) +LIBGCCJIT_EXTRA_OPTS = $(LIBGCCJIT_DEF_FILE) -Wl,--exclude-all-symbols \ + -Wl,--out-implib,$(LIBGCCJIT_IMPORT_LIB) + +$(LIBGCCJIT_DEF_FILE): $(srcdir)/jit/libgccjit.exports + echo EXPORTS > [email protected] + $(AWK) '/^_/ { sub(/^_/, ""); print }' $< >> [email protected] + $(SHELL) $(srcdir)/../move-if-change [email protected] $@ else ifneq (,$(findstring darwin,$(host))) LIBGCCJIT_VERS = $(LIBGCCJIT_CURRENT).$(LIBGCCJIT_REVISION).$(LIBGCCJIT_AGE) @@ -189,7 +197,7 @@ EXTRA_GCC_OBJS_EXCLUSIVE = $(foreach _obj1, $(EXTRA_GCC_OBJS), \ $(LIBGCCJIT_FILENAME): $(jit_OBJS) \ libbackend.a libcommon-target.a libcommon.a \ $(CPPLIB) $(LIBDECNUMBER) \ - $(LIBDEPS) $(srcdir)/jit/libgccjit.map \ + $(LIBDEPS) $(srcdir)/jit/libgccjit.map $(LIBGCCJIT_DEF_FILE) \ $(EXTRA_GCC_OBJS_EXCLUSIVE) $(jit.prev) @$(call LINK_PROGRESS,$(INDEX.jit),start) +$(LLINKER) $(ALL_LINKERFLAGS) $(JIT_LDFLAGS) -o $@ -shared \ @@ -433,7 +441,7 @@ jit.uninstall: jit.mostlyclean: -rm -f $(LIBGCCJIT_FILENAME) $(LIBGCCJIT_SYMLINK) -rm -f $(LIBGCCJIT_LINKER_NAME_SYMLINK) $(FULL_DRIVER_NAME) - -rm -f $(LIBGCCJIT_SONAME) + -rm -f $(LIBGCCJIT_SONAME) $(LIBGCCJIT_DEF_FILE) $(LIBGCCJIT_DEF_FILE).tmp -rm -f $(jit_OBJS) jit.clean:
