This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Fix help text
ClosedPublic

Authored by sameerarora101 on Jun 15 2020, 9:47 PM.

Details

Summary

Update help text for each of the three tools: objcopy, strip and
install-name-tool. For reference: the issue is
highlighted in comments under https://reviews.llvm.org/D81527.

Diff Detail

Event Timeline

sameerarora101 created this revision.Jun 15 2020, 9:47 PM
Herald added a project: Restricted Project. · View Herald Transcript
sameerarora101 edited the summary of this revision. (Show Details)Jun 15 2020, 9:49 PM

llvm-strip doesn't allow a positional argument output either, as it can take multiple input files. This looks like a regression in the help text since an older version I have kicking around. Could you fix it for both (and update the patch description), please? You should also expand the help message test for both llvm-strip and llvm-objcopy to test that the full string has been matched.

llvm/tools/llvm-objcopy/CopyConfig.cpp
403–416

Rather than relying on a string for the name, I wonder if this code would be more robust with an enum that represents the three different tools, given that there's always potential for more front ends to be added. You would probably still want to pass in the tool name, but that could just be whatever the executable is called, possibly. For example, if the tool was llvm_install_name_tool, it would print that as the name in the help text message, rather than the current llvm-install-name-tool.

sameerarora101 marked an inline comment as done.

Update help text for install-name-tool, strip and objcopy.

sameerarora101 marked an inline comment as done.Jun 16 2020, 7:40 AM
sameerarora101 added inline comments.
llvm/tools/llvm-objcopy/CopyConfig.cpp
403–416

So I made a small enum and passed the appropriate enum types at the various function calls to printHelp. Does this work?

sameerarora101 retitled this revision from [llvm-objcopy] Fix help text for install-name-tool to [llvm-objcopy] Fix help text.Jun 16 2020, 7:40 AM
sameerarora101 edited the summary of this revision. (Show Details)Jun 16 2020, 7:46 AM
jhenderson accepted this revision.Jun 17 2020, 12:27 AM

LGTM, with one nit.

llvm/test/tools/llvm-objcopy/ELF/help-message.test
17–18

Nit: whilst you're here, please delete one of these two blank lines.

llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test
1–3

So I just noticed that neither this nor the llvm-objcopy/llvm-strip test belong in their current directories - they should be one level up, since they are not platform specific, and probably then merged into a single test in my opinion. No need to change it in this patch, but if you can afford the hopefully small amount of time to do it, I think merging the two tests and putting them in llvm/test/tools/llvm-objcopy/ would be a nice thing to do.

Note that tool-name.test already tests all three tools.

llvm/tools/llvm-objcopy/CopyConfig.cpp
403–416

Yup, thanks.

This revision is now accepted and ready to land.Jun 17 2020, 12:27 AM
sameerarora101 marked 3 inline comments as done.Jun 17 2020, 6:37 AM
sameerarora101 added inline comments.
llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test
1–3

yup, i can create a separate diff merging the two help test files into help-message.test

sameerarora101 marked an inline comment as done.

Deleting extra blank line.

alexander-shaposhnikov requested changes to this revision.Jun 22 2020, 6:06 PM
alexander-shaposhnikov added inline comments.
llvm/tools/llvm-objcopy/CopyConfig.cpp
403

nit: ToolType ToolEnum -> ToolType Tool

ToolName can be derived from ToolType, we probably don't need to pass it as an argument.

This revision now requires changes to proceed.Jun 22 2020, 6:06 PM
jhenderson added inline comments.Jun 23 2020, 12:10 AM
llvm/tools/llvm-objcopy/CopyConfig.cpp
403

How would you and others feel about passing in the real executable name and printing that instead? It was an idea I had, but didn't suggest it before.

llvm/tools/llvm-objcopy/CopyConfig.cpp
403

I would be fine with that

sameerarora101 marked 2 inline comments as done.Jun 23 2020, 9:10 AM
sameerarora101 added inline comments.
llvm/tools/llvm-objcopy/CopyConfig.cpp
403

@jhenderson What do you mean by "real executable name"? So what should I be doing here now? We keep the ToolName? Sorry for not understanding what you guys meant exactly 😔

Currently I have made the change ToolType ToolEnum -> ToolType Tool. Not sure about ToolName yet?

ToolEnum -> Tool

llvm/tools/llvm-objcopy/CopyConfig.cpp
403

@sameerarora101, sorry about the confusion, if I understand correctly @jhenderson is referring to the global variable ToolName (initialized in llvm-objcopy.cpp) or its basename. My first thought was that it might be useful but now i think that there are some undesirable consequences of this approach - e.g. some unexpected changes to the help message if the binary is moved around. It's already the case to some extent (because that's how we differentiate objcopy vs strip vs install-name-tool), but now it'll happen more frequently + it would create a dependency on the global variable from another file. I don't insist on any particular approach here, it feels like it's simpler to get rid of the duplication which I mentioned above and keep the old behavior.

sameerarora101 marked 2 inline comments as done.

Removing ToolName as an argument

sameerarora101 added inline comments.Jun 23 2020, 1:47 PM
llvm/tools/llvm-objcopy/CopyConfig.cpp
403

oh ok I think I understand now. Thanks a lot for clarifying @alexshap . I'll update the diff to remove duplication.

jhenderson accepted this revision.Jun 24 2020, 12:09 AM
jhenderson added inline comments.
llvm/tools/llvm-objcopy/CopyConfig.cpp
403

Thanks for the update. I was suggesting something like the following output:

my-renamed-objcopy-11.exe [options] input [output]

etc, i.e. whatever the real file name is, but I'm not sure about it myself either way, so I'm happy not to bother.

This revision is now accepted and ready to land.Jun 24 2020, 10:40 AM
This revision was automatically updated to reflect the committed changes.