[PATCH] D28612: [ELF] - Added support for --emit-relocs.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 12:52:46 PST 2017
ruiu added inline comments.
================
Comment at: ELF/InputFiles.cpp:409
+ return make<InputSection<ELFT>>(this, &Sec, Name);
+
return nullptr;
----------------
nit: remove this blank line.
================
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;
----------------
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.
https://reviews.llvm.org/D28612
More information about the llvm-commits
mailing list