OSDN Git Service

[lld-macho] Fix TLV data initialization
authorJez Ng <jezng@fb.com>
Fri, 8 Jan 2021 23:47:40 +0000 (18:47 -0500)
committerJez Ng <jezng@fb.com>
Fri, 8 Jan 2021 23:48:12 +0000 (18:48 -0500)
commitdaaaed6bb89044ac58a23f1bb1ccdd12342a5a58
treeb21d71c73d2e362f3b882ac2d8fa054b57cc0bd6
parent756dd707668ccc1ac22b88d5899984843a5a3262
[lld-macho] Fix TLV data initialization

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.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D94329
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