This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Update flag propagation rule to ignore discarded output sections
ClosedPublic

Authored by MaskRay on Jan 28 2022, 11:15 PM.

Details

Summary

See the updated insert-before.test for the effects: many synthetic
sections are SHF_ALLOC|SHF_WRITE. If they are discarded, we don't want
to propagate their flags to subsequent output section descriptions.

getFirstInputSection(sec) == nullptr can technically be merged into isDiscardable
but I'd like to postpone as not sharing getFirstInputSection(sec) == nullptr may give more refactoring .opportunity.

Depends on D118529.

Diff Detail

Event Timeline

MaskRay created this revision.Jan 28 2022, 11:15 PM
MaskRay requested review of this revision.Jan 28 2022, 11:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 28 2022, 11:15 PM
bluca accepted this revision.Jan 29 2022, 10:01 AM

Tested, this solves the problem with SHF_ALLOC in a SHT_NOTE section.

This revision is now accepted and ready to land.Jan 29 2022, 10:02 AM
peter.smith accepted this revision.Jan 31 2022, 5:51 AM

LGTM too.

lld/ELF/LinkerScript.cpp
1153

Trivial language nit, suggest one instead of an. // If sec has at least one input section and is not discarded.

andrewng added inline comments.Jan 31 2022, 8:03 AM
lld/ELF/LinkerScript.cpp
1152

I believe that all uses of isDiscardable() are now combined with getFirstInputSection() == nullptr, so perhaps getFirstInputSection() == nullptr should be part of isDiscardable()? Although that doesn't really "help" here as you need isEmpty.

MaskRay updated this revision to Diff 404606.Jan 31 2022, 10:36 AM
MaskRay marked an inline comment as done.

fix a comment

lld/ELF/LinkerScript.cpp
1152

Agree with your analysis.

isEmpty makes the code sharing not much helpful. Two factors make me think we may need to postpone the code share:

  • The code sharing causes getFirstInputSection(sec) to be called one extra time.
  • I think we may need to refactor this logic once again. Adding getFirstInputSection(sec) might make refactoring difficult.
1153

Thanks. Fixed.

MaskRay edited the summary of this revision. (Show Details)Feb 1 2022, 10:18 AM