Skip to content

aosp: Support devices older than Android 9 - #13108

Merged
andrewsavage1 merged 3 commits into
youtube:mainfrom
hferreiro:min-sdk-ndk
Oct 6, 2026
Merged

andrewsavage1 merged 3 commits into
youtube:mainfrom
hferreiro:min-sdk-ndk

Conversation

@hferreiro

Copy link
Copy Markdown
Collaborator

The AOSP starboard toolchains targeted NDK API level 28 so that aligned_alloc() would link, which made the native libraries fail to load on anything older than Android 9.

Build for Cobalt's default API level 24 again and add posix_emu polyfills for the functions bionic gained later, each compiled only while the NDK level is below the function's: aligned_alloc() and getrandom(). The existing pthread_getname_np() polyfill, which only handled the calling thread, is re-enabled and fixed to work for every thread.

The -Wunguarded-availability pragmas stay: in the NDK's weak-symbol mode the bionic declaration and its API level are always visible, so a polyfill does not silence the check.

Bug: 569900934
Bug: 374300500

The AOSP starboard toolchains targeted NDK API level 28 so that
aligned_alloc() would link, which made the native libraries fail to load
on anything older than Android 9.

Build for Cobalt's default API level 24 again and add posix_emu
polyfills for the functions bionic gained later, each compiled only
while the NDK level is below the function's: aligned_alloc() and
getrandom(). The existing pthread_getname_np() polyfill, which only
handled the calling thread, is re-enabled and fixed to work for every
thread.

The -Wunguarded-availability pragmas stay: in the NDK's weak-symbol mode
the bionic declaration and its API level are always visible, so a
polyfill does not silence the check.

Bug: 569900934
Bug: 374300500
@hferreiro
hferreiro requested a review from a team as a code owner October 5, 2026 15:15
@hferreiro
hferreiro requested a review from y4vor October 5, 2026 15:15
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


android: Support devices older than Android 9

The AOSP Starboard toolchains previously targeted NDK API level 28 to
support aligned_alloc, which caused native library load failures on
devices running versions older than Android 9.

This change restores the default API level 24 and introduces posix_emu
polyfills for aligned_alloc and getrandom. The pthread_getname_np
polyfill has also been updated to support all threads. Availability
pragmas are maintained to handle Bionic declarations when targeting
lower API levels in the NDK.

Bug: 569900934
Bug: 374300500

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Context State Description
CI / All Pass ✅ PASS All checks passed
CI / android ✅ PASS Passed
CI / evergreen ✅ PASS Passed
CI / linux ✅ PASS Passed
CI / tvos ✅ PASS Passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request re-enables and expands POSIX emulation/polyfills for Android (specifically targeting APIs < 26 and < 28). It adds a robust pthread_getname_np implementation that reads from /proc/self/task/<tid>/comm for non-current threads, introduces a getrandom polyfill using system calls, and provides an aligned_alloc polyfill using memalign. It also updates toolchain configurations and ABI wrappers to support these changes on older Android API levels. Feedback focuses on improving the correctness and POSIX compliance of the polyfills. Specifically, the aligned_alloc polyfill should validate that the alignment is a non-zero power of two and that the size is a multiple of the alignment to match native Bionic behavior. Additionally, the pthread_getname_np polyfill should map ENOENT to ESRCH when the target thread's proc directory does not exist.

Comment thread copied_base/base/os_compat_android.cc Resolved
@andrewsavage1
andrewsavage1 enabled auto-merge (squash) October 6, 2026 22:12
@andrewsavage1
andrewsavage1 merged commit 4fdb36a into youtube:main Oct 6, 2026
683 of 687 checks passed
@hferreiro
hferreiro deleted the min-sdk-ndk branch October 7, 2026 22:50
briantting pushed a commit that referenced this pull request Oct 8, 2026
…oid 9

Refer to original PR: #13108

The AOSP starboard toolchains targeted NDK API level 28 so that
aligned_alloc() would link, which made the native libraries fail to load
on anything older than Android 9.

Build for Cobalt's default API level 24 again and add posix_emu
polyfills for the functions bionic gained later, each compiled only
while the NDK level is below the function's: aligned_alloc() and
getrandom(). The existing pthread_getname_np() polyfill, which only
handled the calling thread, is re-enabled and fixed to work for every
thread.

The -Wunguarded-availability pragmas stay: in the NDK's weak-symbol mode
the bionic declaration and its API level are always visible, so a
polyfill does not silence the check.

Bug: 569900934
Bug: 374300500

(cherry picked from commit 4fdb36a)
briantting pushed a commit that referenced this pull request Oct 8, 2026
…droid 9 (#13210)

Automated cherry-pick roll to staging.

Original pull requests:
- #13108

CONFLICTED files:
```
starboard/aosp/arm/toolchain/BUILD.gn
starboard/aosp/arm64/toolchain/BUILD.gn
```

To merge these changes, run the autoroll script:

```bash
GITHUB_REPOSITORY=youtube/cobalt python3 cobalt/devinfra/github/autoroll/merge_autoroll.py \
  --source-branch main \
  --target-branch staging
```

⚠️ This PR has conflicts that must be resolved manually (don't forget to
update the `.github/AUTOROLL` file). Use the following commands to
checkout the branch locally and resolve the conflicts in a separate
commit:

```bash
gh pr checkout <pull_request_number> -R youtube/cobalt

# Resolve conflicts and update .github/AUTOROLL then
git add <resolved_files>

# Copy CONFLICTED commit's message and metadata
# Replace CONFLICTED in title with RESOLVED
git commit -c <conflicted_sha>

git push origin autoroll-main-to-staging
```

---------

Co-authored-by: Henrique Ferreiro <hferreiro@igalia.com>
briantting pushed a commit that referenced this pull request Oct 16, 2026
Refer to original PR: #13108

The AOSP starboard toolchains targeted NDK API level 28 so that
aligned_alloc() would link, which made the native libraries fail to load
on anything older than Android 9.

Build for Cobalt's default API level 24 again and add posix_emu
polyfills for the functions bionic gained later, each compiled only
while the NDK level is below the function's: aligned_alloc() and
getrandom(). The existing pthread_getname_np() polyfill, which only
handled the calling thread, is re-enabled and fixed to work for every
thread.

The -Wunguarded-availability pragmas stay: in the NDK's weak-symbol mode
the bionic declaration and its API level are always visible, so a
polyfill does not silence the check.

Bug: 569900934
Bug: 374300500

(cherry picked from commit 4fdb36a)
briantting pushed a commit that referenced this pull request Oct 16, 2026
Refer to original PR: #13108

The AOSP starboard toolchains targeted NDK API level 28 so that
aligned_alloc() would link, which made the native libraries fail to load
on anything older than Android 9.

Build for Cobalt's default API level 24 again and add posix_emu
polyfills for the functions bionic gained later, each compiled only
while the NDK level is below the function's: aligned_alloc() and
getrandom(). The existing pthread_getname_np() polyfill, which only
handled the calling thread, is re-enabled and fixed to work for every
thread.

The -Wunguarded-availability pragmas stay: in the NDK's weak-symbol mode
the bionic declaration and its API level are always visible, so a
polyfill does not silence the check.

Bug: 569900934
Bug: 374300500

(cherry picked from commit 4fdb36a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants