[llvm] c839981 - [gn build] Support building x86/64 Android libraries

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 09:18:50 PST 2023


Author: Arthur Eubanks
Date: 2023-02-17T09:18:38-08:00
New Revision: c8399811e7b162bb1b11c06a2d757d23576b1c95

URL: https://github.com/llvm/llvm-project/commit/c8399811e7b162bb1b11c06a2d757d23576b1c95
DIFF: https://github.com/llvm/llvm-project/commit/c8399811e7b162bb1b11c06a2d757d23576b1c95.diff

LOG: [gn build] Support building x86/64 Android libraries

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D143598

Added: 
    

Modified: 
    llvm/utils/gn/build/BUILD.gn
    llvm/utils/gn/build/toolchain/BUILD.gn
    llvm/utils/gn/build/toolchain/target_flags.gni
    llvm/utils/gn/secondary/compiler-rt/target.gni
    llvm/utils/gn/secondary/libunwind/src/BUILD.gn
    llvm/utils/gn/secondary/llvm/lib/Target/targets.gni
    llvm/utils/gn/secondary/llvm/triples.gni

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn
index 16af242979581..14e65c18f3abf 100644
--- a/llvm/utils/gn/build/BUILD.gn
+++ b/llvm/utils/gn/build/BUILD.gn
@@ -448,7 +448,7 @@ config("zdefs") {
   # -Wl,-z,defs doesn't work with sanitizers.
   # https://clang.llvm.org/docs/AddressSanitizer.html
   if (current_os != "ios" && current_os != "mac" && current_os != "win" &&
-      !(use_asan || use_tsan || use_ubsan)) {
+      current_os != "android" && !(use_asan || use_tsan || use_ubsan)) {
     ldflags = [ "-Wl,-z,defs" ]
   }
 }

diff  --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index 81408115b225c..80e5bd92a1ad8 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -231,6 +231,20 @@ if (android_ndk_path != "") {
       current_cpu = "arm"
     }
   }
+
+  stage2_unix_toolchain("stage2_android_x64") {
+    toolchain_args = {
+      current_os = "android"
+      current_cpu = "x64"
+    }
+  }
+
+  stage2_unix_toolchain("stage2_android_x86") {
+    toolchain_args = {
+      current_os = "android"
+      current_cpu = "x86"
+    }
+  }
 }
 
 if (host_os == "mac") {

diff  --git a/llvm/utils/gn/build/toolchain/target_flags.gni b/llvm/utils/gn/build/toolchain/target_flags.gni
index 3c099149f6fc6..92da8774e935d 100644
--- a/llvm/utils/gn/build/toolchain/target_flags.gni
+++ b/llvm/utils/gn/build/toolchain/target_flags.gni
@@ -15,7 +15,10 @@ if (current_os == "android") {
     "--sysroot=$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
     "--gcc-toolchain=$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64",
   ]
-  target_ldflags += [ "-static-libstdc++" ]
+  target_ldflags += [
+    "-static-libstdc++",
+    "--unwindlib=none",
+  ]
   if (current_cpu == "arm") {
     target_flags += [ "-march=armv7-a" ]
   }
@@ -44,5 +47,5 @@ if (current_os == "android") {
 }
 
 if (current_cpu == "x86") {
-  target_flags = [ "-m32" ]
+  target_flags += [ "-m32" ]
 }

diff  --git a/llvm/utils/gn/secondary/compiler-rt/target.gni b/llvm/utils/gn/secondary/compiler-rt/target.gni
index 44e8343170b0c..bd8048499c0ae 100644
--- a/llvm/utils/gn/secondary/compiler-rt/target.gni
+++ b/llvm/utils/gn/secondary/compiler-rt/target.gni
@@ -2,7 +2,11 @@ import("//clang/resource_dir.gni")
 import("//clang/runtimes.gni")
 
 if (current_cpu == "x86") {
-  crt_current_target_arch = "i386"
+  if (current_os == "android") {
+    crt_current_target_arch = "i686"
+  } else {
+    crt_current_target_arch = "i386"
+  }
 } else if (current_cpu == "x64") {
   crt_current_target_arch = "x86_64"
 } else if (current_cpu == "arm") {

diff  --git a/llvm/utils/gn/secondary/libunwind/src/BUILD.gn b/llvm/utils/gn/secondary/libunwind/src/BUILD.gn
index c60fc0362a4b9..87bde59010913 100644
--- a/llvm/utils/gn/secondary/libunwind/src/BUILD.gn
+++ b/llvm/utils/gn/secondary/libunwind/src/BUILD.gn
@@ -55,6 +55,10 @@ if (current_os == "android") {
     unwind_output_dir = "$crt_current_out_dir/aarch64"
   } else if (current_cpu == "arm") {
     unwind_output_dir = "$crt_current_out_dir/arm"
+  } else if (current_cpu == "x64") {
+    unwind_output_dir = "$crt_current_out_dir/x86_64"
+  } else if (current_cpu == "x86") {
+    unwind_output_dir = "$crt_current_out_dir/i686"
   }
 } else {
   unwind_output_dir = runtimes_dir

diff  --git a/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni b/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni
index edefb58738351..0d36a2f68bf11 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni
+++ b/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni
@@ -114,4 +114,10 @@ if (android_ndk_path != "") {
     supported_android_toolchains +=
         [ "//llvm/utils/gn/build/toolchain:stage2_android_arm" ]
   }
+  if (llvm_build_X86) {
+    supported_android_toolchains += [
+      "//llvm/utils/gn/build/toolchain:stage2_android_x64",
+      "//llvm/utils/gn/build/toolchain:stage2_android_x86",
+    ]
+  }
 }

diff  --git a/llvm/utils/gn/secondary/llvm/triples.gni b/llvm/utils/gn/secondary/llvm/triples.gni
index e39e1dd8089e2..e891025a49378 100644
--- a/llvm/utils/gn/secondary/llvm/triples.gni
+++ b/llvm/utils/gn/secondary/llvm/triples.gni
@@ -3,6 +3,8 @@ if (current_cpu == "x86") {
     llvm_current_triple = "i386-unknown-linux-gnu"
   } else if (current_os == "win") {
     llvm_current_triple = "i386-pc-windows-msvc"
+  } else if (current_os == "android") {
+    llvm_current_triple = "i686-linux-android29"
   }
 } else if (current_cpu == "x64") {
   if (current_os == "freebsd") {
@@ -13,6 +15,8 @@ if (current_cpu == "x86") {
     llvm_current_triple = "x86_64-apple-darwin"
   } else if (current_os == "win") {
     llvm_current_triple = "x86_64-pc-windows-msvc"
+  } else if (current_os == "android") {
+    llvm_current_triple = "x86_64-linux-android29"
   }
 } else if (current_cpu == "arm") {
   if (current_os == "android") {


        


More information about the llvm-commits mailing list