[PATCH] D28612: [ELF] - Added support for --emit-relocs.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 04:07:38 PST 2017
grimar added inline comments.
================
Comment at: ELF/LinkerScript.cpp:266-277
+ if (!Config->EmitRelocs)
+ continue;
+
+ ArrayRef<InputSectionBase<ELFT> *> Sections = S->getFile()->getSections();
+ for (InputSectionBase<ELFT> *IS : Sections) {
+ if (!IS || !IS->Live || (IS->Type != SHT_REL && IS->Type != SHT_RELA))
+ continue;
----------------
ruiu wrote:
> grimar wrote:
> > ruiu wrote:
> > > What is this?
> > It fixes crash reported for PR31579, showed in emit-reloc-discard.s testcase.
> >
> > If we have some section, for example .debug_info and discard it from script,
> > then we are not able to emit .rela.debug_info section.
> >
> > Because "section to which the relocation applies" is not exist:
> >
> > ```
> > // sh_info for SHT_REL[A] sections should contain the section header index of
> > // the section to which the relocation applies.
> > InputSectionBase<ELFT> *S = Sections[0]->getRelocatedSection();
> > this->Info = S->OutSec->SectionIndex;
> > ```
> >
> > So that code discards .rel[a] sections in that case as well. That is consistent to what gnu linkers do.
> > I added comment.
> This seems like you are implement your own GC in some sense here. You probably should use `DependentSection` member of InputSection to do that automatically.
Thanks for hit about DependentSection, I used it in --gc-sections case (updated code and added testcase to show how it works now).
That place of code is used for handling "/DISCARD/". Which is handled in script much later than GC runs and not relative to GC. Though using of DependentSection helped here as well. It is not what I would call "automatically", but since it is not relative to GC, code looks good for me now. What do you think ?
https://reviews.llvm.org/D28612
More information about the llvm-commits
mailing list