[PATCH] D28612: [ELF] - Added support for --emit-relocs.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 01:29:48 PST 2017


grimar added inline comments.


================
Comment at: ELF/InputFiles.cpp:403-404
+
+    if (Config->EmitRelocs)
+      return make<InputSection<ELFT>>(this, &Sec, Name);
+
----------------
ruiu wrote:
> Needs comment.
> 
>   // Relocation sections processed by the linker are usually removed
>   // from the output, so returning `nullptr` for the normal case.
>   // However, if -emit-relocs is given, we need to leave them in the output.
>   // (Some post link analysis tools need this information.)
> 
Done. Thanks for comment.


================
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:
> 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.


https://reviews.llvm.org/D28612





More information about the llvm-commits mailing list