This is an archive of the discontinued LLVM Phabricator instance.

[Android] Use ELF TLS for Android API level 29+
ClosedPublic

Authored by brad on Apr 8 2023, 4:40 AM.

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.

(This is an updated https://reviews.llvm.org/D63904)

Diff Detail

Event Timeline

brad created this revision.Apr 8 2023, 4:40 AM
brad requested review of this revision.Apr 8 2023, 4:40 AM

+1, but I'd like @rprichard to be the one to actually sign off since he'll be the one to know if there are any caveats.

nit: In the description/commit message, the "when the API level is > 29" should be "when the API level is >= 29".

I think it's OK, but I'd like confirmation that it works with LTO?

One issue I noticed earlier was that the compiler flag (-f[no-]emulated-tls) doesn't work with LTO:

  • The flag is ignored when the compiler is only outputting LLVM IR, and
  • The flag is also ignored at link-time when the IR is converted to emutls-or-efltls machine code.

This link-time LTO setting can be changed using -Wl,-plugin-opt,-emulated-tls={0,1}.

It's not clear to me from the patch whether the new default applies when -flto is used to compile. (I suspect that it does, but a confirmation might be useful?)

Also: This is technically an ABI break, but it only applies when a thread-local variable is accessed across an ABI boundary, which seems unlikely/rare. It seems like the change is worth it, in any case.

enh added a subscriber: enh.Apr 10 2023, 3:35 PM

nit: In the description/commit message, the "when the API level is > 29" should be "when the API level is >= 29".

I think it's OK, but I'd like confirmation that it works with LTO?

One issue I noticed earlier was that the compiler flag (-f[no-]emulated-tls) doesn't work with LTO:

  • The flag is ignored when the compiler is only outputting LLVM IR, and
  • The flag is also ignored at link-time when the IR is converted to emutls-or-efltls machine code.

This link-time LTO setting can be changed using -Wl,-plugin-opt,-emulated-tls={0,1}.

does https://reviews.llvm.org/D147834 fix this?

It's not clear to me from the patch whether the new default applies when -flto is used to compile. (I suspect that it does, but a confirmation might be useful?)

Also: This is technically an ABI break, but it only applies when a thread-local variable is accessed across an ABI boundary, which seems unlikely/rare. It seems like the change is worth it, in any case.

One issue I noticed earlier was that the compiler flag (-f[no-]emulated-tls) doesn't work with LTO:

  • The flag is ignored when the compiler is only outputting LLVM IR, and
  • The flag is also ignored at link-time when the IR is converted to emutls-or-efltls machine code.

This link-time LTO setting can be changed using -Wl,-plugin-opt,-emulated-tls={0,1}.

does https://reviews.llvm.org/D147834 fix this?

Thanks, I hadn't seen that before. Yes, that should make -f[no-]emulated-tls work with LTO.

rprichard accepted this revision.Apr 10 2023, 3:50 PM
This revision is now accepted and ready to land.Apr 10 2023, 3:50 PM
brad added a comment.Apr 15 2023, 2:11 PM

I'm not in a rush to commit this, it would be nice if at least one other person could Ok this.

danalbert accepted this revision.Apr 17 2023, 2:24 PM

The rest of us are just echoing rprichard since he's the expert, but done :)

brad edited the summary of this revision. (Show Details)Apr 17 2023, 4:26 PM
enh accepted this revision.Apr 17 2023, 4:28 PM

(yeah, thanks so much for doing this!)

This revision was automatically updated to reflect the committed changes.