I tried to build with the following *FLAGS to optimize the build: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing
Note the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.
I got this error:
x86_64-pc-linux-gnu-g++ -std=c++11 -no-pie -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Wno-error=format-security -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 -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -o cc1 c-family/c-common.o c/c-lang.o c/c-errors.o c/c-convert.o c/gimple-parser.o c/c-objc-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-indentation.o c-family/c-opts.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-lex.o cc1_dummies.o \
libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a libcommon.a ../libcpp/libcpp.a ../libbacktrace/.libs/libbacktrace.a ../../sdbinutils/libiberty/libiberty.a -L./../zlib -lz -lzstd
alloc-pool.h:29:13: error: type of ‘after_memory_report’ does not match original declaration [-Werror=lto-type-mismatch]
29 | extern bool after_memory_report;
| ^
cc1_dummies.cc:316:5: note: type ‘int’ should match type ‘bool’
316 | int after_memory_report;
| ^
cc1_dummies.cc:316:5: note: ‘after_memory_report’ was previously declared here
cc1_dummies.cc:316:5: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
debug.h:267:1: error: ‘dump_go_spec_init’ violates the C++ One Definition Rule [-Werror=odr]
267 | dump_go_spec_init (const char *, const struct gcc_debug_hooks *);
| ^
cc1_dummies.cc:107:6: note: return value type mismatch
107 | void dump_go_spec_init(char const*, const struct gcc_debug_hooks*)
| ^
cc1_dummies.cc:107:6: note: ‘dump_go_spec_init’ was previously declared here
./stringpool.h:25:13: error: ‘get_identifier’ violates the C++ One Definition Rule [-Werror=odr]
25 | extern tree get_identifier (const char *);
| ^
cc1_dummies.cc:130:5: note: return value type mismatch
130 | int get_identifier(char const*)
| ^
cc1_dummies.cc:130:5: note: type ‘int’ should match type ‘union tree_node *’
cc1_dummies.cc:130:5: note: ‘get_identifier’ was previously declared here
cc1_dummies.cc:130:5: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
c/c-tree.h:571:13: error: ‘pushdecl’ violates the C++ One Definition Rule [-Werror=odr]
571 | extern tree pushdecl (tree);
| ^
cc1_dummies.cc:257:5: note: return value type mismatch
257 | int pushdecl(tree_node*)
| ^
cc1_dummies.cc:257:5: note: type ‘int’ should match type ‘union tree_node *’
cc1_dummies.cc:257:5: note: ‘pushdecl’ was previously declared here
cc1_dummies.cc:257:5: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
c/c-tree.h:673:13: error: ‘c_missing_noreturn_ok_p’ violates the C++ One Definition Rule [-Werror=odr]
673 | extern bool c_missing_noreturn_ok_p (tree);
| ^
cc1_dummies.cc:68:5: note: return value type mismatch
68 | int c_missing_noreturn_ok_p(tree_node*)
| ^
cc1_dummies.cc:68:5: note: type ‘int’ should match type ‘bool’
cc1_dummies.cc:68:5: note: ‘c_missing_noreturn_ok_p’ was previously declared here
cc1_dummies.cc:68:5: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
lto1: some warnings being treated as errors
lto-wrapper: fatal error: x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[3]: *** [c/Make-lang.in:101: cc1] Error 1
Downstream report: https://bugs.gentoo.org/924691
Full build log is attached. This is a local reproducer that built directly from svn.
Have you tried to use your options to build only gcc?
Can you try current trunk? I think this could have been fixed in [r14819].
Related
Commit: [r14819]
I can't try current trunk as it doesn't build since [r14858].
Regenerating the autotools now breaks once it hits that directory. No time to investigate tonight.
Related
Commit: [r14858]