Skip to content

Commit 18b9d49

Browse files
authored
lldb: get lldb API tests working with newer Android NDKs
## Purpose Running the LLDB API tests against a remote Android target with NDK version r22 or later fails to compile the test inferiors. NDK r21 from 2021 is the most recent NDK that still works with the LLDB API tests. This PR updates the Android make rules to support newer Android NDK versions (r19 and later). ## Overview * Updates and simplifies `Android.rules` to match the newer Android NDK unified toolchain layout introduced in NDK r19 * Sets `OBJCOPY` and `ARCHIVER` env vars, required by a few test cases, to their `llvm-` versions in the unified toolchain * Drops support for pre-2019 Android NDK versions to keep the rules simple * Provides an error message if the tests are run using an incompatible NDK layout ## Problem Details Android introduced a unified tools layout in NDK r19 (2019) and removed the old layout in r22 (2021). Releases r19, r20, and r21 support both the old and new layout side-by-side. More details are in #106270. ## Validation Ran a sub-set of the LLDB API tests against remote Android targets for the four primary architectures i386, x86_64, arm, and aarch64. No validation was done against riscv targets. For each case, ran the copy of `lldb-server` from the Android NDK on the device with the latest LLDB test cases in llvm-project Ran tests with both r19 (the oldest supported) and r26 (more recent, unified layout only) NDK versions. Example test command for aarch64: ``` ./build/bin/lldb-dotest --out-of-tree-debugserver --arch aarch64 --platform-name remote-android --platform-url connect://localhost:5432 --platform-working-dir /data/local/tmp --compiler=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/clang lldb/test/API/android/ ``` **NOTE: there are a lot of test failures when running the full suite (especially against 32-bit ARM target). These failures occur independent of this change.** Verified the expected error message appears when attempting to run using NDK r18 ``` Build Command Output: make: Entering directory '/home/andrew/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size' /home/andrew/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make/Android.rules:16: *** "No unified toolchain sysroot found in /home/andrew/Android/Sdk/ndk/18.1.5063045/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../... NDK must be r19 or later.". Stop. make: Leaving directory '/home/andrew/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size' ``` ## Impact **This change explicitly removes support for the pre-2019 NDK structure.** Only NDK r19 (from 2019) and later can be used when running the LLDB API tests. If the maintainers object, we can easily support both the old and new NDK toolchain layouts side-by-side at the cost of readability/maintainability. Since this change only impacts tests, I don't see much value in supporting NDKs that are over 5 years old. ## Guidance to Reviewers * I am not an expert on `clang` arguments so if anything looks off let me know. * While I personally thing supporting 5+ year old NDKs for testing seems unnecessary, please chime-in if you are concerned with dropping that support. I can easily revise to support both old and new layouts side-by-side. * If there are any specific tests you'd like me to run I will do my best to accommodate. It doesn't look like there's much (any?) Android LLDB CI coverage.
1 parent fa627d9 commit 18b9d49

File tree

1 file changed

+32
-54
lines changed

1 file changed

+32
-54
lines changed
Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,59 @@
11
NDK_ROOT := $(shell dirname $(CC))/../../../../..
22

3-
ifeq "$(findstring 64, $(ARCH))" "64"
4-
# lowest 64-bit API level
5-
API_LEVEL := 21
6-
else ifeq "$(ARCH)" "i386"
7-
# clone(2) declaration is present only since this api level
8-
API_LEVEL := 17
3+
ifeq "$(HOST_OS)" "Linux"
4+
HOST_TAG := linux-x86_64
5+
else ifeq "$(HOST_OS)" "Darwin"
6+
HOST_TAG := darwin-x86_64
97
else
10-
# lowest supported 32-bit API level
11-
API_LEVEL := 16
8+
HOST_TAG := windows-x86_64
9+
endif
10+
11+
TOOLCHAIN_ROOT := $(NDK_ROOT)/toolchains/llvm/prebuilt/$(HOST_TAG)
12+
TOOLCHAIN_SYSROOT := $(TOOLCHAIN_ROOT)/sysroot
13+
14+
OBJCOPY ?= $(TOOLCHAIN_ROOT)/bin/llvm-objcopy
15+
ARCHIVER ?= $(TOOLCHAIN_ROOT)/bin/llvm-ar
16+
17+
ifeq "$(wildcard $(TOOLCHAIN_SYSROOT)/.)" ""
18+
# Compiling test inferiors for Android requires an NDK with the unified
19+
# toolchain introduced in version r19.
20+
$(error "No unified toolchain sysroot found in $(NDK_ROOT). NDK must be r19 or later.")
1221
endif
1322

1423
ifeq "$(ARCH)" "arm"
15-
SYSROOT_ARCH := arm
16-
STL_ARCH := armeabi-v7a
1724
TRIPLE := armv7-none-linux-androideabi
1825
ARCH_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm
1926
else ifeq "$(ARCH)" "aarch64"
20-
SYSROOT_ARCH := arm64
21-
STL_ARCH := arm64-v8a
2227
TRIPLE := aarch64-none-linux-android
2328
else ifeq "$(ARCH)" "i386"
24-
SYSROOT_ARCH := x86
25-
STL_ARCH := x86
2629
TRIPLE := i686-none-linux-android
2730
else
28-
SYSROOT_ARCH := $(ARCH)
29-
STL_ARCH := $(ARCH)
3031
TRIPLE := $(ARCH)-none-linux-android
3132
endif
3233

33-
ifeq "$(findstring 86,$(ARCH))" "86"
34-
TOOLCHAIN_DIR := $(STL_ARCH)-4.9
35-
else ifeq "$(ARCH)" "arm"
36-
TOOLCHAIN_DIR := arm-linux-androideabi-4.9
37-
else
38-
TOOLCHAIN_DIR := $(subst -none,,$(TRIPLE))-4.9
39-
endif
34+
# lowest 64-bit API level
35+
API_LEVEL := 21
4036

4137
ifeq "$(ARCH)" "arm"
42-
TOOL_PREFIX := arm-linux-androideabi
38+
ARCH_DIR := arm-linux-androideabi
4339
else
44-
TOOL_PREFIX := $(subst -none,,$(TRIPLE))
40+
ARCH_DIR := $(subst -none,,$(TRIPLE))
4541
endif
4642

47-
ifeq "$(HOST_OS)" "Linux"
48-
HOST_TAG := linux-x86_64
49-
else ifeq "$(HOST_OS)" "Darwin"
50-
HOST_TAG := darwin-x86_64
51-
else
52-
HOST_TAG := windows-x86_64
53-
endif
54-
55-
GCC_TOOLCHAIN = $(NDK_ROOT)/toolchains/$(TOOLCHAIN_DIR)/prebuilt/$(HOST_TAG)
56-
57-
OBJCOPY ?= $(GCC_TOOLCHAIN)/bin/$(TOOL_PREFIX)-objcopy
58-
ARCHIVER ?= $(GCC_TOOLCHAIN)/bin/$(TOOL_PREFIX)-ar
59-
60-
ifeq "$(findstring clang,$(CC))" "clang"
61-
ARCH_CFLAGS += -target $(TRIPLE) --gcc-toolchain=$(GCC_TOOLCHAIN)
62-
ARCH_LDFLAGS += -target $(TRIPLE) --gcc-toolchain=$(GCC_TOOLCHAIN)
63-
endif
64-
65-
ARCH_CFLAGS += --sysroot=$(NDK_ROOT)/sysroot \
66-
-isystem $(NDK_ROOT)/sysroot/usr/include/$(TOOL_PREFIX) \
67-
-D__ANDROID_API__=$(API_LEVEL) \
68-
-isystem $(NDK_ROOT)/platforms/android-$(API_LEVEL)/arch-$(SYSROOT_ARCH)/usr/include
69-
70-
ARCH_LDFLAGS += --sysroot=$(NDK_ROOT)/platforms/android-$(API_LEVEL)/arch-$(SYSROOT_ARCH) -lm
43+
ARCH_CFLAGS += \
44+
--target=$(TRIPLE) \
45+
--sysroot=$(TOOLCHAIN_SYSROOT) \
46+
-D__ANDROID_API__=$(API_LEVEL)
7147

7248
ARCH_CXXFLAGS += \
73-
-isystem $(NDK_ROOT)/sources/cxx-stl/llvm-libc++/include \
74-
-isystem $(NDK_ROOT)/sources/android/support/include \
75-
-isystem $(NDK_ROOT)/sources/cxx-stl/llvm-libc++abi/include
49+
-isystem $(TOOLCHAIN_SYSROOT)/usr/include/c++/v1
7650

7751
ARCH_LDFLAGS += \
78-
-L$(NDK_ROOT)/sources/cxx-stl/llvm-libc++/libs/$(STL_ARCH) \
79-
$(NDK_ROOT)/sources/cxx-stl/llvm-libc++/libs/$(STL_ARCH)/libc++_static.a \
52+
--target=$(TRIPLE) \
53+
--sysroot=$(TOOLCHAIN_SYSROOT) \
54+
--prefix=$(TOOLCHAIN_SYSROOT)/usr/lib/$(ARCH_DIR)/$(API_LEVEL) \
55+
-L$(TOOLCHAIN_SYSROOT)/usr/lib/$(ARCH_DIR)/$(API_LEVEL) \
56+
$(TOOLCHAIN_SYSROOT)/usr/lib/$(ARCH_DIR)/libc++_static.a \
57+
-lm \
8058
-lc++abi \
8159
-nostdlib++

0 commit comments

Comments
 (0)