[PATCH] D61186: [LLD][ELF] /DISCARD/ output sections should not be orphans

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 08:45:53 PDT 2019


peter.smith added a comment.

In D61186#1482193 <https://reviews.llvm.org/D61186#1482193>, @andrewng wrote:

> In D61186#1482074 <https://reviews.llvm.org/D61186#1482074>, @grimar wrote:
>
> > I think it is 2 lines of code change actually :) I believe the much more correct way to fix it is this: https://reviews.llvm.org/D61251
> >  With this approach there is no `/DISCARD/` in the output.
> >  (note, I did not change the original test case there).
>
>
> Unfortunately, this doesn't completely work, although it does "work" for this particular issue. The problem is if the "/DISCARD/" has a PHDR assignment that needs to propagate to other sections, which is why the "isDiscardable" function returns false for sections with explicit PHDR assignment. It's an unlikely but still possible scenario.


Just to clarify my understanding, are you referring to (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html#OUTPUT-SECTION-PHDR)

>   If a section is assigned to one or more segments, then all subsequent allocated sections will be assigned to those segments as well, unless they use an explicitly :phdr modifier. You can use :NONE to tell the linker to not put the section in any segment at all.

Something like:

  /DISCARD/ : { *(.comment) } :my_phdr
   .name : { *(.name) }
  ...

Where we'd want .name to to be assigned to my_phdr and any following OutputSections? I can see that this is how ld.bfd and ld.gold behave, although as you say this is somewhat of a contrived example.

I'm with George in that we shouldn't output the /DISCARD/ as a SectionHeader as it isn't really an OutputSection, although as I understand it this is not a correctness problem. If we don't fix it in this patch can we add a FIXME ann/or raise a PR so that we know that we have a problem?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61186/new/

https://reviews.llvm.org/D61186





More information about the llvm-commits mailing list