Fail hard (or support) wildcard characters
| Bugzilla Link | 41268 |
| Resolution | FIXED |
| Resolved on | Oct 17, 2019 13:53 |
| Version | trunk |
| OS | Linux |
| CC | @alexshap,@eleviant,@jh7370,@nickdesaulniers,@rupprecht |
| Fixed by commit(s) | r375169 |
Extended Description
Several GNU objcopy/strip commands support glob-like syntax by default, such as: "strip --remove-section=.text.* --remove-section=!.text.foo". It seems the characters supported are: *, !, ?, , [, ].
My personal opinion is that the --regex flag we added to llvm-objcopy is better than this and we shouldn't carry this legacy syntax forward, but one downside we currently have is people using strip/objcopy may not notice these flags aren't working -- e.g. "--remove-section=.text." will try to remove a section literally called ".text." and end up not removing anything. Instead, we should return an error to make it more visible that the user needs to use a different syntax (regex instead of globs) and also pass --regex.
(Or, we could support globs, though I don't think anyone is in favor of that).
Glob support improved in r375149, llvm-objcopy change landed in r375169.
Glob support landed in r375051, reverted in r375052, relanded in 375126.
IIUC, there's still outstanding work now to tie the above infra into llvm-objcopy?
Yeah
r375126 is just a test fix because Windows filepaths are weird, and even that required a further fix w/ r375131. I'll reland r375051 (glob support) later today, and then land the rest of llvm-objcopy changes in D66613 soon after that.
Glob support landed in r375051, reverted in r375052, relanded in 375126.
IIUC, there's still outstanding work now to tie the above infra into llvm-objcopy?
Patch up: https://reviews.llvm.org/D66613
This feature would help us adopt llvm-strip for the Linux kernel: https://github.com/ClangBuiltLinux/linux/issues/478
We should be able to assume symbol/section names don't contain those given that the world has clearly been assuming that for ages. I just like to avoid making assumptions where possible.
The other thing to note is that llvm-objcopy doesn't have to be a tool that can do every possible operation on an object in every possible case. It should work in existing builds where it makes sense and it should be a tool that can be used in the common case for little binary modifications that experts need to make very occasionally.
Escaping would 100% solve the problem for me given that I'm mainly concerned about these 1-off expert cases not uses in existing builds.
If we can instead assume nobody has literal "*!?[]" in their symbol/section names, we could just fail in args parsing. But maybe we can't make that assumption? Does GNU provide a way of escaping these sort of characters? E.g. could a literal star be matched with '*'?
Personally, I think the '' syntax makes a lot of sense. For example, for some reason you might want to remove all relocation or all text sections, so -R .text or -R .rela.* would be nice, and much simpler than needing to use --regex (which would require different patterns, and require escaping of every '.' character). Beyond that I don't really care.
Actually, I'm not totally opposed to basic glob expansions (i.e. the * part), and maybe the ! for negation to go along with it, since those seem simple enough. But IMHO the rest seems better suited to explicitly requesting things as a regex. Either way though, we should fail more obviously on things we don't support.
We should fail hard if a glove character is used and not section matches the literal string input This will make use of objcopy/strip somewhat unpredictable. Suppose you do have a symbol literally called "Foo*" that you want to scrub anywhere it accidentally shows up in your build system. You cannot just call "strip -R Foo* foo.o", as that would then work on the objects where Foo* is contained, and fail if it doesn't show up, and you have to call "nm foo.o | grep Foo* && strip -R Foo* foo.o". That works, but doesn't seem particularly friendly.
If we can instead assume nobody has literal "*!?[]" in their symbol/section names, we could just fail in args parsing. But maybe we can't make that assumption?
I can imagine Linux or some other project uses that for better or for worse and they probably won't accept a patch that only adds support for llvm-objcopy
You guessed right, I forgot to include the context: this is something I noticed while looking at a Makefile in the Clang+Linux project: https://github.com/ClangBuiltLinux/linux/issues/435.
We should fail hard if a glove character is used and not section matches the literal string input. We should warn if any section name has a good character and if any section name used on the command line has a glove character.
If a use case emerges for globs that can't be worked around we should support it. I can imagine Linux or some other project uses that for better or for worse and they probably won't accept a patch that only adds support for llvm-objcopy
assigned to @rupprecht