This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Add --keep-section flag
ClosedPublic

Authored by sbc100 on May 4 2023, 4:09 PM.

Details

Summary

This flag causes wasm-ld preserve a section even in the face of
--strip-all. This is useful, for example, to preserve the
target_features section in the ase of clang (which can run wasm-opt
after linking), and emcc (which performs a bunch of post-link work).

Fixes: https://github.com/llvm/llvm-project/issues/60613
Fixes: https://github.com/llvm/llvm-project/issues/55781

Diff Detail

Event Timeline

sbc100 created this revision.May 4 2023, 4:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 4:09 PM
Herald added subscribers: pmatos, asb, wingo and 4 others. · View Herald Transcript
sbc100 requested review of this revision.May 4 2023, 4:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 4:09 PM

Still needs a test..

kripken accepted this revision.May 4 2023, 4:41 PM
This revision is now accepted and ready to land.May 4 2023, 4:41 PM

Do we want to make this any more general? In the future we might want to preserve other sections, e.g. passing optimization or profiling info from LLVM to Binaryen. Or maybe JSPI info?

sbc100 added a comment.May 8 2023, 2:55 PM

Do we want to make this any more general? In the future we might want to preserve other sections, e.g. passing optimization or profiling info from LLVM to Binaryen. Or maybe JSPI info?

Do you have something you suggest? Something like --preserve-section=custom_section_name?

Yeah, I think that would work. Or maybe --preserve-sections=sec1,sec2 since we might want to preserve multiple sections.

sbc100 updated this revision to Diff 557937.Oct 30 2023, 9:12 AM
  • rename flag

Updated to use --keep-section. PTAL.

sbc100 retitled this revision from [lld][WebAssembly] Add --preserve-features flag to [lld][WebAssembly] Add --keep-section flag.Oct 30 2023, 9:13 AM
sbc100 edited the summary of this revision. (Show Details)
kripken requested changes to this revision.Oct 30 2023, 9:57 AM
kripken added inline comments.
clang/lib/Driver/ToolChains/WebAssembly.cpp
154

Shouldn't secton => section?

This revision now requires changes to proceed.Oct 30 2023, 9:57 AM
dschuff added inline comments.Oct 30 2023, 2:58 PM
lld/wasm/Options.td
196

Can this flag be used more than once? From the code it looks like maybe it can, but the description should maybe say that and there should be a test (probably I should have written one for objcopy/strip too)

sbc100 updated this revision to Diff 557958.Nov 1 2023, 10:28 AM
sbc100 marked an inline comment as done.
  • feedback
sbc100 updated this revision to Diff 557959.Nov 1 2023, 10:36 AM
sbc100 marked an inline comment as done.
  • feedback
sbc100 updated this revision to Diff 557960.Nov 1 2023, 10:43 AM
  • feedback
kripken accepted this revision.Nov 1 2023, 11:32 AM
This revision is now accepted and ready to land.Nov 1 2023, 11:32 AM
dschuff accepted this revision.Nov 1 2023, 3:27 PM

otherwise LGTM

lld/wasm/Options.td
196

Should this description also say that keep-section can be used more than once? or is there some other way to know that?

This revision was automatically updated to reflect the committed changes.
lld/test/wasm/strip-all.s