[llvm] [gn build] Fix up win/x86 flags and add stage2_unix_x86 (PR #111595)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 15:14:18 PDT 2024


https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/111595

None

>From 3911ef50737d71f293e46535540cf9b9654e5b0a Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Tue, 8 Oct 2024 21:28:59 +0000
Subject: [PATCH] [gn build] Fix up win/x86 flags and add stage2_unix_x86

---
 llvm/utils/gn/build/BUILD.gn                      | 8 ++++++--
 llvm/utils/gn/build/toolchain/BUILD.gn            | 7 +++++++
 llvm/utils/gn/build/toolchain/target_flags.gni    | 9 +++++++--
 llvm/utils/gn/secondary/compiler-rt/BUILD.gn      | 1 +
 llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn  | 2 +-
 llvm/utils/gn/secondary/compiler-rt/test/test.gni | 2 +-
 6 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn
index 0b0f62721d374c..9b5254e4c9f0b1 100644
--- a/llvm/utils/gn/build/BUILD.gn
+++ b/llvm/utils/gn/build/BUILD.gn
@@ -61,7 +61,7 @@ config("compiler_defaults") {
   }
 
   asmflags = target_flags
-  cflags = target_flags
+  cflags = target_flags + target_cflags
   cflags_cc = []
   ldflags = target_flags + target_ldflags
 
@@ -343,7 +343,11 @@ config("compiler_defaults") {
         ldflags += [ "/winsysroot:" + rebase_path(sysroot, root_build_dir) ]
 
         # FIXME: Remove once PR54409 is fixed.
-        ldflags += [ "/machine:x64" ]
+        if (current_cpu == "x64") {
+          ldflags += [ "/machine:x64" ]
+        } else if (current_cpu == "x86") {
+          ldflags += [ "/machine:x86" ]
+        }
       }
     } else if (current_os != "ios" && current_os != "mac" &&
                current_os != "android") {
diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index e4852549bba6c5..ce2e6df1b69f55 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -209,6 +209,13 @@ stage2_unix_toolchain("stage2_unix") {
   }
 }
 
+stage2_unix_toolchain("stage2_unix_x86") {
+  toolchain_args = {
+    current_os = host_os
+    current_cpu = "x86"
+  }
+}
+
 if (android_ndk_path != "") {
   # Android compiler-rt libraries don't really work with per-target runtime
   # directories yet so force it off.
diff --git a/llvm/utils/gn/build/toolchain/target_flags.gni b/llvm/utils/gn/build/toolchain/target_flags.gni
index 50d31a3da85fc5..cdfab75ed8bcdd 100644
--- a/llvm/utils/gn/build/toolchain/target_flags.gni
+++ b/llvm/utils/gn/build/toolchain/target_flags.gni
@@ -8,6 +8,7 @@ import("//llvm/utils/gn/build/toolchain/compiler.gni")
 # COMPILER_RT_TEST_COMPILER_CFLAGS).
 
 target_flags = []
+target_cflags = []
 target_ldflags = []
 
 if (current_os == "android") {
@@ -55,6 +56,10 @@ if (current_os == "android") {
   target_flags += [ "--target=$llvm_current_triple" ]
 }
 
-if (current_cpu == "x86" && current_os != "win") {
-  target_flags += [ "-m32" ]
+if (current_cpu == "x86") {
+  if (current_os == "win") {
+    target_cflags += [ "-m32" ]
+  } else {
+    target_flags += [ "-m32" ]
+  }
 }
diff --git a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
index b31016108419e6..c8d3917ccde31e 100644
--- a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
@@ -12,6 +12,7 @@ if (current_os == "win" || win_sysroot != "") {
 }
 if (current_os != "win") {
   supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
+  supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix_x86" ]
 }
 supported_toolchains += supported_android_toolchains
 if (llvm_build_AArch64) {
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
index 02c20483b7a8bd..57b86f53254f57 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
@@ -4,7 +4,7 @@ group("lib") {
     "//compiler-rt/lib/builtins",
     "//compiler-rt/lib/cfi:ignorelist($host_toolchain)",
   ]
-  if (current_os == "linux") {
+  if (current_os == "linux" && current_cpu == "x64") {
     deps += [ "//compiler-rt/lib/msan" ]
   }
   if (current_os == "linux" || current_os == "android") {
diff --git a/llvm/utils/gn/secondary/compiler-rt/test/test.gni b/llvm/utils/gn/secondary/compiler-rt/test/test.gni
index 2d1aa0721248e4..01de4ee09256c4 100644
--- a/llvm/utils/gn/secondary/compiler-rt/test/test.gni
+++ b/llvm/utils/gn/secondary/compiler-rt/test/test.gni
@@ -10,7 +10,7 @@ declare_args() {
 
 target_flags_string = ""
 
-foreach(flag, target_flags + target_ldflags) {
+foreach(flag, target_flags + target_cflags + target_ldflags) {
   if (target_flags_string != "") {
     target_flags_string += " "
   }



More information about the llvm-commits mailing list