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

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 11 23:03:40 PDT 2021


mstorsjo added a comment.

In D102138#2752049 <https://reviews.llvm.org/D102138#2752049>, @MaskRay wrote:

> .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$`

Thanks for the info! No I'm not saying that mingw can have fragmented `.eh_frame$`, that was just my initial assumption for how to implement it, mirroring the SEH case. But now it does indeed sound like that wouldn't be the right thing to do, so that saves me some amount of wasted time. Thanks!

> .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.
> However, we don't necessarily retain everything referenced by .eh_frame pieces.
> 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.

Thanks! That sounds like it would be the way to go, but it also sounds like a bit more effort than I was expecting to spend on it, so in that case, I think this particular approach might be good enough for now - dwarf EH on mingw isn't used on the most important targets anyway.



================
Comment at: lld/test/COFF/gc-dwarf-eh.s:37
+.section .eh_frame,"r"
+.long _main at IMGREL
+.long ___gxx_personality_v0 at IMGREL
----------------
MaskRay wrote:
> Is `.cfi_personality` supported? Would be good to use correct content. The personality (`__gxx_personality_v0`) relocation precedes the text section symbols.
I can try to give it a shot to rewrite this using proper CFI directives. This way it felt a bit more clear exactly what the object file looks like though (although I could reorder things to fake a real .eh_frame a bit better too).


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