https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81968
--- Comment #21 from Richard Biener <rguenth at gcc dot gnu.org> --- Created attachment 42225 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42225&action=edit patch to really remove discarded sections The attached removes discarded sections and thus should avoid one class of warnings. It's incomplete with now dead code not removed and incomplete in not handling SHN_XINDEX (I suppose the code marking required sections as needed isn't handling that correctly either). I'm quite sure we eventually would have to care for this given LTO bytecode contains one section per function (so we need "only" ~65250 functions to trigger an issue). Note that SHT_NULL is documented as #define SHT_NULL 0 /* Section header table entry unused */ that doesn't mean that such unused entries do not exist. Not sure what Solaris ld is really complaining about... Alternatively we could use an empty SHT_NOTE with SHF_EXCLUDE (but maybe it then warns about empty SHT_NOTE or one without a section name...). For the symbol table entry issue I'm not sure, I obviously can't produce an assembler testcase producing a UNDEF global without a referece to it. But I can believe the linker isn't forced to "remove" unused UNDEFs in case they are present. But maybe it is, as said, a question for the Solaris ld folks again. Similar to the attached patch a patch rewriting all relocation entries with a to be produced symbol table mapping would be possible.