Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lldb API tests fail to compile inferiors with newer Android NDK (r22b or later) #106270

Open
andrurogerz opened this issue Aug 27, 2024 · 2 comments

Comments

@andrurogerz
Copy link
Contributor

Android introduced a unified tools layout in NDK r19 (2019) and removed support for the old layout in r22 (2021). Running lldb tests with NDK r22 or newer fails when compiling the test inferiors because Android.rules references an outdated sysroot path (and other paths) that no longer exists. More details on NDK unified tools changes are here.

This issue can be fixed by teaching Android.rules about the new NDK structure. There are two ways to proceed:

  1. We can support both the old and new NDK layout side-by-side. This option is more flexible, but will make Android.rules complex and difficult to maintain.
  2. We can support only the new NDK layout. This option will actually simplify Android.rules from what it is currently and will be more maintainable.

Since the change will only impact the ability to run the lldb API tests against Android remote targets, I recommend going with option 2 because it leaves the codebase cleaner and I cannot come up with any reason to run the tests against a 5+ year old NDK.

Repro Steps

  1. Install latest Android NDK (currently r27)
  2. Install Android SDK and emulator
  3. Create and launch an x86_64 AVD
  4. Copy lldb-server from the NDK to the device
adb push $ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/18/lib/linux/x86_64/lldb-server /data/local/tmp
  1. Forward a port for the debugger connection
adb forward tcp:54321 tcp:54321
  1. Launch lldb-server in platform mode on the Android device
adb shell /data/local/tmp/lldb-server platform --server --listen localhost:54321
  1. Build lldb and tests locally
cd llvm/llvm-project
cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS='clang;lldb' -DCMAKE_BUILD_TYPE=Release -DLLDB_ENABLE_PYTHON=On
  1. Run the lldb API Android test against the remote Android target
./build/bin/lldb-dotest --out-of-tree-debugserver --arch x86_64 --platform-name remote-android --platform-url connect://localhost:54321 --platform-working-dir /data/local/tmp --compiler=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/clang lldb/test/API/android/

Expected Results

The test passes just like when run against NDK r19:

PASS: LLDB (/home/andrew/Android/Sdk/ndk/19.2.5345600/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-x86_64) :: test_cache_line_size (TestDefaultCacheLineSize.DefaultCacheLineSizeTestCase.test_cache_line_size)
----------------------------------------------------------------------
Ran 1 test in 0.221s

OK

Actual Results

The test fails when compiling the inferior:

FAIL: LLDB (/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-x86_64) :: test_cache_line_size (TestDefaultCacheLineSize.DefaultCacheLineSizeTestCase.test_cache_line_size)
======================================================================
ERROR: test_cache_line_size (TestDefaultCacheLineSize.DefaultCacheLineSizeTestCase.test_cache_line_size)
----------------------------------------------------------------------
Error when building test subject.

Build Command:
make VPATH=/home/user/src/llvm/llvm-project/lldb/test/API/android/platform -C /home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size -I /home/user/src/llvm/llvm-project/lldb/test/API/android/platform -I /home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make -f /home/user/src/llvm/llvm-project/lldb/test/API/android/platform/Makefile all ARCH=x86_64 'CC="/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"' CLANG_MODULE_CACHE_DIR=/home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/module-cache-clang LLDB_OBJ_ROOT=/home/user/src/llvm/llvm-project/build/tools/lldb OS=Android PIE=1 HOST_OS=Linux

Build Command Output:
make: Entering directory '/home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size'
"/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"  -std=c++11 -g -O0  -m64 -I/home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/home/user/src/llvm/llvm-project/build/tools/lldb/include -I/home/user/src/llvm/llvm-project/lldb/test/API/android/platform -I/home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info -target x86_64-none-linux-android --gcc-toolchain=/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../toolchains/x86_64-4.9/prebuilt/linux-x86_64 --sysroot=/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sysroot -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../platforms/android-21/arch-x86_64/usr/include  -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sources/cxx-stl/llvm-libc++/include -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sources/android/support/include -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sources/cxx-stl/llvm-libc++abi/include   --driver-mode=g++ -MT main.o -MD -MP -MF main.d -c -o main.o /home/user/src/llvm/llvm-project/lldb/test/API/android/platform/main.cpp
In file included from <built-in>:1:
/home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h:30:10: fatal error: 'sys/prctl.h' file not found
   30 | #include <sys/prctl.h>
      |          ^~~~~~~~~~~~~
1 error generated.
make: *** [Makefile.rules:664: main.o] Error 1
make: Leaving directory '/home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size'

Test Directory:
/home/user/src/llvm/llvm-project/lldb/test/API/android/platform
----------------------------------------------------------------------
Ran 1 test in 0.042s

FAILED (errors=1)
@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2024

@llvm/issue-subscribers-lldb

Author: Andrew Rogers (andrurogerz)

Android introduced a unified tools layout in NDK r19 (2019) and removed support for the old layout in r22 (2021). Running lldb tests with NDK r22 or newer fails when compiling the test inferiors because `Android.rules` references an outdated sysroot path (and other paths) that no longer exists. More details on NDK unified tools changes are [here](https://github.com/android/ndk/issues/780).

This issue can be fixed by teaching Android.rules about the new NDK structure. There are two ways to proceed:

  1. We can support both the old and new NDK layout side-by-side. This option is more flexible, but will make Android.rules complex and difficult to maintain.
  2. We can support only the new NDK layout. This option will actually simplify Android.rules from what it is currently and will be more maintainable.

Since the change will only impact the ability to run the lldb API tests against Android remote targets, I recommend going with option 2 because it leaves the codebase cleaner and I cannot come up with any reason to run the tests against a 5+ year old NDK.

Repro Steps

  1. Install latest Android NDK (currently r27)
  2. Install Android SDK and emulator
  3. Create and launch an x86_64 AVD
  4. Copy lldb-server from the NDK to the device
adb push $ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/18/lib/linux/x86_64/lldb-server /data/local/tmp
  1. Forward a port for the debugger connection
adb forward tcp:54321 tcp:54321
  1. Launch lldb-server in platform mode on the Android device
adb shell /data/local/tmp/lldb-server platform --server --listen localhost:54321
  1. Build lldb and tests locally
cd llvm/llvm-project
cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS='clang;lldb' -DCMAKE_BUILD_TYPE=Release -DLLDB_ENABLE_PYTHON=On
  1. Run the lldb API Android test against the remote Android target
./build/bin/lldb-dotest --out-of-tree-debugserver --arch x86_64 --platform-name remote-android --platform-url connect://localhost:54321 --platform-working-dir /data/local/tmp --compiler=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/clang lldb/test/API/android/

Expected Results

The test passes just like when run against NDK r19:

PASS: LLDB (/home/andrew/Android/Sdk/ndk/19.2.5345600/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-x86_64) :: test_cache_line_size (TestDefaultCacheLineSize.DefaultCacheLineSizeTestCase.test_cache_line_size)
----------------------------------------------------------------------
Ran 1 test in 0.221s

OK

Actual Results

The test fails when compiling the inferior:

FAIL: LLDB (/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-x86_64) :: test_cache_line_size (TestDefaultCacheLineSize.DefaultCacheLineSizeTestCase.test_cache_line_size)
======================================================================
ERROR: test_cache_line_size (TestDefaultCacheLineSize.DefaultCacheLineSizeTestCase.test_cache_line_size)
----------------------------------------------------------------------
Error when building test subject.

Build Command:
make VPATH=/home/user/src/llvm/llvm-project/lldb/test/API/android/platform -C /home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size -I /home/user/src/llvm/llvm-project/lldb/test/API/android/platform -I /home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make -f /home/user/src/llvm/llvm-project/lldb/test/API/android/platform/Makefile all ARCH=x86_64 'CC="/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"' CLANG_MODULE_CACHE_DIR=/home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/module-cache-clang LLDB_OBJ_ROOT=/home/user/src/llvm/llvm-project/build/tools/lldb OS=Android PIE=1 HOST_OS=Linux

Build Command Output:
make: Entering directory '/home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size'
"/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"  -std=c++11 -g -O0  -m64 -I/home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/home/user/src/llvm/llvm-project/build/tools/lldb/include -I/home/user/src/llvm/llvm-project/lldb/test/API/android/platform -I/home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info -target x86_64-none-linux-android --gcc-toolchain=/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../toolchains/x86_64-4.9/prebuilt/linux-x86_64 --sysroot=/home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sysroot -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../platforms/android-21/arch-x86_64/usr/include  -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sources/cxx-stl/llvm-libc++/include -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sources/android/support/include -isystem /home/user/Android/Sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/bin/../../../../../sources/cxx-stl/llvm-libc++abi/include   --driver-mode=g++ -MT main.o -MD -MP -MF main.d -c -o main.o /home/user/src/llvm/llvm-project/lldb/test/API/android/platform/main.cpp
In file included from &lt;built-in&gt;:1:
/home/user/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h:30:10: fatal error: 'sys/prctl.h' file not found
   30 | #include &lt;sys/prctl.h&gt;
      |          ^~~~~~~~~~~~~
1 error generated.
make: *** [Makefile.rules:664: main.o] Error 1
make: Leaving directory '/home/user/src/llvm/llvm-project/build/lldb-test-build.noindex/android/platform/TestDefaultCacheLineSize.test_cache_line_size'

Test Directory:
/home/user/src/llvm/llvm-project/lldb/test/API/android/platform
----------------------------------------------------------------------
Ran 1 test in 0.042s

FAILED (errors=1)

@andrurogerz
Copy link
Contributor Author

I am locally testing changes to Android.rules that will address this issue, and I will put up a PR soon.

compnerd pushed a commit that referenced this issue Sep 25, 2024
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants