This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Support input section description .gnu.version* in /DISCARD/
ClosedPublic

Authored by MaskRay on Dec 22 2019, 3:27 PM.

Details

Summary

Linux powerpc discards *(.gnu.version*) (arch/powerpc/kernel/vmlinux.lds.S)
to suppress --orphan-handling=warn warnings in the -pie output .tmp_vmlinux1

The support is simple. Just add isLive() to:

  1. Fix an assertion in SectionBase::getPartition() called by VersionTableSection::isNeeded().
  2. Suppress DT_VERSYM, DT_VERDEF, DT_VERNEED and DT_VERNEEDNUM, if the relevant section is discarded.

Event Timeline

MaskRay created this revision.Dec 22 2019, 3:27 PM
grimar accepted this revision.Dec 23 2019, 1:15 AM

LGTM

This revision is now accepted and ready to land.Dec 23 2019, 1:15 AM
MaskRay edited the summary of this revision. (Show Details)Dec 23 2019, 12:44 PM
MaskRay updated this revision to Diff 235297.Dec 25 2019, 2:53 PM
MaskRay edited the summary of this revision. (Show Details)

Suppress DT_VER* if the relevant section is discarded.

Coincidentally, someone asked https://sourceware.org/ml/binutils/2019-12/msg00329.html

With this patch, that use case can be satisified with:

/DISCARD/ : { *(.gnu.version*) }
grimar added inline comments.Dec 25 2019, 11:15 PM
lld/ELF/SyntheticSections.cpp
1440

Seems you can just use if (part.verSym->isNeeded()) here and if (part.verNeed->isNeeded()) below?

if (part.verSym->isNeeded())
  addInSec(DT_VERSYM, part.verSym);
if (part.verDef) {
  addInSec(DT_VERDEF, part.verDef);
  addInt(DT_VERDEFNUM, getVerDefNum());
}
if (part.verNeed->isNeeded()) {
 ...
}
lld/test/ELF/linkerscript/discard-gnu-version.s
25

You need to specify -d here and below I think to dump the dynamic table.

MaskRay updated this revision to Diff 235320.Dec 25 2019, 11:48 PM
MaskRay marked an inline comment as done.

Simplify DT_VERSYM
Fix DT_VERDEF

grimar added inline comments.Dec 25 2019, 11:57 PM
lld/ELF/SyntheticSections.cpp
1446

Can't you remove hasVerNeed variable and use verNeed->isNeeded() here too?

grimar added inline comments.Dec 26 2019, 12:00 AM
lld/ELF/SyntheticSections.cpp
1446

You perhaps need to add isLive() condition to bool VersionNeedSection<ELFT>::isNeeded() for that.

MaskRay updated this revision to Diff 235322.Dec 26 2019, 12:27 AM
MaskRay marked 4 inline comments as done.

move isLive() to VersionNeedSection<ELFT>::isNeeded()

lld/ELF/SyntheticSections.cpp
1446

Yes.. I was a bit hesitant whether we should move isLive() to VersionNeedSection<ELFT>::isNeeded(). Note that we don't check isLive() in SyntheticSection::isNeeded(), the base member function.

It seems moving isLive() makes the code look better. So I will do that.

grimar accepted this revision.Dec 26 2019, 12:34 AM

LGTM

This revision was automatically updated to reflect the committed changes.