[PATCH] D102138: [LLD] [COFF] Fix including the personality function for DWARF EH when linking with --gc-sections

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 11 14:04:24 PDT 2021


MaskRay added a comment.

.eh_frame consists of FDE (text section contribution) and CIE (common part shared by multiple FDE).
It needs to be monolithic in -ffunction-sections mode because:

- A section header has a large overhead (sizeof(Elf64_Shdr)=64).
- A CIE must precede a FDE which references it (`CIE Pointer` in a FDE is a non-zero unsigned integer). The input section order in one object file may not match the output section order, breaking this requirement. (I am surprised that mingw can have fragmented `.eh_frame$`

.eh_frame pieces can be stale (GC, ICF), so ld.lld has a pass merging .eh_frame pieces and discarded unneeded pieces.

When GC is concerned: ld.lld computes --gc-sections (`markLive<ELFT>()`) before combining .eh_frame pices (`combineEHSections`).
So we now have a phase ordering problem.
Since GC runs earlier, we have to conservatively assume all .eh_frame pieces live.
See the comment in `MarkLive.cpp:scanEHFrameSection` and `MarkLive<ELFT>::resolveReloc`: we retain most referenced symbols live except
a symbol defined in an executable non-linkorder-non-group section.

In ELF, you may find `test/ELF/eh-frame-gc{,2}.s` and their history useful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102138



More information about the llvm-commits mailing list