This is an archive of the discontinued LLVM Phabricator instance.

[ELF] --orphan-handling=: don't warn/error for unused synthesized sections
ClosedPublic

Authored by MaskRay on Feb 25 2020, 3:33 PM.

Details

Summary

This makes --orphan-handling= less noisy.
This change also improves our compatibility with GNU ld.

GNU ld special cases .symtab, .strtab and .shstrtab . We need output section
descriptions for .symtab, .strtab and .shstrtab to suppress:

<internal>:(.symtab) is being placed in '.symtab'
<internal>:(.shstrtab) is being placed in '.shstrtab'
<internal>:(.strtab) is being placed in '.strtab'

With --strip-all, .symtab and .strtab can be omitted (--strip-all is not
compatible with --emit-relocs).

Diff Detail

Event Timeline

MaskRay created this revision.Feb 25 2020, 3:33 PM
MaskRay updated this revision to Diff 246593.Feb 25 2020, 3:42 PM

Improve tests

nickdesaulniers accepted this revision.Feb 25 2020, 3:55 PM

Thanks for the patch, just minor drive by comments, mostly aesthetic.

Is there anywhere we can document what the "synthetic sections" are?

lld/ELF/LinkerScript.cpp
731

Bikeshed: needs a better name. DiagnoseOrphanHandling or EnforceOrphanHandlingPolicy or such. process doesn't make any modifications.

732

Consider returning early if the loop invariant config->orphanHandling != OrphanHandlingPolicy::Error && config->orphanHandling != OrphanHandlingPolicy::Warn.

lld/ELF/LinkerScript.h
285

can this method be marked const?

lld/ELF/Writer.cpp
1680–1681

s/SS/ss/?

This revision is now accepted and ready to land.Feb 25 2020, 3:55 PM
kees added a comment.Feb 25 2020, 3:57 PM

On my orphan checking kernel series, I'm left with only .rela_* and .rela.* getting reported, along with:

(.shstrtab) is being placed in '.shstrtab'
(.strtab) is being placed in '.strtab'
(.symtab) is being placed in '.symtab'

The diff before and after this patch is:

$ diff -u /tmp/before.log /tmp/after.log 
--- /tmp/before.log     2020-02-25 15:56:05.906258196 -0800
+++ /tmp/after.log      2020-02-25 15:53:28.144706255 -0800
@@ -1,6 +1,3 @@
-(.bss.rel.ro) is being placed in '.bss.rel.ro'
-(.iplt) is being placed in '.iplt'
-(.plt) is being placed in '.plt'
 (.rela.altinstr_aux) is being placed in '.rela.altinstr_aux'
 (.rela.altinstr_replacement) is being placed in '.rela.altinstr_replacement'
 (.rela.altinstructions) is being placed in '.rela.altinstructions'
@@ -10939,4 +10936,3 @@
 (.shstrtab) is being placed in '.shstrtab'
 (.strtab) is being placed in '.strtab'
 (.symtab) is being placed in '.symtab'
-(.symtab_shndx) is being placed in '.symtab_shndx'
MaskRay updated this revision to Diff 246597.Feb 25 2020, 4:02 PM
MaskRay marked 4 inline comments as done.

Address review comments

lld/ELF/LinkerScript.cpp
731

Thanks for the suggestions. I'll go with diagnoseOrphanHandling. (I considered handleOrphanHandling and thought it is silly.)

732

I think the current code is more readable. (config->orphanHandling != OrphanHandlingPolicy::Error && config->orphanHandling != OrphanHandlingPolicy::Warn adds two extra lines.)

if ... else if makes it clear that there is the third choice (no diagnostics).

grimar added inline comments.Feb 26 2020, 12:48 AM
lld/test/ELF/linkerscript/orphan-report.s
18

There is an excessive space after ".symtab". Pehaps just add the word "sections"?

37

Use --implicit-check-not=<internal> in tests?
In the current way seems the test case accepts the situation when for a COMMON case
there is an internal section between .comment and .shstrtab

MaskRay updated this revision to Diff 246749.Feb 26 2020, 8:50 AM
MaskRay marked 2 inline comments as done.

Improve tests

MaskRay updated this revision to Diff 246753.Feb 26 2020, 8:55 AM
MaskRay edited the summary of this revision. (Show Details)

Update description

This revision was automatically updated to reflect the committed changes.