$OpenBSD: patch-build_config_compiler_BUILD_gn,v 1.22 2021/11/01 17:53:42 robert Exp $

Index: build/config/compiler/BUILD.gn
--- build/config/compiler/BUILD.gn.orig
+++ build/config/compiler/BUILD.gn
@@ -153,7 +153,7 @@ declare_args() {
 
   # Token limits may not be accurate for build configs not covered by the CQ,
   # so only enable them by default for mainstream build configs.
-  enable_wmax_tokens =
+  enable_wmax_tokens = !is_openbsd &&
       !is_official_build && !(is_component_build && !is_debug) &&
       ((is_mac && target_cpu == "x64" && !use_system_xcode) ||
        (is_linux && !is_chromeos && target_cpu == "x64") ||
@@ -239,12 +239,8 @@ 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 &&
-      (is_linux || is_chromeos || is_android || is_fuchsia)) {
-    ldflags = [
-      "-Wl,-z,defs",
-      "-Wl,--as-needed",
-    ]
+  if (current_cpu == "x86" && is_openbsd) {
+    ldflags = [ "-Wl,-z,notext" ]
   }
 }
 
@@ -292,6 +288,8 @@ config("compiler") {
 
   configs += [
     # See the definitions below.
+    ":clang_revision",
+    ":compiler_cpu_abi",
     ":compiler_codegen",
     ":compiler_deterministic",
   ]
@@ -438,6 +436,7 @@ config("compiler") {
     }
 
     ldflags += [
+      "-Wl,-z,wxneeded",
       "-Wl,-z,noexecstack",
       "-Wl,-z,relro",
     ]
@@ -866,7 +865,7 @@ config("compiler_cpu_abi") {
         ]
       }
     } else if (current_cpu == "arm") {
-      if (is_clang && !is_android && !is_nacl) {
+      if (is_clang && !is_android && !is_nacl && !is_openbsd) {
         cflags += [ "--target=arm-linux-gnueabihf" ]
         ldflags += [ "--target=arm-linux-gnueabihf" ]
       }
@@ -880,7 +879,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_openbsd) {
         cflags += [ "--target=aarch64-linux-gnu" ]
         ldflags += [ "--target=aarch64-linux-gnu" ]
       }
@@ -1587,11 +1586,6 @@ config("default_warnings") {
         cflags += [
           "-Wenum-compare-conditional",
 
-          # An ABI compat warning we don't care about, https://crbug.com/1102157
-          # TODO(thakis): Push this to the (few) targets that need it,
-          # instead of having a global flag.
-          "-Wno-psabi",
-
           # Ignore warnings about MSVC optimization pragmas.
           # TODO(thakis): Only for no_chromium_code? http://crbug.com/912662
           "-Wno-ignored-pragma-optimize",
@@ -1601,7 +1595,7 @@ config("default_warnings") {
         ]
 
         # NaCl does not support flags from ToT.
-        if (!is_nacl) {
+        if (!is_nacl && !is_openbsd) {
           cflags += [
             # TODO(https://crbug.com/1203071): Clean up and enable.
             "-Wno-unused-but-set-parameter",
@@ -1743,7 +1737,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_openbsd) {
       cflags += [
         # TODO(https://crbug.com/1202159): Clean up and enable.
         "-Wno-misleading-indentation",
@@ -1823,7 +1817,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_openbsd) || is_fuchsia) {
     arflags = [ "-T" ]
   } else if (is_win && use_lld) {
     arflags = [ "/llvmlibthin" ]
@@ -2020,8 +2014,7 @@ config("default_stack_frames") {
 }
 
 # Default "optimization on" config.
-config("optimize") { }
-config("xoptimize") {
+config("optimize") {
   if (is_win) {
     if (chrome_pgo_phase != 2) {
       # Favor size over speed, /O1 must be before the common flags.
@@ -2061,8 +2054,7 @@ config("xoptimize") {
 }
 
 # Turn off optimizations.
-config("no_optimize") { }
-config("xno_optimize") {
+config("no_optimize") {
   if (is_win) {
     cflags = [
       "/Od",  # Disable optimization.
@@ -2102,8 +2094,7 @@ config("xno_optimize") {
 # Turns up the optimization level. On Windows, this implies whole program
 # optimization and link-time code generation which is very expensive and should
 # be used sparingly.
-config("optimize_max") { }
-config("xoptimize_max") {
+config("optimize_max") {
   if (is_nacl && is_nacl_irt) {
     # The NaCl IRT is a special case and always wants its own config.
     # Various components do:
@@ -2136,8 +2127,7 @@ config("xoptimize_max") {
 #
 # TODO(crbug.com/621335) - rework how all of these configs are related
 # so that we don't need this disclaimer.
-config("optimize_speed") { }
-config("xoptimize_speed") {
+config("optimize_speed") {
   if (is_nacl && is_nacl_irt) {
     # The NaCl IRT is a special case and always wants its own config.
     # Various components do:
@@ -2163,8 +2153,7 @@ config("xoptimize_speed") {
   }
 }
 
-config("optimize_fuzzing") { }
-config("xoptimize_fuzzing") {
+config("optimize_fuzzing") {
   cflags = [ "-O1" ] + common_optimize_on_cflags
   rustflags = [ "-Copt-level=1" ]
   ldflags = common_optimize_on_ldflags
@@ -2230,7 +2219,7 @@ config("afdo_optimize_size") {
 # between //base/allocator:tcmalloc and AFDO on GCC), so we provide a separate
 # config to allow AFDO to be disabled per-target.
 config("afdo") {
-  if (is_clang) {
+  if (is_clang && !is_openbsd) {
     cflags = []
     if (clang_emit_debug_info_for_profiling) {
       # Add the following flags to generate debug info for profiling.
@@ -2246,7 +2235,7 @@ config("afdo") {
       cflags += [ "-fprofile-sample-use=${rebased_clang_sample_profile}" ]
       inputs = [ _clang_sample_profile ]
     }
-  } else if (auto_profile_path != "" && is_a_target_toolchain) {
+  } else if (auto_profile_path != "" && is_a_target_toolchain && !is_openbsd) {
     cflags = [ "-fauto-profile=${auto_profile_path}" ]
     inputs = [ auto_profile_path ]
   }
@@ -2284,8 +2273,7 @@ config("win_pdbaltpath") {
 }
 
 # Full symbols.
-config("symbols") { }
-config("xsymbols") {
+config("symbols") {
   if (is_win) {
     if (is_clang) {
       cflags = [ "/Z7" ]  # Debug information in the .obj files.
@@ -2376,7 +2364,7 @@ config("xsymbols") {
     }
   }
 
-  if (is_clang && !is_nacl && !use_xcode_clang) {
+  if (is_clang && !is_nacl && !use_xcode_clang && !is_openbsd) {
     if (is_apple) {
       # TODO(https://crbug.com/1050118): Investigate missing debug info on mac.
       # Make sure we don't use constructor homing on mac.
@@ -2399,8 +2387,7 @@ config("xsymbols") {
 # Minimal symbols.
 # This config guarantees to hold symbol for stack trace which are shown to user
 # when crash happens in unittests running on buildbot.
-config("minimal_symbols") { }
-config("xminimal_symbols") {
+config("minimal_symbols") {
   if (is_win) {
     # Functions, files, and line tables only.
     cflags = []
@@ -2472,8 +2459,7 @@ config("xminimal_symbols") {
 # This configuration contains function names only. That is, the compiler is
 # told to not generate debug information and the linker then just puts function
 # names in the final debug information.
-config("no_symbols") { }
-config("xno_symbols") {
+config("no_symbols") {
   if (is_win) {
     ldflags = [ "/DEBUG" ]
 
