This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][ELF] Allow --set-section-flags src=... and --rename-section src=tst
ClosedPublic

Authored by MaskRay on Jul 7 2022, 5:28 PM.

Details

Summary
  • GNU objcopy supports --set-section-flags src=... --rename-section src=tst and --set-section-flags runs first.
  • GNU objcopy processes --update-section before --rename-section.

To match the two behaviors, postpone --rename-section and allow its use together
with --set-section-flags.

As a side effect, --rename-section=.foo1=.foo2 --add-section=.foo1=/dev/null
leads to .foo2 while GNU objcopy surprisingly produces .foo1 (so
--set-section-flags --add-section --rename-section do not form a total order).
I think the deviation is fine as a total order makes more sense.

Rename set-section-flags-and-rename.test to
set-section-attr-and-rename.test and additionally test --set-section-alignment

Diff Detail

Event Timeline

MaskRay created this revision.Jul 7 2022, 5:28 PM
MaskRay requested review of this revision.Jul 7 2022, 5:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 5:28 PM

If I'm not mistaken, this change does more than just enable --set-section-flags (and --set-section-alignment) to be run before --rename-section. In particular, I believe it now means that --rename-section can rename added sections, and that updated sections apply to sections with their original name, rather than renamed sections. (NB: I've only looked at these via code inspection, so might be misreading the code). I suspect these changes could potentially invalidate some workflows (whilst admittedly making new ones possible). For example, imagine I wanted to rename a section (e.g. to create a backup of it within the data), and then add a new section with the original name. This is no longer possible, I believe.

llvm/test/tools/llvm-objcopy/ELF/set-section-attr-and-rename.test
15

Nit: This line's getting quite long. Perhaps time to split it over two?

Aside: do we need a similar conflict error for --section-section-alignment?

llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
813
MaskRay updated this revision to Diff 443167.Jul 8 2022, 1:38 AM
MaskRay edited the summary of this revision. (Show Details)

Add tests. Clarify behavior changes

MaskRay updated this revision to Diff 443168.Jul 8 2022, 1:41 AM
MaskRay marked 2 inline comments as done.

address comments

llvm/test/tools/llvm-objcopy/ELF/set-section-attr-and-rename.test
15

Probably yes, but the test can be a separate change.

jhenderson accepted this revision.Jul 11 2022, 1:20 AM

LGTM, but I think the behaviour change warrants a release note.

This revision is now accepted and ready to land.Jul 11 2022, 1:20 AM
MaskRay updated this revision to Diff 443666.Jul 11 2022, 9:04 AM

add a release note

This revision was landed with ongoing or failed builds.Jul 11 2022, 9:04 AM
This revision was automatically updated to reflect the committed changes.
llvm/test/tools/llvm-objcopy/ELF/set-section-attr-and-rename.test