[PATCH] D123435: [lld-macho] Initial support for EH Frames

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 19:27:12 PDT 2022


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

Background
----------

`llvm-mc` generates unwind info in both compact unwind and DWARF
formats. LLD already handles the compact unwind format; this diff gets
us close to handling the DWARF format properly.

Caveats
-------

It's not quite done yet, but I figure it's worth getting this reviewed
and landed first as it's shaping up to be a fairly large code change.

**Known limitations of the current code:**

- Only works for x86_64, for which `llvm-mc` emits "abs-ified" relocations as described in https://github.com/llvm/llvm-project/commit/618def651b59bd42c05bbd91d825af2fb2145683. `llvm-mc` emits regular relocations for ARM EH frames, which we do not yet handle correctly.

- (Probably) only works when `-dead_strip` is passed to LLD. Otherwise, we don't prune unreferenced FDEs. I'm doubtful that libunwind can handle these redundant FDEs gracefully.

Since the feature is not ready for real use yet, I've gated it behind a
flag that only gets toggled on during test suite runs. With most of the
new code disabled, we see just a hint of perf regression, so I don't
think it'd be remiss to land this as-is:

             base           diff           difference (95% CI)
  sys_time   1.926 ± 0.168  1.979 ± 0.117  [  -1.2% ..   +6.6%]
  user_time  3.590 ± 0.033  3.606 ± 0.028  [  +0.0% ..   +0.9%]
  wall_time  7.104 ± 0.184  7.179 ± 0.151  [  -0.2% ..   +2.3%]
  samples    30             31

Design
------

Like compact unwind entries, EH frames are also represented as regular
ConcatInputSections that get pointed to via `Defined::unwindEntry`. This
allows them to be handled generically by e.g. the MarkLive and ICF
code. (But note that unlike compact unwind subsections, EH frame
subsections do end up in the final binary.)

In order to make EH frames "look like" a regular ConcatInputSection,
some processing is required. First, we need to split the `__eh_frame`
section along EH frame boundaries rather than along symbol boundaries.
We do this by decoding the length field of each EH frame. Second, the
abs-ified relocations need to be turned into regular Relocs.

Next Steps
----------

In order to support EH frames on ARM targets, we will either have to
teach LLD how to handle EH frames with explicit relocs, or we can try to
make `llvm-mc` emit abs-ified relocs for ARM as well. I'm hoping to do
the latter as I think it will make the LLD implementation both simpler
and faster to execute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123435

Files:
  lld/MachO/Arch/ARM64.cpp
  lld/MachO/Arch/ARM64_32.cpp
  lld/MachO/Arch/X86_64.cpp
  lld/MachO/CMakeLists.txt
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/EhFrame.cpp
  lld/MachO/EhFrame.h
  lld/MachO/InputFiles.cpp
  lld/MachO/InputFiles.h
  lld/MachO/InputSection.cpp
  lld/MachO/InputSection.h
  lld/MachO/Relocations.h
  lld/MachO/Symbols.h
  lld/MachO/Target.h
  lld/MachO/UnwindInfoSection.cpp
  lld/test/MachO/Inputs/eh-frame-x86_64-r.o
  lld/test/MachO/eh-frame.s
  lld/test/MachO/invalid/eh-frame.s
  lld/test/MachO/tools/generate-cfi-funcs.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123435.421671.patch
Type: text/x-patch
Size: 45684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220409/faf61cc4/attachment-0001.bin>


More information about the llvm-commits mailing list