Skip to content

[FR] auto-enable ELF TLS in clang driver when minSdkVersion is sufficiently high #1679

@AndroidInternal

Description

@AndroidInternal

Description

Hi,

Disabled emulate tls With cflags to enable TLS:

-fno-emulated-tls
-Wl,-plugin-opt=-emulated-tls=0

Then ELF TLS works fine with the static library, and I can see .tbss section in the binary :

llvm-readelf libkmalloc_scudo.a -S | grep tbss

[275] .tbss._ZN5scudo18TSDRegistrySharedTINS_9AllocatorINS_13AndroidConfigEXadL_Z21scudo_malloc_postinitEEEELj32ELj8EE9ThreadTSDE NOBITS 0000000000000000 008f80 000008 00 WAGT  0   0  8
[281] .tbss._ZN5scudo18TSDRegistrySharedTINS_9AllocatorINS_19AndroidSvelteConfigEXadL_Z28scudo_svelte_malloc_postinitEEEELj2ELj1EE9ThreadTSDE NOBITS 0000000000000000 009280 000008 00 WAGT  0   0  8

But when adding LTO in flag:

-flto

Then the static library compiled is not an ELF format any more, instead it is LLVM IR code:

file flags_parser.cpp.o 
flags_parser.cpp.o: LLVM IR bitcode

Then .tbss section is not in the static library, and when a shared library compiled with this prebuilt static library, it will use emulate tls rather than elf tls.

Thanks.

Affected versions

r23

Canary version

No response

Host OS

Mac

Host OS version

macOS 12.2.1

Affected ABIs

arm64-v8a

Build system

CMake

Other build system

No response

minSdkVersion

30

Device API level

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Prebuilts submitted

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions