This will allow to use llvm-objcopy with file names that begin with dashes.
Details
Diff Detail
Event Timeline
I'm not against the functional change, but why have so many tests changed? You should have a single dedicated test that covers this, rather than arbitrarily modifying existing tests to cover the new behaviour. As this is not file format specific, it can even be put in the top-level llvm-objcopy directory, although you may want a comment saying it is testing generic behaviour, since it'll presumably need to use e.g. an ELF object to avoid the "no input file" error.
Is there a particular reason you've singled out llvm-objcopy, and not llvm-strip?
llvm/tools/llvm-objcopy/CopyConfig.cpp | ||
---|---|---|
478 | Nit: fix this clang-tidy issue. | |
486 | What about the case where a user does llvm-objcopy -- with no arguments or input files? What does GNU objcopy do in this case? |
I agree that it would be better to create a single LIT test for a file name beginning with dash, but it is not clear how to write it. I assume such test would require use of %T (directory of a %t), but according to the documentation it is deprecated now. So, I decided to follow the same strategy for testing this patch as was used in a similar llvm-rc change (D56743) - updating few arbitrary tests to use ‘--’ separator for the file names. If you have ideas how to write a test for a file name beginning with ‘-‘, please share.
Is there a particular reason you've singled out llvm-objcopy, and not llvm-strip?
No, no particular reason. I only needed this to be supported in llvm-objcopy, so I’ve changed this tool only. But I can prepare a similar change for llvm-strip as well in a separate patch.
llvm/tools/llvm-objcopy/CopyConfig.cpp | ||
---|---|---|
486 | GNU objcopy prints help in this case. I have updated this change to match GNU objcopy behavior: llvm-objcopy -- => print help |
You can use something like mkdir %t in tests (see various cases throughout the testsuites) and then cd into that directory, where you can then use relative names, e.g. to files starting with -, without neeing %t to be involved.
Is there a particular reason you've singled out llvm-objcopy, and not llvm-strip?
No, no particular reason. I only needed this to be supported in llvm-objcopy, so I’ve changed this tool only. But I can prepare a similar change for llvm-strip as well in a separate patch.
Sounds reasonable.
llvm/tools/llvm-objcopy/CopyConfig.cpp | ||
---|---|---|
478 | Actually, auto doesn't really gain us anything here, as the return type is not obvious from the single line here. Just make the type explicit. |
llvm/test/tools/llvm-objcopy/objcopy-dash-dash.test | ||
---|---|---|
1 ↗ | (On Diff #346106) | Nit: in newer llvm-objcopy tests, we tend to use ## for comment markers, to make the comments stand out clearly from the test directives. Also, no need for "objcopy" to be in the name. dash-dash.test would be sufficient. Since the functionality for llvm-strip would be nearly identical, it could live in the same test. |
4–5 ↗ | (On Diff #346106) | I would change the commnet slightly to make it generic - after all, non-dashed files are still valid after this point too. Something like: "Check that llvm-objcopy correctly treats paths after "--" as file paths, even if they start with dashes." You would then have a case where the name has a dash as a leading character, and another where it doesn't. I'd make the filenames with a leading dash valid options too. Also, I recommend you test the following cases:
|
8 ↗ | (On Diff #346106) | You don't need to check the full file properties. In fact, I'd recommend doing a run without -- and then use cmp to compare this with the output of the different test cases. |
10–19 ↗ | (On Diff #346106) | This can be dramatically simplified. We don't need a section at all, and I believe the Machine is optional too. You can also remove excess padding, and add the --- to properly start the YAML. |
LGTM, with one suggestion.
llvm/test/tools/llvm-objcopy/dash-dash.test | ||
---|---|---|
12 ↗ | (On Diff #346147) | I'd put the -- before test-obj here. That way, you have coverage for all positional arguments being after the --. It also removes the potential for positional arguments either side of the -- treating the first as an option (in terms of whether the lack of options is an issue). |
llvm/test/tools/llvm-objcopy/dash-dash.test | ||
---|---|---|
9 ↗ | (On Diff #346364) | This is causing a bot failure: If you have some cmp that requires the --, I have found that using env POSIXLY_CORRECT=1 cmp would help. |
llvm/test/tools/llvm-objcopy/dash-dash.test | ||
---|---|---|
9 ↗ | (On Diff #346364) | Or using cmp -- out-obj1 --only-section would work. |
clang-tidy: warning: 'auto DashDash' can be declared as 'const auto *DashDash' [llvm-qualified-auto]
not useful