This adds support for the --discard-locals flag, which acts similarly to --discard-all, except it only applies to compiler-generated symbols (i.e. symbols starting with .L in ELF).
I am not sure about COFF local symbols: those appear to also use .L in most cases, but also use just L in other cases, so for now I am just leaving it unimplemented there.
Fixes PR36160
You can simplify this a bit, by removing one of the sections, removing the content of the other section, and removing things like the flags, address and alignment fields. You don't need much of an ELF to test symbol discarding.