[PATCH] D94329: [lld-macho] Fix TLV data initialization

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 8 12:04:25 PST 2021


int3 created this revision.
int3 added a reviewer: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We were mishandling the case where both __tbss and __thread_data sections were
present.

TLVP relocations should be encoded as offsets from the start of `__thread_data`,
even if the symbol is actually located in `__thread_bss`. Previously, we were
writing the offset from the start of the containing section, which doesn't
really make sense since there's no way `tlv_get_addr()` can know which section a
given `tlv$init` symbol is in at runtime.

In addition, this patch ensures that we place `__thread_data` immediately before
`__thread_bss`. This is what ld64 does, likely for performance reasons. Zerofill
sections must also be at the end of their segments; we were already doing this,
but now we ensure that `__thread_bss` occurs before `__bss`, so that it's always
possible to have it contiguous with `__thread_data`.

Fixes llvm.org/PR48657.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94329

Files:
  lld/MachO/InputSection.cpp
  lld/MachO/InputSection.h
  lld/MachO/Writer.cpp
  lld/MachO/Writer.h
  lld/test/MachO/bss.s
  lld/test/MachO/tlv.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94329.315477.patch
Type: text/x-patch
Size: 12762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210108/7f7a8682/attachment.bin>


More information about the llvm-commits mailing list