This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Fix --add-section when section contain empty bytes
ClosedPublic

Authored by gmorer on Dec 2 2022, 10:25 AM.

Details

Summary

Implicit cast between char* and StringRef when writing sections.

Reproduce:

$> llvm-objcopy --dump-section=name=name.data out.wasm
$> llvm-objcopy --remove-section=name out.wasm out_no_name.wasm
$> llvm-objcopy --add-section=name=name.data out_no_name.wasm out_new_name.wasm

# With wasm-objdump -h we can see that the name section is not totally copied in the new wasm file (if it actually contain empty bytes)

Diff Detail

Event Timeline

gmorer created this revision.Dec 2 2022, 10:25 AM
gmorer edited the summary of this revision. (Show Details)Dec 2 2022, 10:26 AM
gmorer published this revision for review.Dec 2 2022, 10:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2022, 10:37 AM

The code looks good to me. Could you add a test case to llvm/test/tools/llvm-objcopy/wasm/add-section.test?
I guess it could be like the 2nd test case (that creates a file using echo and adds it, then checks the YAML payload).

dschuff accepted this revision.Dec 2 2022, 4:04 PM
dschuff added inline comments.
llvm/test/tools/llvm-objcopy/wasm/add-section.test
23

nit: Can you mention in the comment that zero bytes are an important component of this test?

This revision is now accepted and ready to land.Dec 2 2022, 4:04 PM
gmorer updated this revision to Diff 479778.Dec 2 2022, 4:26 PM

Update the test explanation

gmorer marked an inline comment as done.Dec 2 2022, 4:27 PM

Thanks! do you need me to commit this?

gmorer added a comment.Dec 2 2022, 4:41 PM

Yes please!

This revision was landed with ongoing or failed builds.Dec 2 2022, 5:00 PM
This revision was automatically updated to reflect the committed changes.
dyung added a subscriber: dyung.Dec 2 2022, 10:42 PM

@gmorer I had to revert your change because it was causing at least 2 Windows build bots to fail:

gmorer reopened this revision.Dec 3 2022, 2:57 PM
This revision is now accepted and ready to land.Dec 3 2022, 2:57 PM
gmorer updated this revision to Diff 479872.Dec 3 2022, 2:57 PM

Trying to fix windows test suite, because echo does not behave the same as unix

Nit: the reiew title uses --section-add but the option is --add-section. Please update.

llvm/test/tools/llvm-objcopy/wasm/add-section.test
23

Nit: most comments in tests in llvm-objcopy, including some in this file, use ## to mark them rather than just # to distinguish them from lit test directives.

gmorer updated this revision to Diff 480030.Dec 5 2022, 2:48 AM

Update test comment

gmorer retitled this revision from [llvm-objcopy] Fix --section-add when section contain empty bytes to [llvm-objcopy] Fix --add-section when section contain empty bytes.Dec 5 2022, 2:49 AM
gmorer updated this revision to Diff 480031.Dec 5 2022, 2:52 AM
gmorer marked an inline comment as done.

Change commit name

jhenderson added inline comments.Dec 5 2022, 3:07 AM
llvm/test/tools/llvm-objcopy/wasm/add-section.test
30
gmorer updated this revision to Diff 480042.Dec 5 2022, 3:54 AM

Update test comment

gmorer marked an inline comment as done.Dec 5 2022, 3:54 AM
gmorer added a comment.EditedDec 5 2022, 5:48 AM

Do i need to prefix the commit message with "Reapply: ", and tell which commit reverted it? Not 100% sure it pass the windows tests, I used echo the same way it's used in other tests. But i do not have a windows build machine with the same env to test on.

dschuff added a comment.EditedDec 5 2022, 6:08 PM

Thanks for fixing this! I tested it on windows and it seems to work (with the caveat that it's not my primary platform either). I'll reland it. I'll add "reland" to the commit message but it also still has the link to this review issue, so that should be good enough for context.

This revision was landed with ongoing or failed builds.Dec 5 2022, 6:13 PM
This revision was automatically updated to reflect the committed changes.