--- build/config/compiler/BUILD.gn.orig 2021-12-31 00:57:18 UTC +++ build/config/compiler/BUILD.gn @@ -140,7 +140,7 @@ declare_args() { # # TODO(crbug.com/1131993): Enabling this when 'is_android' is true breaks # content_shell_test_apk on both ARM and x86. - init_stack_vars = !is_android + init_stack_vars = !is_android && !is_bsd # This argument is to control whether enabling text section splitting in the # final binary. When enabled, the separated text sections with prefix @@ -241,7 +241,7 @@ config("default_include_dirs") { # Compiler instrumentation can introduce dependencies in DSOs to symbols in # the executable they are loaded into, so they are unresolved at link-time. config("no_unresolved_symbols") { - if (!using_sanitizer && + if (!using_sanitizer && !is_bsd && (is_linux || is_chromeos || is_android || is_fuchsia)) { ldflags = [ "-Wl,-z,defs", @@ -361,7 +361,7 @@ config("compiler") { } # Linker warnings. - if (fatal_linker_warnings && !is_apple && current_os != "aix" && + if (fatal_linker_warnings && !is_apple && !is_bsd && current_os != "aix" && current_os != "zos") { ldflags += [ "-Wl,--fatal-warnings" ] } @@ -539,7 +539,7 @@ config("compiler") { ldflags += [ "-Wl,-z,keep-text-section-prefix" ] } - if (is_clang && !is_nacl && !use_xcode_clang && current_os != "zos") { + if (is_clang && !is_nacl && !is_bsd && !use_xcode_clang && current_os != "zos") { cflags += [ "-fcrash-diagnostics-dir=" + clang_diagnostic_dir ] # TODO(hans): Remove this once Clang generates better optimized debug info @@ -682,7 +682,12 @@ config("compiler") { # and let it use all cores. # TODO(thakis): Check if '=0' (that is, number of cores, instead # of "all" which means number of hardware threads) is faster. - ldflags += [ "-Wl,--thinlto-jobs=all" ] + if (is_bsd) { + # FreeBSD < 13 uses LLVM 10, which doesn't support --thinlto-jobs=all + ldflags += [ "-Wl,--thinlto-jobs=2" ] + } else { + ldflags += [ "-Wl,--thinlto-jobs=all" ] + } if (is_mac) { ldflags += [ "-Wl,-cache_path_lto," + @@ -910,7 +915,7 @@ config("compiler_cpu_abi") { cflags += [ "-mtune=$arm_tune" ] } } else if (current_cpu == "arm64") { - if (is_clang && !is_android && !is_nacl && !is_fuchsia) { + if (is_clang && !is_android && !is_nacl && !is_fuchsia && !is_bsd) { cflags += [ "--target=aarch64-linux-gnu" ] ldflags += [ "--target=aarch64-linux-gnu" ] } @@ -1266,6 +1271,9 @@ config("compiler_deterministic") { "-Xclang", ".", ] + } else if (is_bsd) { + # -ffile-compilation-dir is not supported in the LLVM version FreeBSD ships + cflags += [ "-fdebug-compilation-dir=." ] } else { # -ffile-compilation-dir is an alias for both -fdebug-compilation-dir= # and -fcoverage-compilation-dir=. @@ -1519,7 +1527,7 @@ config("default_warnings") { cflags += [ "-Wno-null-pointer-subtraction" ] } - if (current_toolchain == host_toolchain || !use_xcode_clang) { + if ((current_toolchain == host_toolchain || !use_xcode_clang) && !is_bsd) { # Flags Xcode 9.2 (Clang clang-900.0.39.2) does not recognize. cflags += [ "-Wenum-compare-conditional", @@ -1549,6 +1557,18 @@ config("default_warnings") { cflags += [ "-Wmax-tokens" ] } } + + if (is_clang && is_bsd) { + cflags += [ + "-Wno-ignored-pragma-optimize", + "-Wno-implicit-int-float-conversion", + "-Wno-final-dtor-non-final-class", + "-Wno-builtin-assume-aligned-alignment", + "-Wno-deprecated-copy", + "-Wno-thread-safety-analysis", + "-Wno-thread-safety-attributes", + ] + } } } } @@ -1684,7 +1704,7 @@ config("no_chromium_code") { # third-party libraries. "-Wno-c++11-narrowing", ] - if (!is_nacl && (current_toolchain == host_toolchain || !use_xcode_clang)) { + if (!is_nacl && (current_toolchain == host_toolchain || !use_xcode_clang) && !is_bsd) { cflags += [ # Disabled for similar reasons as -Wunused-variable. "-Wno-unused-but-set-variable", @@ -1767,7 +1787,7 @@ config("thin_archive") { # archives. # TODO(crbug.com/1221615): Enable on is_apple if use_lld once that no longer # confuses lldb. - if ((is_posix && !is_nacl && !is_apple) || is_fuchsia) { + if ((is_posix && !is_nacl && !is_apple && !is_bsd) || is_fuchsia) { arflags = [ "-T" ] } else if (is_win && use_lld) { arflags = [ "/llvmlibthin" ] @@ -2267,7 +2287,11 @@ config("symbols") { # flag, so we can use use -g1 for pnacl and nacl-clang compiles. # gcc nacl is is_nacl && !is_clang, pnacl and nacl-clang are && is_clang. if ((!is_nacl || is_clang) && current_os != "zos") { - cflags += [ "-g2" ] + if (is_bsd) { + cflags += [ "-g0" ] + } else { + cflags += [ "-g2" ] + } } # Since only one of the build options -gdwarf-aranges and -fembed-bitcode @@ -2307,7 +2331,7 @@ config("symbols") { # DWARF info may be corrupt; offsets in a range list entry are in different # sections" there. Maybe just a bug in nacl_switch_32.S. _enable_gdb_index = - symbol_level == 2 && !is_apple && !is_nacl && current_cpu != "x86" && + symbol_level == 2 && !is_apple && !is_nacl && !is_bsd && current_cpu != "x86" && current_os != "zos" && (use_gold || use_lld) && # Disable on non-fission 32-bit Android because it pushes # libcomponents_unittests over the 4gb size limit.