yann@402: Signed-off-by: dank@kegel.com yann@402: Fixes ld speed issue. yann@402: See http://weblogs.mozillazine.org/roc/archives/2005/02/optimizing_gnu.html yann@402: See thread "Re: optimizations for 3x speedup in ld", yann@402: http://sources.redhat.com/ml/binutils/2005-03/msg00847.html yann@402: yann@402: Wildcard section matching enhancement, backported from the binutils CVS tree. yann@402: Here's the CVS log comment from the original change to ldlang.c: yann@402: yann@402: revision 1.177 yann@402: date: 2005/04/06 15:33:02; author: jakub; state: Exp; lines: +438 -51 yann@402: 2005-04-06 Jakub Jelinek yann@402: yann@402: * ldlang.c: Formatting. yann@402: (walk_wild_consider_section): Remember return value from wildcardp. yann@402: (is_simple_wild): Use strcspn instead of 2 strpbrk calls and strlen. yann@402: (wild_spec_can_overlap): Use strcspn instead of strpbrk and strlen. yann@402: yann@402: 2005-04-06 Robert O'Callahan yann@402: yann@402: * ld.h (lean_section_userdata_type): Remove. yann@402: (fat_section_userdata_type): Remove file field. yann@402: (SECTION_USERDATA_SIZE): Remove. yann@402: * ldlang.c (init_os): Eliminate initialization of unused yann@402: lean_section_userdata_type. yann@402: yann@402: * ldlang.h (callback_t, walk_wild_section_handler_t): New yann@402: typedefs. yann@402: (struct lang_wild_statement_struct): Add walk_wild_section_handler yann@402: and handler_data fields. yann@402: * ldlang.c (callback_t): Removed. yann@402: (walk_wild_consider_section, walk_wild_section_general, yann@402: section_iterator_callback, find_section, is_simple_wild, yann@402: match_simple_wild, walk_wild_section_specs1_wild0, yann@402: walk_wild_section_specs1_wild1, walk_wild_section_specs2_wild1, yann@402: walk_wild_section_specs3_wild2, walk_wild_section_specs4_wild2, yann@402: wild_spec_can_overlap, analyze_walk_wild_section_handler): New yann@402: functions. yann@402: (lang_add_wild): Call analyze_walk_wild_section_handler. yann@402: (walk_wild_section): Renamed to walk_wild_section_general and yann@402: created a wrapper function. yann@402: (section_iterator_callback_data): New typedef. yann@402: yann@402: yann@402: Index: src/ld/ld.h yann@402: =================================================================== yann@402: RCS file: /cvs/src/src/ld/ld.h,v yann@402: retrieving revision 1.26 yann@402: retrieving revision 1.27 yann@402: diff -u -r1.26 -r1.27 yann@402: --- binutils/ld/ld.h.old 16 Mar 2005 21:52:42 -0000 1.26 yann@402: +++ binutils/ld/ld.h 6 Apr 2005 15:33:02 -0000 1.27 yann@402: @@ -1,6 +1,6 @@ yann@402: /* ld.h -- general linker header file yann@402: Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, yann@402: - 2001, 2002, 2003, 2004 yann@402: + 2001, 2002, 2003, 2004, 2005 yann@402: Free Software Foundation, Inc. yann@402: yann@402: This file is part of GLD, the Gnu Linker. yann@402: @@ -89,28 +89,15 @@ yann@402: struct map_symbol_def *next; yann@402: }; yann@402: yann@402: -/* Extra information we hold on sections */ yann@402: -typedef struct lean_user_section_struct { yann@402: - /* For output sections: pointer to the section where this data will go. */ yann@402: - struct lang_input_statement_struct *file; yann@402: -} lean_section_userdata_type; yann@402: - yann@402: /* The initial part of fat_user_section_struct has to be idential with yann@402: lean_user_section_struct. */ yann@402: typedef struct fat_user_section_struct { yann@402: - /* For output sections: pointer to the section where this data will go. */ yann@402: - struct lang_input_statement_struct *file; yann@402: /* For input sections, when writing a map file: head / tail of a linked yann@402: list of hash table entries for symbols defined in this section. */ yann@402: struct map_symbol_def *map_symbol_def_head; yann@402: struct map_symbol_def **map_symbol_def_tail; yann@402: } fat_section_userdata_type; yann@402: yann@402: -#define SECTION_USERDATA_SIZE \ yann@402: - (command_line.reduce_memory_overheads \ yann@402: - ? sizeof (lean_section_userdata_type) \ yann@402: - : sizeof (fat_section_userdata_type)) yann@402: - yann@402: #define get_userdata(x) ((x)->userdata) yann@402: yann@402: #define BYTE_SIZE (1) yann@402: Index: src/ld/ldlang.c yann@402: =================================================================== yann@402: RCS file: /cvs/src/src/ld/ldlang.c,v yann@402: retrieving revision 1.176 yann@402: retrieving revision 1.177 yann@402: diff -u -r1.176 -r1.177 yann@402: --- binutils/ld/ldlang.c.old 18 Mar 2005 13:56:26 -0000 1.176 yann@402: +++ binutils/ld/ldlang.c 6 Apr 2005 15:33:02 -0000 1.177 yann@402: @@ -84,9 +84,6 @@ yann@402: static void lang_record_phdrs (void); yann@402: static void lang_do_version_exports_section (void); yann@402: yann@402: -typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *, yann@402: - asection *, lang_input_statement_type *, void *); yann@402: - yann@402: /* Exported variables. */ yann@402: lang_output_section_statement_type *abs_output_section; yann@402: lang_statement_list_type lang_output_section_statement; yann@402: @@ -155,21 +152,71 @@ yann@402: yann@402: /* Generic traversal routines for finding matching sections. */ yann@402: yann@402: +/* Try processing a section against a wildcard. This just calls yann@402: + the callback unless the filename exclusion list is present yann@402: + and excludes the file. It's hardly ever present so this yann@402: + function is very fast. */ yann@402: + yann@402: +static void yann@402: +walk_wild_consider_section (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + asection *s, yann@402: + struct wildcard_list *sec, yann@402: + callback_t callback, yann@402: + void *data) yann@402: +{ yann@402: + bfd_boolean skip = FALSE; yann@402: + struct name_list *list_tmp; yann@402: + yann@402: + /* Don't process sections from files which were yann@402: + excluded. */ yann@402: + for (list_tmp = sec->spec.exclude_name_list; yann@402: + list_tmp; yann@402: + list_tmp = list_tmp->next) yann@402: + { yann@402: + bfd_boolean is_wildcard = wildcardp (list_tmp->name); yann@402: + if (is_wildcard) yann@402: + skip = fnmatch (list_tmp->name, file->filename, 0) == 0; yann@402: + else yann@402: + skip = strcmp (list_tmp->name, file->filename) == 0; yann@402: + yann@402: + /* If this file is part of an archive, and the archive is yann@402: + excluded, exclude this file. */ yann@402: + if (! skip && file->the_bfd != NULL yann@402: + && file->the_bfd->my_archive != NULL yann@402: + && file->the_bfd->my_archive->filename != NULL) yann@402: + { yann@402: + if (is_wildcard) yann@402: + skip = fnmatch (list_tmp->name, yann@402: + file->the_bfd->my_archive->filename, yann@402: + 0) == 0; yann@402: + else yann@402: + skip = strcmp (list_tmp->name, yann@402: + file->the_bfd->my_archive->filename) == 0; yann@402: + } yann@402: + yann@402: + if (skip) yann@402: + break; yann@402: + } yann@402: + yann@402: + if (!skip) yann@402: + (*callback) (ptr, sec, s, file, data); yann@402: +} yann@402: + yann@402: +/* Lowest common denominator routine that can handle everything correctly, yann@402: + but slowly. */ yann@402: + yann@402: static void yann@402: -walk_wild_section (lang_wild_statement_type *ptr, yann@402: - lang_input_statement_type *file, yann@402: - callback_t callback, yann@402: - void *data) yann@402: +walk_wild_section_general (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + callback_t callback, yann@402: + void *data) yann@402: { yann@402: asection *s; yann@402: - yann@402: - if (file->just_syms_flag) yann@402: - return; yann@402: + struct wildcard_list *sec; yann@402: yann@402: for (s = file->the_bfd->sections; s != NULL; s = s->next) yann@402: { yann@402: - struct wildcard_list *sec; yann@402: - yann@402: sec = ptr->section_list; yann@402: if (sec == NULL) yann@402: (*callback) (ptr, sec, s, file, data); yann@402: @@ -177,39 +224,8 @@ yann@402: while (sec != NULL) yann@402: { yann@402: bfd_boolean skip = FALSE; yann@402: - struct name_list *list_tmp; yann@402: yann@402: - /* Don't process sections from files which were yann@402: - excluded. */ yann@402: - for (list_tmp = sec->spec.exclude_name_list; yann@402: - list_tmp; yann@402: - list_tmp = list_tmp->next) yann@402: - { yann@402: - if (wildcardp (list_tmp->name)) yann@402: - skip = fnmatch (list_tmp->name, file->filename, 0) == 0; yann@402: - else yann@402: - skip = strcmp (list_tmp->name, file->filename) == 0; yann@402: - yann@402: - /* If this file is part of an archive, and the archive is yann@402: - excluded, exclude this file. */ yann@402: - if (! skip && file->the_bfd != NULL yann@402: - && file->the_bfd->my_archive != NULL yann@402: - && file->the_bfd->my_archive->filename != NULL) yann@402: - { yann@402: - if (wildcardp (list_tmp->name)) yann@402: - skip = fnmatch (list_tmp->name, yann@402: - file->the_bfd->my_archive->filename, yann@402: - 0) == 0; yann@402: - else yann@402: - skip = strcmp (list_tmp->name, yann@402: - file->the_bfd->my_archive->filename) == 0; yann@402: - } yann@402: - yann@402: - if (skip) yann@402: - break; yann@402: - } yann@402: - yann@402: - if (!skip && sec->spec.name != NULL) yann@402: + if (sec->spec.name != NULL) yann@402: { yann@402: const char *sname = bfd_get_section_name (file->the_bfd, s); yann@402: yann@402: @@ -220,13 +236,381 @@ yann@402: } yann@402: yann@402: if (!skip) yann@402: - (*callback) (ptr, sec, s, file, data); yann@402: + walk_wild_consider_section (ptr, file, s, sec, callback, data); yann@402: yann@402: sec = sec->next; yann@402: } yann@402: } yann@402: } yann@402: yann@402: +/* Routines to find a single section given its name. If there's more yann@402: + than one section with that name, we report that. */ yann@402: + yann@402: +typedef struct yann@402: +{ yann@402: + asection *found_section; yann@402: + bfd_boolean multiple_sections_found; yann@402: +} section_iterator_callback_data; yann@402: + yann@402: +static bfd_boolean yann@402: +section_iterator_callback (bfd *bfd ATTRIBUTE_UNUSED, asection *s, void *data) yann@402: +{ yann@402: + section_iterator_callback_data *d = data; yann@402: + yann@402: + if (d->found_section != NULL) yann@402: + { yann@402: + d->multiple_sections_found = TRUE; yann@402: + return TRUE; yann@402: + } yann@402: + yann@402: + d->found_section = s; yann@402: + return FALSE; yann@402: +} yann@402: + yann@402: +static asection * yann@402: +find_section (lang_input_statement_type *file, yann@402: + struct wildcard_list *sec, yann@402: + bfd_boolean *multiple_sections_found) yann@402: +{ yann@402: + section_iterator_callback_data cb_data = { NULL, FALSE }; yann@402: + yann@402: + bfd_get_section_by_name_if (file->the_bfd, sec->spec.name, yann@402: + section_iterator_callback, &cb_data); yann@402: + *multiple_sections_found = cb_data.multiple_sections_found; yann@402: + return cb_data.found_section; yann@402: +} yann@402: + yann@402: +/* Code for handling simple wildcards without going through fnmatch, yann@402: + which can be expensive because of charset translations etc. */ yann@402: + yann@402: +/* A simple wild is a literal string followed by a single '*', yann@402: + where the literal part is at least 4 characters long. */ yann@402: + yann@402: +static bfd_boolean yann@402: +is_simple_wild (const char *name) yann@402: +{ yann@402: + size_t len = strcspn (name, "*?["); yann@402: + return len >= 4 && name[len] == '*' && name[len + 1] == '\0'; yann@402: +} yann@402: + yann@402: +static bfd_boolean yann@402: +match_simple_wild (const char *pattern, const char *name) yann@402: +{ yann@402: + /* The first four characters of the pattern are guaranteed valid yann@402: + non-wildcard characters. So we can go faster. */ yann@402: + if (pattern[0] != name[0] || pattern[1] != name[1] yann@402: + || pattern[2] != name[2] || pattern[3] != name[3]) yann@402: + return FALSE; yann@402: + yann@402: + pattern += 4; yann@402: + name += 4; yann@402: + while (*pattern != '*') yann@402: + if (*name++ != *pattern++) yann@402: + return FALSE; yann@402: + yann@402: + return TRUE; yann@402: +} yann@402: + yann@402: +/* Specialized, optimized routines for handling different kinds of yann@402: + wildcards */ yann@402: + yann@402: +static void yann@402: +walk_wild_section_specs1_wild0 (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + callback_t callback, yann@402: + void *data) yann@402: +{ yann@402: + /* We can just do a hash lookup for the section with the right name. yann@402: + But if that lookup discovers more than one section with the name yann@402: + (should be rare), we fall back to the general algorithm because yann@402: + we would otherwise have to sort the sections to make sure they yann@402: + get processed in the bfd's order. */ yann@402: + bfd_boolean multiple_sections_found; yann@402: + struct wildcard_list *sec0 = ptr->handler_data[0]; yann@402: + asection *s0 = find_section (file, sec0, &multiple_sections_found); yann@402: + yann@402: + if (multiple_sections_found) yann@402: + walk_wild_section_general (ptr, file, callback, data); yann@402: + else if (s0) yann@402: + walk_wild_consider_section (ptr, file, s0, sec0, callback, data); yann@402: +} yann@402: + yann@402: +static void yann@402: +walk_wild_section_specs1_wild1 (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + callback_t callback, yann@402: + void *data) yann@402: +{ yann@402: + asection *s; yann@402: + struct wildcard_list *wildsec0 = ptr->handler_data[0]; yann@402: + yann@402: + for (s = file->the_bfd->sections; s != NULL; s = s->next) yann@402: + { yann@402: + const char *sname = bfd_get_section_name (file->the_bfd, s); yann@402: + bfd_boolean skip = !match_simple_wild (wildsec0->spec.name, sname); yann@402: + yann@402: + if (!skip) yann@402: + walk_wild_consider_section (ptr, file, s, wildsec0, callback, data); yann@402: + } yann@402: +} yann@402: + yann@402: +static void yann@402: +walk_wild_section_specs2_wild1 (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + callback_t callback, yann@402: + void *data) yann@402: +{ yann@402: + asection *s; yann@402: + struct wildcard_list *sec0 = ptr->handler_data[0]; yann@402: + struct wildcard_list *wildsec1 = ptr->handler_data[1]; yann@402: + bfd_boolean multiple_sections_found; yann@402: + asection *s0 = find_section (file, sec0, &multiple_sections_found); yann@402: + yann@402: + if (multiple_sections_found) yann@402: + { yann@402: + walk_wild_section_general (ptr, file, callback, data); yann@402: + return; yann@402: + } yann@402: + yann@402: + /* Note that if the section was not found, s0 is NULL and yann@402: + we'll simply never succeed the s == s0 test below. */ yann@402: + for (s = file->the_bfd->sections; s != NULL; s = s->next) yann@402: + { yann@402: + /* Recall that in this code path, a section cannot satisfy more yann@402: + than one spec, so if s == s0 then it cannot match yann@402: + wildspec1. */ yann@402: + if (s == s0) yann@402: + walk_wild_consider_section (ptr, file, s, sec0, callback, data); yann@402: + else yann@402: + { yann@402: + const char *sname = bfd_get_section_name (file->the_bfd, s); yann@402: + bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname); yann@402: + yann@402: + if (!skip) yann@402: + walk_wild_consider_section (ptr, file, s, wildsec1, callback, yann@402: + data); yann@402: + } yann@402: + } yann@402: +} yann@402: + yann@402: +static void yann@402: +walk_wild_section_specs3_wild2 (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + callback_t callback, yann@402: + void *data) yann@402: +{ yann@402: + asection *s; yann@402: + struct wildcard_list *sec0 = ptr->handler_data[0]; yann@402: + struct wildcard_list *wildsec1 = ptr->handler_data[1]; yann@402: + struct wildcard_list *wildsec2 = ptr->handler_data[2]; yann@402: + bfd_boolean multiple_sections_found; yann@402: + asection *s0 = find_section (file, sec0, &multiple_sections_found); yann@402: + yann@402: + if (multiple_sections_found) yann@402: + { yann@402: + walk_wild_section_general (ptr, file, callback, data); yann@402: + return; yann@402: + } yann@402: + yann@402: + for (s = file->the_bfd->sections; s != NULL; s = s->next) yann@402: + { yann@402: + if (s == s0) yann@402: + walk_wild_consider_section (ptr, file, s, sec0, callback, data); yann@402: + else yann@402: + { yann@402: + const char *sname = bfd_get_section_name (file->the_bfd, s); yann@402: + bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname); yann@402: + yann@402: + if (!skip) yann@402: + walk_wild_consider_section (ptr, file, s, wildsec1, callback, data); yann@402: + else yann@402: + { yann@402: + skip = !match_simple_wild (wildsec2->spec.name, sname); yann@402: + if (!skip) yann@402: + walk_wild_consider_section (ptr, file, s, wildsec2, callback, yann@402: + data); yann@402: + } yann@402: + } yann@402: + } yann@402: +} yann@402: + yann@402: +static void yann@402: +walk_wild_section_specs4_wild2 (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + callback_t callback, yann@402: + void *data) yann@402: +{ yann@402: + asection *s; yann@402: + struct wildcard_list *sec0 = ptr->handler_data[0]; yann@402: + struct wildcard_list *sec1 = ptr->handler_data[1]; yann@402: + struct wildcard_list *wildsec2 = ptr->handler_data[2]; yann@402: + struct wildcard_list *wildsec3 = ptr->handler_data[3]; yann@402: + bfd_boolean multiple_sections_found; yann@402: + asection *s0 = find_section (file, sec0, &multiple_sections_found), *s1; yann@402: + yann@402: + if (multiple_sections_found) yann@402: + { yann@402: + walk_wild_section_general (ptr, file, callback, data); yann@402: + return; yann@402: + } yann@402: + yann@402: + s1 = find_section (file, sec1, &multiple_sections_found); yann@402: + if (multiple_sections_found) yann@402: + { yann@402: + walk_wild_section_general (ptr, file, callback, data); yann@402: + return; yann@402: + } yann@402: + yann@402: + for (s = file->the_bfd->sections; s != NULL; s = s->next) yann@402: + { yann@402: + if (s == s0) yann@402: + walk_wild_consider_section (ptr, file, s, sec0, callback, data); yann@402: + else yann@402: + if (s == s1) yann@402: + walk_wild_consider_section (ptr, file, s, sec1, callback, data); yann@402: + else yann@402: + { yann@402: + const char *sname = bfd_get_section_name (file->the_bfd, s); yann@402: + bfd_boolean skip = !match_simple_wild (wildsec2->spec.name, yann@402: + sname); yann@402: + yann@402: + if (!skip) yann@402: + walk_wild_consider_section (ptr, file, s, wildsec2, callback, yann@402: + data); yann@402: + else yann@402: + { yann@402: + skip = !match_simple_wild (wildsec3->spec.name, sname); yann@402: + if (!skip) yann@402: + walk_wild_consider_section (ptr, file, s, wildsec3, yann@402: + callback, data); yann@402: + } yann@402: + } yann@402: + } yann@402: +} yann@402: + yann@402: +static void yann@402: +walk_wild_section (lang_wild_statement_type *ptr, yann@402: + lang_input_statement_type *file, yann@402: + callback_t callback, yann@402: + void *data) yann@402: +{ yann@402: + if (file->just_syms_flag) yann@402: + return; yann@402: + yann@402: + (*ptr->walk_wild_section_handler) (ptr, file, callback, data); yann@402: +} yann@402: + yann@402: +/* Returns TRUE when name1 is a wildcard spec that might match yann@402: + something name2 can match. We're conservative: we return FALSE yann@402: + only if the prefixes of name1 and name2 are different up to the yann@402: + first wildcard character. */ yann@402: + yann@402: +static bfd_boolean yann@402: +wild_spec_can_overlap (const char *name1, const char *name2) yann@402: +{ yann@402: + size_t prefix1_len = strcspn (name1, "?*["); yann@402: + size_t prefix2_len = strcspn (name2, "?*["); yann@402: + size_t min_prefix_len; yann@402: + yann@402: + /* Note that if there is no wildcard character, then we treat the yann@402: + terminating 0 as part of the prefix. Thus ".text" won't match yann@402: + ".text." or ".text.*", for example. */ yann@402: + if (name1[prefix1_len] == '\0') yann@402: + prefix1_len++; yann@402: + if (name2[prefix2_len] == '\0') yann@402: + prefix2_len++; yann@402: + yann@402: + min_prefix_len = prefix1_len < prefix2_len ? prefix1_len : prefix2_len; yann@402: + yann@402: + return memcmp (name1, name2, min_prefix_len) == 0; yann@402: +} yann@402: + yann@402: +/* Select specialized code to handle various kinds of wildcard yann@402: + statements. */ yann@402: + yann@402: +static void yann@402: +analyze_walk_wild_section_handler (lang_wild_statement_type *ptr) yann@402: +{ yann@402: + int sec_count = 0; yann@402: + int wild_name_count = 0; yann@402: + struct wildcard_list *sec; yann@402: + int signature; yann@402: + int data_counter; yann@402: + yann@402: + ptr->walk_wild_section_handler = walk_wild_section_general; yann@402: + yann@402: + /* Count how many wildcard_specs there are, and how many of those yann@402: + actually use wildcards in the name. Also, bail out if any of the yann@402: + wildcard names are NULL. (Can this actually happen? yann@402: + walk_wild_section used to test for it.) And bail out if any yann@402: + of the wildcards are more complex than a simple string yann@402: + ending in a single '*'. */ yann@402: + for (sec = ptr->section_list; sec != NULL; sec = sec->next) yann@402: + { yann@402: + ++sec_count; yann@402: + if (sec->spec.name == NULL) yann@402: + return; yann@402: + if (wildcardp (sec->spec.name)) yann@402: + { yann@402: + ++wild_name_count; yann@402: + if (!is_simple_wild (sec->spec.name)) yann@402: + return; yann@402: + } yann@402: + } yann@402: + yann@402: + /* The zero-spec case would be easy to optimize but it doesn't yann@402: + happen in practice. Likewise, more than 4 specs doesn't yann@402: + happen in practice. */ yann@402: + if (sec_count == 0 || sec_count > 4) yann@402: + return; yann@402: + yann@402: + /* Check that no two specs can match the same section. */ yann@402: + for (sec = ptr->section_list; sec != NULL; sec = sec->next) yann@402: + { yann@402: + struct wildcard_list *sec2; yann@402: + for (sec2 = sec->next; sec2 != NULL; sec2 = sec2->next) yann@402: + { yann@402: + if (wild_spec_can_overlap (sec->spec.name, sec2->spec.name)) yann@402: + return; yann@402: + } yann@402: + } yann@402: + yann@402: + signature = (sec_count << 8) + wild_name_count; yann@402: + switch (signature) yann@402: + { yann@402: + case 0x0100: yann@402: + ptr->walk_wild_section_handler = walk_wild_section_specs1_wild0; yann@402: + break; yann@402: + case 0x0101: yann@402: + ptr->walk_wild_section_handler = walk_wild_section_specs1_wild1; yann@402: + break; yann@402: + case 0x0201: yann@402: + ptr->walk_wild_section_handler = walk_wild_section_specs2_wild1; yann@402: + break; yann@402: + case 0x0302: yann@402: + ptr->walk_wild_section_handler = walk_wild_section_specs3_wild2; yann@402: + break; yann@402: + case 0x0402: yann@402: + ptr->walk_wild_section_handler = walk_wild_section_specs4_wild2; yann@402: + break; yann@402: + default: yann@402: + return; yann@402: + } yann@402: + yann@402: + /* Now fill the data array with pointers to the specs, first the yann@402: + specs with non-wildcard names, then the specs with wildcard yann@402: + names. It's OK to process the specs in different order from the yann@402: + given order, because we've already determined that no section yann@402: + will match more than one spec. */ yann@402: + data_counter = 0; yann@402: + for (sec = ptr->section_list; sec != NULL; sec = sec->next) yann@402: + if (!wildcardp (sec->spec.name)) yann@402: + ptr->handler_data[data_counter++] = sec; yann@402: + for (sec = ptr->section_list; sec != NULL; sec = sec->next) yann@402: + if (wildcardp (sec->spec.name)) yann@402: + ptr->handler_data[data_counter++] = sec; yann@402: +} yann@402: + yann@402: /* Handle a wild statement for a single file F. */ yann@402: yann@402: static void yann@402: @@ -1175,17 +1559,12 @@ yann@402: static void yann@402: init_os (lang_output_section_statement_type *s) yann@402: { yann@402: - lean_section_userdata_type *new; yann@402: - yann@402: if (s->bfd_section != NULL) yann@402: return; yann@402: yann@402: if (strcmp (s->name, DISCARD_SECTION_NAME) == 0) yann@402: einfo (_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME); yann@402: yann@402: - new = stat_alloc (SECTION_USERDATA_SIZE); yann@402: - memset (new, 0, SECTION_USERDATA_SIZE); yann@402: - yann@402: s->bfd_section = bfd_get_section_by_name (output_bfd, s->name); yann@402: if (s->bfd_section == NULL) yann@402: s->bfd_section = bfd_make_section (output_bfd, s->name); yann@402: @@ -1199,7 +1578,14 @@ yann@402: /* We initialize an output sections output offset to minus its own yann@402: vma to allow us to output a section through itself. */ yann@402: s->bfd_section->output_offset = 0; yann@402: - get_userdata (s->bfd_section) = new; yann@402: + if (!command_line.reduce_memory_overheads) yann@402: + { yann@402: + fat_section_userdata_type *new yann@402: + = stat_alloc (sizeof (fat_section_userdata_type)); yann@402: + memset (new, 0, sizeof (fat_section_userdata_type)); yann@402: + get_userdata (s->bfd_section) = new; yann@402: + } yann@402: + yann@402: yann@402: /* If there is a base address, make sure that any sections it might yann@402: mention are initialized. */ yann@402: @@ -4939,6 +5325,7 @@ yann@402: new->section_list = section_list; yann@402: new->keep_sections = keep_sections; yann@402: lang_list_init (&new->children); yann@402: + analyze_walk_wild_section_handler (new); yann@402: } yann@402: yann@402: void yann@402: Index: src/ld/ldlang.h yann@402: =================================================================== yann@402: RCS file: /cvs/src/src/ld/ldlang.h,v yann@402: retrieving revision 1.44 yann@402: retrieving revision 1.45 yann@402: diff -u -r1.44 -r1.45 yann@402: --- binutils/ld/ldlang.h.old 3 Mar 2005 11:51:58 -0000 1.44 yann@402: +++ binutils/ld/ldlang.h 6 Apr 2005 15:33:03 -0000 1.45 yann@402: @@ -298,7 +298,17 @@ yann@402: union lang_statement_union *file; yann@402: } lang_afile_asection_pair_statement_type; yann@402: yann@402: -typedef struct lang_wild_statement_struct yann@402: +typedef struct lang_wild_statement_struct lang_wild_statement_type; yann@402: + yann@402: +typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *, yann@402: + asection *, lang_input_statement_type *, void *); yann@402: + yann@402: +typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *, yann@402: + lang_input_statement_type *, yann@402: + callback_t callback, yann@402: + void *data); yann@402: + yann@402: +struct lang_wild_statement_struct yann@402: { yann@402: lang_statement_header_type header; yann@402: const char *filename; yann@402: @@ -306,7 +316,10 @@ yann@402: struct wildcard_list *section_list; yann@402: bfd_boolean keep_sections; yann@402: lang_statement_list_type children; yann@402: -} lang_wild_statement_type; yann@402: + yann@402: + walk_wild_section_handler_t walk_wild_section_handler; yann@402: + struct wildcard_list *handler_data[4]; yann@402: +}; yann@402: yann@402: typedef struct lang_address_statement_struct yann@402: {