This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
[patch] Allow an EXCLUDE_FILE list in linker scripts
- To: binutils at sourceware dot cygnus dot com
- Subject: [patch] Allow an EXCLUDE_FILE list in linker scripts
- From: "Catherine L. Moore" <clm at cygnus dot com>
- Date: Tue, 04 Jan 2000 12:53:35 -0600
This patch will allow a list of files to specified in an EXCLUDE_FILE
statement. The previous implementation allowed a single file to be
specified. Okay to commit?
Tue Jan 4 10:00:04 2000 Catherine Moore <clm@cygnus.com>
* ld.h (wildcard_spec): Change exclude_name to exclude_name_list.
(name_list): New.
* ld.texinfo (EXCLUDE_FILE): Update documentation.
* ldgram.y (wildcard_spec): Support a list of excluded_files.
(exclude_name_list): New.
ldlang.c (walk_wild_section): Support list of excluded files.
(print_wild_statement): Likewise.
(lang_add_wild): Likewise.
* ldlang.h (lang_wild_statement_type): Likewise.
* scripttempl/elf.sc (OTHER_EXCLUDE_FILES): Support.
Index: ld.h
===================================================================
RCS file: /cvs/binutils/binutils/ld/ld.h,v
retrieving revision 1.2
diff -p -r1.2 ld.h
*** ld.h 1999/09/12 16:59:49 1.2
--- ld.h 2000/01/04 17:56:53
***************
*** 56,68 ****
discarded. */
#define DISCARD_SECTION_NAME "/DISCARD/"
/* A wildcard specification. This is only used in ldgram.y, but it
winds up in ldgram.h, so we need to define it outside. */
struct wildcard_spec
{
const char *name;
! const char *exclude_name;
boolean sorted;
};
--- 56,75 ----
discarded. */
#define DISCARD_SECTION_NAME "/DISCARD/"
+ /* A file name list */
+ typedef struct name_list
+ {
+ const char *name;
+ struct name_list *next;
+ } name_list;
+
/* A wildcard specification. This is only used in ldgram.y, but it
winds up in ldgram.h, so we need to define it outside. */
struct wildcard_spec
{
const char *name;
! struct name_list *exclude_name_list;
boolean sorted;
};
Index: ld.texinfo
===================================================================
RCS file: /cvs/binutils/binutils/ld/ld.texinfo,v
retrieving revision 1.7
diff -p -r1.7 ld.texinfo
*** ld.texinfo 1999/09/09 16:12:28 1.7
--- ld.texinfo 2000/01/04 17:57:25
*************** include all input @samp{.text} sections,
*** 2235,2247 ****
*(.text)
@end smallexample
@noindent
! Here the @samp{*} is a wildcard which matches any file name. To exclude a file
! from matching the file name wildcard, EXCLUDE_FILE may be used to match all files
! except the one specified by EXCLUDE_FILE. For example:
@smallexample
! (*(EXCLUDE_FILE (*crtend.o) .ctors))
@end smallexample
! will cause all .ctors sections from all files except crtend.o to be included.
There are two ways to include more than one section:
@smallexample
--- 2235,2249 ----
*(.text)
@end smallexample
@noindent
! Here the @samp{*} is a wildcard which matches any file name. To exclude a list
! of files from matching the file name wildcard, EXCLUDE_FILE may be used to
! match all files except the ones specified in the EXCLUDE_FILE list. For
! example:
@smallexample
! (*(EXCLUDE_FILE (*crtend.o, *otherfile.o) .ctors))
@end smallexample
! will cause all .ctors sections from all files except crtend.o and otherfile.o
! to be included.
There are two ways to include more than one section:
@smallexample
Index: ldgram.y
===================================================================
RCS file: /cvs/binutils/binutils/ld/ldgram.y,v
retrieving revision 1.2
diff -p -r1.2 ldgram.y
*** ldgram.y 1999/06/12 21:24:54 1.2
--- ldgram.y 2000/01/04 17:57:31
*************** static int error_index;
*** 70,75 ****
--- 70,76 ----
char *name;
const char *cname;
struct wildcard_spec wildcard;
+ struct name_list *name_list;
int token;
union etree_union *etree;
struct phdr_info
*************** static int error_index;
*** 89,94 ****
--- 90,96 ----
%type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
%type <etree> opt_exp_without_type
%type <integer> fill_opt
+ %type <name_list> exclude_name_list
%type <name> memspec_opt casesymlist
%type <cname> wildcard_name
%type <wildcard> wildcard_spec
*************** wildcard_spec:
*** 392,434 ****
{
$$.name = $1;
$$.sorted = false;
! $$.exclude_name = NULL;
}
! | EXCLUDE_FILE '(' wildcard_name ')' wildcard_name
{
$$.name = $5;
$$.sorted = false;
! $$.exclude_name = $3;
}
| SORT '(' wildcard_name ')'
{
$$.name = $3;
$$.sorted = true;
! $$.exclude_name = NULL;
}
! | SORT '(' EXCLUDE_FILE '(' wildcard_name ')' wildcard_name ')'
{
$$.name = $7;
$$.sorted = true;
! $$.exclude_name = $5;
}
;
file_NAME_list:
wildcard_spec
{
lang_add_wild ($1.name, $1.sorted,
current_file.name,
current_file.sorted,
! ldgram_had_keep, $1.exclude_name);
}
| file_NAME_list opt_comma wildcard_spec
{
lang_add_wild ($3.name, $3.sorted,
current_file.name,
current_file.sorted,
! ldgram_had_keep, $3.exclude_name);
}
;
--- 394,457 ----
{
$$.name = $1;
$$.sorted = false;
! $$.exclude_name_list = NULL;
}
! | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
{
$$.name = $5;
$$.sorted = false;
! $$.exclude_name_list = $3;
}
| SORT '(' wildcard_name ')'
{
$$.name = $3;
$$.sorted = true;
! $$.exclude_name_list = NULL;
}
! | SORT '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
{
$$.name = $7;
$$.sorted = true;
! $$.exclude_name_list = $5;
}
;
+
+ exclude_name_list:
+ exclude_name_list ',' wildcard_name
+ {
+ struct name_list *tmp;
+ tmp = (struct name_list *) xmalloc (sizeof *tmp);
+ tmp->name = $3;
+ tmp->next = $1;
+ $$ = tmp;
+ }
+ |
+ wildcard_name
+ {
+ struct name_list *tmp;
+ tmp = (struct name_list *) xmalloc (sizeof *tmp);
+ tmp->name = $1;
+ tmp->next = NULL;
+ $$ = tmp;
+ }
+ ;
+
file_NAME_list:
wildcard_spec
{
lang_add_wild ($1.name, $1.sorted,
current_file.name,
current_file.sorted,
! ldgram_had_keep, $1.exclude_name_list);
}
| file_NAME_list opt_comma wildcard_spec
{
lang_add_wild ($3.name, $3.sorted,
current_file.name,
current_file.sorted,
! ldgram_had_keep, $3.exclude_name_list);
}
;
Index: ldlang.c
===================================================================
RCS file: /cvs/binutils/binutils/ld/ldlang.c,v
retrieving revision 1.16
diff -p -r1.16 ldlang.c
*** ldlang.c 1999/11/24 11:43:11 1.16
--- ldlang.c 2000/01/04 17:57:47
*************** walk_wild_section (ptr, section, file, c
*** 213,229 ****
void *data;
{
/* Don't process sections from files which were excluded. */
! if (ptr->exclude_filename != NULL)
{
! boolean match;
! if (wildcardp (ptr->exclude_filename))
! match = fnmatch (ptr->exclude_filename, file->filename, 0) == 0 ? true : false;
! else
! match = strcmp (ptr->exclude_filename, file->filename) == 0 ? true : false;
! if (match)
! return;
}
if (file->just_syms_flag == false)
--- 213,233 ----
void *data;
{
/* Don't process sections from files which were excluded. */
! if (ptr->exclude_filename_list != NULL)
{
! struct name_list *list_tmp;
! for (list_tmp = ptr->exclude_filename_list; list_tmp; list_tmp = list_tmp->next)
! {
! boolean match;
! if (wildcardp (list_tmp->name))
! match = fnmatch (list_tmp->name, file->filename, 0) == 0 ? true : false;
! else
! match = strcmp (list_tmp->name, file->filename) == 0 ? true : false;
! if (match)
! return;
! }
}
if (file->just_syms_flag == false)
*************** print_wild_statement (w, os)
*** 2360,2368 ****
if (w->filenames_sorted)
minfo ("SORT(");
! if (w->exclude_filename != NULL)
! minfo ("EXCLUDE_FILE ( %s )", w->exclude_filename);
! if (w->filename != NULL)
minfo ("%s", w->filename);
else
minfo ("*");
--- 2364,2378 ----
if (w->filenames_sorted)
minfo ("SORT(");
! if (w->exclude_filename_list != NULL)
! {
! name_list *tmp;
! minfo ("EXCLUDE_FILE ( %s", w->exclude_filename_list->name);
! for (tmp=w->exclude_filename_list->next; tmp; tmp = tmp->next)
! minfo (", %s", tmp->name);
! minfo (")");
! }
! if (w->filename != NULL)
minfo ("%s", w->filename);
else
minfo ("*");
*************** lang_process ()
*** 4029,4041 ****
void
lang_add_wild (section_name, sections_sorted, filename, filenames_sorted,
! keep_sections, exclude_filename)
const char *const section_name;
boolean sections_sorted;
const char *const filename;
boolean filenames_sorted;
boolean keep_sections;
! const char *exclude_filename;
{
lang_wild_statement_type *new = new_stat (lang_wild_statement,
stat_ptr);
--- 4039,4051 ----
void
lang_add_wild (section_name, sections_sorted, filename, filenames_sorted,
! keep_sections, exclude_filename_list)
const char *const section_name;
boolean sections_sorted;
const char *const filename;
boolean filenames_sorted;
boolean keep_sections;
! struct name_list *exclude_filename_list;
{
lang_wild_statement_type *new = new_stat (lang_wild_statement,
stat_ptr);
*************** lang_add_wild (section_name, sections_so
*** 4053,4059 ****
new->filename = filename;
new->filenames_sorted = filenames_sorted;
new->keep_sections = keep_sections;
! new->exclude_filename = exclude_filename;
lang_list_init (&new->children);
}
--- 4063,4069 ----
new->filename = filename;
new->filenames_sorted = filenames_sorted;
new->keep_sections = keep_sections;
! new->exclude_filename_list = exclude_filename_list;
lang_list_init (&new->children);
}
Index: ldlang.h
===================================================================
RCS file: /cvs/binutils/binutils/ld/ldlang.h,v
retrieving revision 1.2
diff -p -r1.2 ldlang.h
*** ldlang.h 1999/06/12 21:24:56 1.2
--- ldlang.h 2000/01/04 17:57:50
*************** typedef struct lang_wild_statement_struc
*** 283,289 ****
const char *filename;
boolean filenames_sorted;
boolean keep_sections;
! const char *exclude_filename;
lang_statement_list_type children;
} lang_wild_statement_type;
--- 283,289 ----
const char *filename;
boolean filenames_sorted;
boolean keep_sections;
! struct name_list *exclude_filename_list;
lang_statement_list_type children;
} lang_wild_statement_type;
*************** extern void lang_section_start PARAMS ((
*** 401,407 ****
extern void lang_add_entry PARAMS ((const char *, boolean));
extern void lang_add_target PARAMS ((const char *));
extern void lang_add_wild
! PARAMS ((const char *, boolean, const char *, boolean, boolean, const char *));
extern void lang_add_map PARAMS ((const char *));
extern void lang_add_fill PARAMS ((int));
extern lang_assignment_statement_type * lang_add_assignment PARAMS ((union etree_union *));
--- 401,407 ----
extern void lang_add_entry PARAMS ((const char *, boolean));
extern void lang_add_target PARAMS ((const char *));
extern void lang_add_wild
! PARAMS ((const char *, boolean, const char *, boolean, boolean, name_list *));
extern void lang_add_map PARAMS ((const char *));
extern void lang_add_fill PARAMS ((int));
extern lang_assignment_statement_type * lang_add_assignment PARAMS ((union etree_union *));
Index: scripttempl/elf.sc
===================================================================
RCS file: /cvs/binutils/binutils/ld/scripttempl/elf.sc,v
retrieving revision 1.7
diff -p -r1.7 elf.sc
*** elf.sc 1999/10/07 02:19:45 1.7
--- elf.sc 2000/01/04 17:57:52
*************** CTOR=".ctors ${CONSTRUCTING-0} :
*** 67,73 ****
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
! KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
${CONSTRUCTING+${CTOR_END}}
--- 67,73 ----
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
! KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
${CONSTRUCTING+${CTOR_END}}
*************** DTOR=" .dtors ${CONSTRUCTING-0} :
*** 77,83 ****
{
${CONSTRUCTING+${DTOR_START}}
KEEP (*crtbegin.o(.dtors))
! KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
${CONSTRUCTING+${DTOR_END}}
--- 77,83 ----
{
${CONSTRUCTING+${DTOR_START}}
KEEP (*crtbegin.o(.dtors))
! KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
${CONSTRUCTING+${DTOR_END}}