[PATCH] D123279: [lld-macho] Give non-text ConcatOutputSections order-independent finalization

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 21:48:06 PDT 2022


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

This diff is motivated by my work to add proper DWARF unwind support. As
detailed in PR50300, functions that need DWARF unwind need to have
compact unwind entries synthesized for them. These CU entries encode an
offset within `__eh_frame` that points to the corresponding DWARF FDE.

In order to encode this offset during
`UnwindInfoSectionImpl::finalize()`, we need to first assign values to
`InputSection::outSecOff` for each `__eh_frame` subsection. But
`__eh_frame` is ordered after `__unwind_info` (according to ld64 at
least), which puts us in a bit of a bind: `outSecOff` gets assigned
during finalization, but `__eh_frame` is being finalized after
`__unwind_info`.

But it occurred to me that there's no real need for most
ConcatOutputSections to be finalized sequentially. It's only necessary
for text-containing ConcatOutputSections that may contain branch relocs
which may need thunks. ConcatOutputSections containing other types of
data can be finalized in any order.

This diff moves the finalization logic for non-text sections into a
separate `finalizeContents()` method. This method is called before
section address assignment & unwind info finalization takes place. In
theory we could call these `finalizeContents()` methods in parallel, but
in practice it seems to be faster to do it all on the main thread.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123279

Files:
  lld/MachO/ConcatOutputSection.cpp
  lld/MachO/ConcatOutputSection.h
  lld/MachO/Writer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123279.421087.patch
Type: text/x-patch
Size: 6322 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220407/22d8d8fc/attachment.bin>


More information about the llvm-commits mailing list