The combineEhSections runs, by design, before processSectionCommands so that input exception sections like .ARM.exidx and .eh_frame are not assigned to OutputSections. Unfortunately if /DISCARD/ removes InputSections that have associated .ARM.exidx sections without discarding the .ARM.exidx synthetic section then we will end up crashing when trying to sort the InputSections in ascending address order.
We fix this by filtering out the sections that have been discarded prior to processing the InputSections in finalizeContents()
fixes pr42890
Note that we cannot discard a subset of the .ARM.exidx table in LLD as by the time the /DISCARD/ has been evaluated it is a single synthetic section called .ARM.exidx. I'm not too concerned about this as a partial discard doesn't make a lot of sense as LLD creates synthetic entries to fill any gaps in the table.
I don't think that this affects .eh_frame as we don't have the dependent section and ordering requirements that we do for .ARM.exidx.
with a -> with a dependent?