objcopy/strip: Allow section patterns starting with '!'.
For symbol matching, prefixing a pattern with '!' will indicate a non-matching pattern, however, this is not the case for section patterns. As a result it is not possible to say "apply this action to all sections except ...". With this commit the objcopy and strip tools now support '!' prefix for section patterns, so we can say: objcopy --remove-section="*" --remove-section="!.text*" Which will remove all sections, except those matching the pattern '.text*'. binutils/ChangeLog: * objcopy.c (find_section_list): Handle section patterns starting with '!' being a non-matching pattern. * doc/binutils.texi (objcopy): Give example of using '!' with --remove-section and --only-section. (strip): Give example of using '!' with --remove-section. * testsuite/binutils-all/data-sections.s: New file. * testsuite/binutils-all/only-section-01.d: New file. * testsuite/binutils-all/remove-section-01.d: New file. * testsuite/binutils-all/objcopy.exp: Run new tests. * NEWS: Mention new feature.
This commit is contained in:
parent
7df94786e4
commit
e511c9b19f
8 changed files with 124 additions and 11 deletions
|
@ -854,7 +854,7 @@ parse_symflags (const char *s, char **other)
|
|||
static struct section_list *
|
||||
find_section_list (const char *name, bfd_boolean add, unsigned int context)
|
||||
{
|
||||
struct section_list *p;
|
||||
struct section_list *p, *match = NULL;
|
||||
|
||||
/* assert ((context & ((1 << 7) - 1)) != 0); */
|
||||
|
||||
|
@ -890,19 +890,36 @@ find_section_list (const char *name, bfd_boolean add, unsigned int context)
|
|||
}
|
||||
/* If we are not adding a new name/pattern then
|
||||
only check for a match if the context applies. */
|
||||
else if ((p->context & context)
|
||||
/* We could check for the presence of wildchar characters
|
||||
first and choose between calling strcmp and fnmatch,
|
||||
but is that really worth it ? */
|
||||
&& fnmatch (p->pattern, name, 0) == 0)
|
||||
{
|
||||
p->used = TRUE;
|
||||
return p;
|
||||
}
|
||||
else if (p->context & context)
|
||||
{
|
||||
/* We could check for the presence of wildchar characters
|
||||
first and choose between calling strcmp and fnmatch,
|
||||
but is that really worth it ? */
|
||||
if (p->pattern [0] == '!')
|
||||
{
|
||||
if (fnmatch (p->pattern + 1, name, 0) == 0)
|
||||
{
|
||||
p->used = TRUE;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fnmatch (p->pattern, name, 0) == 0)
|
||||
{
|
||||
if (match == NULL)
|
||||
match = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! add)
|
||||
return NULL;
|
||||
{
|
||||
if (match != NULL)
|
||||
match->used = TRUE;
|
||||
return match;
|
||||
}
|
||||
|
||||
p = (struct section_list *) xmalloc (sizeof (struct section_list));
|
||||
p->pattern = name;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue