[PATCH] D53906: [ARM][AArch64] Increase TLS alignment to reserve space for Android's TCB

Ryan Prichard via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 10 23:24:48 PST 2018


rprichard updated this revision to Diff 177663.
rprichard added a comment.

I implemented the proposed fix for ARM/AArch64 (i.e. set a minimum alignment of 8 words on an executable's TLS segment). I think this will work for Android -- i.e. we'll leave the x86 layout alone. Even if we *did* decide to change the x86 TLS layout later, it'd probably make sense to use this approach on ARM.

On a somewhat related topic:

lld rounds up a TLS segment's size to a multiple of its alignment, which tends to waste TLS memory, because it creates alignment padding where libc could have otherwise allocated a TLS object with a lower alignment requirement.

e.g.: With this patch, if an ARM/AArch64 executable and solib both declare a single TLS pointer, we'd have this TLS layout:

2-word TCB
... 6 words of padding for Bionic's TCB ...
executable's pointer
... 7 words of padding ...
solib's pointer

The 7 words of padding is unnecessary, and libc could avoid it if the PT_TLS segment size weren't rounded up.

I looked at other tools:

- ld.bfd does not round up a TLS segment's size.
- ld.gold *does* round up.
- If gold/lld rounded up the size, then binutils' strip brings it back down, apparently using the size of the .tdata/.tbss sections.

The lld padding was added in this commit:
https://reviews.llvm.org/rL252352

The gold padding was added in this commit:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=96a2b4e4bf67a7430e7ddd06a1d0730a49e6b07e

If we did decide to remove this behavior, I could submit another patch for it.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53906/new/

https://reviews.llvm.org/D53906

Files:
  ELF/InputSection.cpp
  ELF/Writer.cpp
  test/ELF/aarch64-cortex-a53-843419-tlsrelax.s
  test/ELF/aarch64-tls-gdle.s
  test/ELF/aarch64-tls-iele.s
  test/ELF/aarch64-tls-le.s
  test/ELF/aarch64-tlsld-ldst.s
  test/ELF/arm-tls-le32.s
  test/ELF/arm-tls-norelax-ie-le.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53906.177663.patch
Type: text/x-patch
Size: 10708 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181211/f7067415/attachment.bin>


More information about the llvm-commits mailing list