https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107950
Bug ID: 107950 Summary: partial LTO linking of libbackend.a: gcc/gcc-rich-location.cc:207: undefined reference to `range_label_for_type_mismatch::get_text(unsigned int) const' Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: bootstrap Assignee: unassigned at gcc dot gnu.org Reporter: marxin at gcc dot gnu.org Target Milestone: --- If I use the patch candidate for PR107944 and do: diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 615a07089ee..e95390169cf 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2122,13 +2122,15 @@ selftest: $(SELFTEST_TARGETS) # This is used only if the user explicitly asks for it. compilations: $(BACKEND) +$(foreach file,$(OBJS),$(eval CFLAGS-$(file) += -flto)) + # This archive is strictly for the host. libbackend.a: $(OBJS) -rm -rf libbackend.a @# Build libbackend.a as a thin archive if possible, as doing so @# significantly reduces build times. ifeq ($(USE_THIN_ARCHIVES),yes) - $(AR) $(AR_FLAGS)T libbackend.a $(OBJS) + -$(LINKER) $^ -flinker-output=nolto-rel -r -o $@ -flto=auto else $(AR) $(AR_FLAGS) libbackend.a $(OBJS) -$(RANLIB) $(RANLIB_FLAGS) libbackend.a I get the following linker error: $ make lto g++ -no-pie -g -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc -o lto1 \ lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-common.o libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a -lmpc -lmpfr -lgmp -rdynamic -L./../zlib -lz -lzstd libcommon.a ../libcpp/libcpp.a ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a /usr/bin/ld: libbackend.a: in function `range_label_for_type_mismatch::range_label_for_type_mismatch(tree_node*, tree_node*)': /home/marxin/Programming/gcc2/gcc/gcc-rich-location.h:158: undefined reference to `vtable for range_label_for_type_mismatch' /usr/bin/ld: libbackend.a: in function `maybe_range_label_for_tree_type_mismatch::get_text(unsigned int) const': /home/marxin/Programming/gcc2/gcc/gcc-rich-location.cc:207: undefined reference to `range_label_for_type_mismatch::get_text(unsigned int) const' collect2: error: ld returned 1 exit status make: *** [/home/marxin/Programming/gcc2/gcc/lto/Make-lang.in:96: lto1] Error 1 The error comes from gcc/gcc-rich-location.cc where we have: label_text maybe_range_label_for_tree_type_mismatch::get_text (unsigned range_idx) const { if (m_expr == NULL_TREE || !EXPR_P (m_expr)) return label_text::borrow (NULL); tree expr_type = TREE_TYPE (m_expr); tree other_type = NULL_TREE; if (m_other_expr && EXPR_P (m_other_expr)) other_type = TREE_TYPE (m_other_expr); range_label_for_type_mismatch inner (expr_type, other_type); return inner.get_text (range_idx); } and yes, both symbols are undefined: nm libbackend.a | grep range_label_for_type_mismatch U _ZNK29range_label_for_type_mismatch8get_textEj U _ZTV29range_label_for_type_mismatch What's strange that also a normal build (non-LTO, no partial linking) has the same definitions: nm libbackend.a | grep range_label_for_type_mismatch U _ZNK29range_label_for_type_mismatch8get_textEj U _ZTV29range_label_for_type_mismatch So any guess what can be bad?