This is an archive of the discontinued LLVM Phabricator instance.

[llvm] add -r functionality to llvm-bitcode-strip
ClosedPublic

Authored by rmaz on Feb 28 2022, 11:24 AM.

Details

Summary

This diff adds functionality to the llvm-bitcode-strip tool for
stripping of LLVM bitcode sections.

Diff Detail

Event Timeline

rmaz created this revision.Feb 28 2022, 11:24 AM
rmaz requested review of this revision.Feb 28 2022, 11:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2022, 11:24 AM

Please split this patch in two, one patch for each option. I'll then review the two independently.

llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-basic.test
1–2

This comment doesn't line up with what the test is doing.

rmaz planned changes to this revision.Mar 1 2022, 7:03 AM
rmaz added inline comments.
llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-basic.test
1–2

Whoops, should have removed

rmaz updated this revision to Diff 412101.EditedMar 1 2022, 7:36 AM

split out -o into separate diff D120731

jhenderson added inline comments.Mar 1 2022, 10:15 PM
llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-basic.test
4–7

Usually, we'd have one test file per option, i.e. in one test, you'd test -o, and another test, you'd test what the -r operation does.

12

I don't think you need to dump the entire section data. Sufficient should be to check the Name: and possibly Segment: fields (and then only the actual names, not the raw values you're currently checking too).

Example:

# RUN: ... | FileCheck %s --implicit-check-not=Name

# CHECK:      Name: __text
# CHECK-NEXT: Segment: __TEXT
# CHECK:      Name: __data
# CHECK-NEXT: Segment: __DATA
llvm/tools/llvm-objcopy/BitcodeStripOpts.td
27

Please normalise the help text to be consistent with ending with a period or not. I prefer not for help text.

llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
1219–1222

No braces for single-line if statements. I take it in the future, other options will provide different actions, and you just have to request one (or more) actions from the available set?

1224–1228

Period at end of sentences. Also, no braces for single-line if statements.

I think you need additional sections in your test case with a section in the __LLVM segment with a different name, and a __bundle section in a non-LLVM segment, to show that it's only the combination of the two that is removed.

It may also be a good idea to show what happens (in a test case) when the error callback is triggered in this code path.

Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 10:15 PM
rmaz added inline comments.Mar 2 2022, 7:10 AM
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
1219–1222

Yes, there are 2 other output options that I have not yet added:

-m     Remove the bitcode from the __LLVM segment, leaving behind a marker.

-l     Remove all of the native executable code, leaving the LLVM bitcode behind. In
       this case, bitcode_strip will take care to preserve the (__TEXT,__info_plist)
       section while removing the rest of the __TEXT segment.
rmaz added inline comments.Mar 2 2022, 7:26 AM
llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-basic.test
4–7

The reason for using a single test is that you cannot use -o without -r, so all the -o test could do would be to test you get an error without -r.

rmaz updated this revision to Diff 412425.Mar 2 2022, 8:13 AM
  • add test case for LLVM section with not bundle name
  • add test case for __bundle section in other segment
  • address formatting comments
rmaz marked 3 inline comments as done.Mar 2 2022, 8:14 AM
rmaz added inline comments.
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
1224–1228

I don't believe you can trigger the error callback on this code path as we are using a MatchStyle::Literal.

jhenderson added inline comments.Mar 2 2022, 10:45 PM
llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-basic.test
4–7

Thanks. When I made this and related comments, I didn't realise that you wanted to make -r a cumpolsory argument. Given that other commands are planned, I'd suggest the following test file breakdown between this and D120731:
bitcode-strip-basic.test - contains tests that show the -o option is required and that at least one command is required. You don't need to show what the behaviour of that command is in this test, other than it suppresses the error.
bitcode-strip-r.test (or similar longer name spelling out what -r does) - contains tests that show the behaviour of -r.

10

Nit: comments should end with a period. Also, you can delete "output flag and" from this comment: the previous test case covers this point, so no need for this test case to explicitly mention that too.

I'd also suggest deleting the blank line between comment and run command, since the two are tied together, rather than the comment being a general comment about the whole test file.

llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
1224–1228

Thanks. Can the if statement ever fail though? (I'm not sure if the ErrorCallback and returned Error are tied together or not). If not, I'd change it to cantFail.

rmaz updated this revision to Diff 412731.Mar 3 2022, 8:09 AM
rmaz marked an inline comment as done.
  • split test into basic and remove
  • cantFail instead of checking error that cannot occur
rmaz marked 4 inline comments as done.Mar 3 2022, 8:10 AM
rmaz added inline comments.
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
1224–1228

The if statement can only fail if the Matcher fails to create, which for a literal matcher cannot happen. Updated to cantFail.

This revision is now accepted and ready to land.Mar 4 2022, 12:14 AM
jhenderson added inline comments.Mar 4 2022, 12:25 AM
llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-remove.test
4

Actually, you should add a colon to the end of the --implicit-check-not command. Otherwise, this might accidentally match a part of someone's local directory tree.

rmaz updated this revision to Diff 413015.Mar 4 2022, 8:18 AM
rmaz marked an inline comment as done.

add : to implicit check not

rmaz updated this revision to Diff 413016.Mar 4 2022, 8:18 AM

with linter

rmaz marked an inline comment as done.Mar 4 2022, 8:19 AM
rmaz updated this revision to Diff 413069.Mar 4 2022, 10:42 AM

update test for windows

This revision was landed with ongoing or failed builds.Mar 4 2022, 1:28 PM
This revision was automatically updated to reflect the committed changes.