This patch implements GNU objcopy -w option, but uses regex instead of glob
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
In general, I think regex is probably a better choice than wildcards, but I'd be wary of pretending to be GNU compatible with -w when it's a different format. Maybe -r would be better, or maybe we don't even need a short arg for this. If we're going to implement it as -w, I think it would be better to actually be wildcards.
i.e. if someone drops llvm-objcopy into their toolchain and somewhere they use -w -G foo*, that means it now only matches things like fooooooo but not foobar (and additionally will now match fo too!)... but it may be a error that takes a while to be exposed. (In general, people assume tools work just fine, and don't always feel the need to write tests).
If we use a different flag, the error will be obvious: it will be "-w is not a valid flag" and exit 1.
Also a question, for others as well: is this a feature we actually want to carry forward? Are there any users of this feature/is it useful? This isn't something I've come across as actually being used, though I'm happy to review it if is.
tools/llvm-objcopy/CopyConfig.h | ||
---|---|---|
100 ↗ | (On Diff #184512) | Technically, the section flags among these always accept wildcards. -w only affects symbol name matching. I'm fine with this though. |
Are there any users of this feature/is it useful?
One of such users is myself. I'm using it to strip specific classes (with all methods and data) from relocatable objects and then execute those object files on memory tight embedded platform using OrcJIT. This is pretty specific use case though.
Still sounds like a reasonable use-case anyway. I could see it being useful for library providers too, who want to hide some things in the external interface, though I don't know of any concrete examples.
If we choose to support this (and I'm happy to +1 it), then I think it should only be a long-form switch, with no short-form equivalent. That's because there's a much higher chance of something being added to GNU objcopy in the future with a short alias that causes a clash than for a long-form version.
OK, thanks -- just wanted to double check it's useful, and sounds like it is. I'm on board too :)
test/tools/llvm-objcopy/ELF/globalize.test | ||
---|---|---|
7 ↗ | (On Diff #184726) | nit: please use --regex instead of -regex in these test cases |
8 ↗ | (On Diff #184726) | In cases where this should be identical to the output of another another command, you can use cmp instead of another readobj | FileCheck, e.g. cmp %t2 %t3 |
tools/llvm-objcopy/CopyConfig.h | ||
52 ↗ | (On Diff #184726) | Can you add a test that just demonstrates regex matching itself? |
64 ↗ | (On Diff #184726) | It looks like this does regex matching anywhere within the string. I think it might be less error prone if we make it a full string regex match, e.g. special.* -- currently matches not-special. I think we should force the user to write .*special.* if that's what they want. Python has a similar distinction, re.match vs re.search. I don't think llvm's regex has anything similar builtin, so you may need to manually wrap the expression in ^$. |
101 ↗ | (On Diff #184726) | It might be worth using StringSaver or something for this, so they can all be StringRef and avoid templating NameOrRegex. I'll take a look since I introduced that nonsense here. |
tools/llvm-objcopy/CopyConfig.h | ||
---|---|---|
53 ↗ | (On Diff #184726) | tbh I have mixed feelings regarding this,
|
tools/llvm-objcopy/CopyConfig.h | ||
---|---|---|
53 ↗ | (On Diff #184726) | although my second thought is that probably it might make sense to have these two cases separate (performance, simplicity of the most popular use case). |
tools/llvm-objcopy/CopyConfig.h | ||
---|---|---|
53 ↗ | (On Diff #184726) | llvm-strip may use multiple CopyConfig instances which differ only in input/output file names. for (const char *Filename : Positional) { Config.InputFilename = Filename; Config.OutputFilename = Filename; DC.CopyConfigs.push_back(Config); } |
tools/llvm-objcopy/CopyConfig.h | ||
---|---|---|
53 ↗ | (On Diff #184726) | oh, i see, this is kind of unfortunate, but i see what you are saying. |
LGTM, with nit fix.
tools/llvm-objcopy/CopyConfig.h | ||
---|---|---|
54 ↗ | (On Diff #185250) | Nit: mumltiple -> multiple |