This is an archive of the discontinued LLVM Phabricator instance.

[Android] Use ELF TLS for Android API level 29+
Needs ReviewPublic

Authored by hctim on Jun 27 2019, 4:11 PM.

Details

Summary

Use ELF TLS by default instead of emulated TLS for Android build targets when the API level is > 29.

Android Q features full TLS support. See release notes here and implementation details here.

Event Timeline

hctim created this revision.Jun 27 2019, 4:11 PM

Test please.

Android's ELF TLS requires lld, but the NDK doesn't default to lld yet. (I believe the NDK uses bfd on arm64 and gold everywhere else.) When the NDK Clang driver targets 29/Q+, the NDK could generate executables or shared objects using ELF TLS that don't load on 29/Q.

For reference, the linker quirks are:

  • x86-32 bfd uses an obsolete TLS relocation (R_386_TLS_TPOFF32) for relaxation
  • arm{32,64} bfd can discard the overalignment placeholder section from crtbegin.c
  • gold uses STB_LOCAL TLS/section symbols that need special handling in soinfo::relocate
brad added a subscriber: brad.Feb 10 2023, 4:51 PM

I happened to come across. What about revisiting this now that the NDK has had LLD as the default since r22? Which is approaching 2 years old.

Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 4:51 PM
Herald added a subscriber: danielkiss. · View Herald Transcript

+1, but like @eugenis says, it needs a test.