Both the .ARM.exidx and .eh_frame sections have a custom SyntheticSection that acts as a container for the InputSections. The InputSections are added to the SyntheticSection prior to /DISCARD/ which limits the affect a /DISCARD/ can have to the whole SyntheticSection. In the majority of cases this is sufficient as it is not common to discard subsets of the InputSections. The Linux kernel has one of these scripts which has something like:
/DISCARD/ : { *(.ARM.exidx.exit.text) *(.ARM.extab.exit.text) ... }
The .ARM.exidx.exit.text are not discarded because the InputSection has been transferred to the Synthetic Section. The *(.ARM.extab.exit.text) sections have not so they are discarded. When we come to write out the .ARM.exidx sections the dangling references from .ARM.exidx.exit.text to .ARM.extab.exit.text currently cause relocation out of range errors, but could as easily cause a fatal error message if we check for dangling references at relocation time.
This patch attempts to respect the /DISCARD/ command by running it on the .ARM.exidx InputSections stored in the SyntheticSection.
The .eh_frame is in theory affected by this problem, but I don't think that there is a dangling reference problem that can happen with these sections.
Fixes remaining part of pr44824 (https://bugs.llvm.org/show_bug.cgi?id=44824)
Delete the function which is only called once.