[ELF] --gc-sections: collect unused .gcc_except_table in section groups and…

Authored by MaskRay on Tue, Nov 17, 9:11 AM.


[ELF] --gc-sections: collect unused .gcc_except_table in section groups and associated text sections

try ... catch in an inline function produces .gcc_except_table.* in a COMDAT
group with GCC or newer Clang (since D83655). For --gc-sections, currently we
scan .eh_frame pieces and mark liveness of such a .gcc_except_table.* and
then the associated .text.* (if a member in a section group is retained, the
others should be retained as well).

Essentially all .text.* and .gcc_except_table.* compiled from inline
functions with try ... catch cannot be discarded by the imprecise
--gc-sections. Compared with the state before D83655, the output
.gcc_except_table is smaller (non-prevailing copies in COMDAT groups can now
be discarded) but .text may be larger, i.e. size regression.

This patch teaches the .eh_frame piece scanning code to not mark
.gcc_except_table in a section group, thus allow unused .text.* and
.gcc_except_table.* in a section group to be discarded.

Note, non-group .gcc_except_table can still not be discarded. That is the status quo.

Reviewed By: grimar, echristo

Differential Revision: https://reviews.llvm.org/D91579