[llvm-objcopy] Add support for shell wildcards

Authored by rupprecht on Oct 17 2019, 1:51 PM.


[llvm-objcopy] Add support for shell wildcards

Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).

The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.

Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the fnmatch used by GNU objcopy since named character classes (e.g. [[:digit:]]) are not supported, but this should support most existing use cases (mostly just * is what's used anyway).

Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap

Reviewed By: MaskRay

Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66613

llvm-svn: 375169


Event Timeline

I've got a number of post-commit comments. Would you mind creating another review to address them, please?


--regex -> :option:--regex (with backticks surrounding "--regex"). Same goes for the llvm-strip document.


What's the point of --strip-debug here and in the llvm-strip case? If it's just to suppress the --strip-all behaviour of llvm-strip, I'd remove it and replace it with --no-strip-all only in llvm-strip for readability.


This comment is a little ambiguous, as it seems to imply that the following tests are only looking for literal matches. I'd change it to:

"... literal matches. Adding ..." -> "... literal matches, and that adding ..."


I think it might be worth a test case showing the glob behaviour for 0 matching characters, e.g. what happens with --remove-section='.b*ar'


You also need a test case showing that ? doesn't match 0 or 2+ characters.


Perhaps a cmp here might be more appropriate? Ditto for the third case.


Ditto re. cmp.


Why? Add that to the comment. (I assume it's "to keep the earlier tests simpler").


I think there are possibly some more test cases needed:

  1. Perhaps worth a case showing that what "\\" matches.
  2. Perhaps worth a case showing that "\**" matches '*' followed by any number of characters (i.e. that only the first character is escaped).
  3. What about attempting to escape a non-special character (e.g. "\s")?
  4. Finally, maybe worth a test case where a character is escaped part way through a glob string, possibly even with glob characters before it.

Regex and GlobPattern are shared...