See also <https://trac.macports.org/ticket/59253> bootstrapping gcc-9.2.1 or gcc-devel (6 Oct 2019) with clang-9.0 fails due to: /opt/local/bin/clang++-mp-9.0 -arch x86_64 -std=gnu++98 -g -DIN_GCC -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wno-format -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -DGENERATOR_FILE -fno-PIE -Wl,-no_pie -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -no-pie -o build/gencondmd \ build/gencondmd.o build/errors.o ../build-x86_64-apple-darwin18/libiberty/libiberty.a clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument] Undefined symbols for architecture x86_64: "ix86_binary_operator_ok(rtx_code, machine_mode, rtx_def**)", referenced from: ___cxx_global_var_init.100 in gencondmd.o "optimize_function_for_size_p(function*)", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_cfun", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_const_tiny_rtx", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_epilogue_completed", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_cf_protection", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_excess_precision", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_finite_math_only", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_fp_int_builtin_inexact", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_peephole2", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_pic", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_rounding_math", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_trapping_math", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_flag_unsafe_math_optimizations", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_insn", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_arch_features", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_cmodel", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_fpmath", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_isa_flags", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_isa_flags2", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_pmode", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_tls_dialect", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_ix86_tune_features", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_operands", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_optimize", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_reload_completed", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_reload_in_progress", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_rtx_class", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_target_flags", referenced from: ___cxx_global_var_init.100 in gencondmd.o "_x86_prefetch_sse", referenced from: ___cxx_global_var_init.100 in gencondmd.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: *** [build/gencondmd] Error 1 bootstrapping with clang-8.0 succeeds, but with many warnings at the same point in the build that look like this: In file included from build/gencondmd.c:24: 5 /opt/local/var/macports/build/_opt_macports-ports_lang_gcc9/gcc9/work/gcc-9.2.0/gcc/coretypes.h:76:1: warning: class 'rtx_def' was previously declared as a struct; this is valid, but may result in linker errors under the Microsoft C++ ABI [-Wmismatched-tags] 6 class rtx_def; 7 ^ 8 /opt/local/var/macports/build/_opt_macports-ports_lang_gcc9/gcc9/work/gcc-9.2.0/gcc/coretypes.h:56:8: note: previous use is here 9 struct rtx_def; 10 ^ ```
Are you sure this is not a bug ing clang-9.0 ? These variables are declared in the header but never referenced. Did something in clang that would produce references to extern variables that are not referenced otherwise except for the declarations?
Or rather it is the way __builtin_constant_p is defined in the new clang. This is a bug in clang. As it says it is GCC_VERSION >= 3001 but does not implement the same semantics as GCC for __builtin_constant_p .
Specificically: /* This table lists each condition found in the machine description. Each condition is mapped to its truth value (0 or 1), or -1 if that cannot be calculated at compile time. If we don't have __builtin_constant_p, or it's not acceptable in array initializers, fall back to assuming that all conditions potentially vary at run time. It works in 3.0.1 and later; 3.0 only when not optimizing. */ #if GCC_VERSION >= 3001
Thanks for the quick analysis. For now we blacklisted clang > 8.x from building gcc, while we wait to see what happens with this.
We can certainly workaround it, like: --- gcc/genconditions.c 2019-01-01 12:37:19.064943662 +0100 +++ gcc/genconditions.c 2019-10-11 10:57:11.464595789 +0200 @@ -57,8 +57,9 @@ write_header (void) \n\ /* It is necessary, but not entirely safe, to include the headers below\n\ in a generator program. As a defensive measure, don't do so when the\n\ - table isn't going to have anything in it. */\n\ -#if GCC_VERSION >= 3001\n\ + table isn't going to have anything in it.\n\ + Clang 9 is buggy and doesn't handle __builtin_constant_p correctly. */\n\ +#if GCC_VERSION >= 3001 && __clang_major__ < 9\n\ \n\ /* Do not allow checking to confuse the issue. */\n\ #undef CHECKING_P\n\ @@ -170,7 +171,7 @@ struct c_test\n\ vary at run time. It works in 3.0.1 and later; 3.0 only when not\n\ optimizing. */\n\ \n\ -#if GCC_VERSION >= 3001\n\ +#if GCC_VERSION >= 3001 && __clang_major__ < 9\n\ static const struct c_test insn_conditions[] = {\n"); traverse_c_tests (write_one_condition, 0); @@ -191,7 +192,7 @@ write_writer (void) " unsigned int i;\n" " const char *p;\n" " puts (\"(define_conditions [\");\n" - "#if GCC_VERSION >= 3001\n" + "#if GCC_VERSION >= 3001 && __clang_major__ < 9\n" " for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n" " {\n" " printf (\" (%d \\\"\", insn_conditions[i].value);\n" but guess it would be better if somebody reports that to LLVM bugzilla first and see if they are willing to fix.
That said, I can't reproduce on x86_64-linux with clang version 10.0.0 (trunk 374035) if I build build/gencondmd.o, both with -O0 or -O2, nm -u shows just U ferror U fflush U printf U putc U puts U stdout which is expected.
For the record, Apple-clang-13.0.0 from Xcode13 fails to build gcc-9.4 and gcc-10.3 (gcc-11.2 builds) getting this error. The patch to gcc/genconditions.c in comment #5 fixes the missing symbol failure.