Skip to content

Commit 1978482

Browse files
committed
gn build: Fix Android build.
Remove --unwindlib=none flag that was added by D143598. It is required to not pass this flag when linking binaries. With this flag, linking e.g. llvm-symbolizer will fail. There was a missing dependency from most targets to the implicitly linked libraries (libunwind and builtins), which was causing the build for those targets to fail when they were built on their own. I never noticed this because I always build the implicitly linked libraries together with their dependencies. Make the dependency explicit by introducing a new target //llvm/utils/gn/build/libs/implicit representing the platform's implicitly linked libraries, and depend on that from the LLVM libraries, so that "normal" binaries like llvm-symbolizer will have all of their dependencies available. D143598 set the arch subdirectory to i686 for Android. However, the arch subdirectory on Android is i386, and has been for a long time. $ find android-ndk-r* -name i386 android-ndk-r18b/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/7.0.2/lib/linux/i386 android-ndk-r19/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.2/lib/linux/i386 android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/lib/linux/i386 android-ndk-r21-beta1/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/lib/linux/i386 android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/lib/linux/i386 android-ndk-r22/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/11.0.5/lib/linux/i386 android-ndk-r23-beta5/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/12.0.5/lib/linux/i386 android-ndk-r24/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/i386 android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/i386 Using the wrong name prevents Clang from being able to find libunwind.a on x86. Fix the code to use i386 as the arch subdirectory, consistent with the NDK. Bring back -Wl,-z,defs which was removed for Android by D143598, presumably because of the missing unwind library. Differential Revision: https://reviews.llvm.org/D146266
1 parent f9da447 commit 1978482

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

llvm/utils/gn/build/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ config("zdefs") {
448448
# -Wl,-z,defs doesn't work with sanitizers.
449449
# https://clang.llvm.org/docs/AddressSanitizer.html
450450
if (current_os != "ios" && current_os != "mac" && current_os != "win" &&
451-
current_os != "android" && !(use_asan || use_tsan || use_ubsan)) {
451+
!(use_asan || use_tsan || use_ubsan)) {
452452
ldflags = [ "-Wl,-z,defs" ]
453453
}
454454
}

llvm/utils/gn/build/BUILDCONFIG.gn

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,22 @@ if (host_os == "win") {
4949
}
5050

5151
set_default_toolchain(host_toolchain)
52+
53+
if (current_os == "android") {
54+
foreach(target_type,
55+
[
56+
"executable",
57+
"loadable_module",
58+
"shared_library",
59+
]) {
60+
template(target_type) {
61+
target(target_type, target_name) {
62+
forward_variables_from(invoker, "*")
63+
if (!defined(deps)) {
64+
deps = []
65+
}
66+
deps += [ "//llvm/utils/gn/build/libs/implicit" ]
67+
}
68+
}
69+
}
70+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This target represents the library dependencies that are implicitly linked by
2+
# the compiler.
3+
if (current_os == "android") {
4+
group("implicit") {
5+
deps = [
6+
"//compiler-rt/lib/builtins",
7+
"//libunwind/src:unwind_static",
8+
]
9+
}
10+
}

llvm/utils/gn/build/toolchain/target_flags.gni

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ if (current_os == "android") {
1717
"--gcc-toolchain=$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64",
1818
"-fno-emulated-tls",
1919
]
20-
target_ldflags += [
21-
"-static-libstdc++",
22-
"--unwindlib=none",
23-
]
20+
target_ldflags += [ "-static-libstdc++" ]
2421
if (current_cpu == "arm") {
2522
target_flags += [ "-march=armv7-a" ]
2623
}

llvm/utils/gn/secondary/libunwind/src/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if (current_os == "android") {
5757
} else if (current_cpu == "x64") {
5858
unwind_output_dir = "$crt_current_out_dir/x86_64"
5959
} else if (current_cpu == "x86") {
60-
unwind_output_dir = "$crt_current_out_dir/i686"
60+
unwind_output_dir = "$crt_current_out_dir/i386"
6161
}
6262
} else {
6363
unwind_output_dir = runtimes_dir

0 commit comments

Comments
 (0)