Skip to content

Commit

Permalink
modpost: expand pattern matching to support substring matches
Browse files Browse the repository at this point in the history
Currently the match() function supports a leading * to match any
prefix and a trailing * to match any suffix.  However there currently
is not a combination of both that can be used to target matches of
whole families of functions that share a common substring.

Here we expand the *foo and foo* match to also support *foo* with
the goal of targeting compiler generated symbol names that contain
strings like ".constprop." and ".isra."

Signed-off-by: Paul Gortmaker <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
Paul Gortmaker authored and rustyrussell committed Apr 22, 2015
1 parent c5c3439 commit 09c20c0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr)
* "foo" will match an exact string equal to "foo"
* "*foo" will match a string that ends with "foo"
* "foo*" will match a string that begins with "foo"
* "*foo*" will match a string that contains "foo"
*/
static int match(const char *sym, const char * const pat[])
{
Expand All @@ -784,8 +785,17 @@ static int match(const char *sym, const char * const pat[])
p = *pat++;
const char *endp = p + strlen(p) - 1;

/* "*foo*" */
if (*p == '*' && *endp == '*') {
char *here, *bare = strndup(p + 1, strlen(p) - 2);

here = strstr(sym, bare);
free(bare);
if (here != NULL)
return 1;
}
/* "*foo" */
if (*p == '*') {
else if (*p == '*') {
if (strrcmp(sym, p + 1) == 0)
return 1;
}
Expand Down

0 comments on commit 09c20c0

Please sign in to comment.