52
52
#define obstack_chunk_alloc xmalloc
53
53
#define obstack_chunk_free free
54
54
static const char *startup_file;
55
static const char *entry_symbol_default = "start";
55
56
static bfd_boolean placed_commons = FALSE;
56
57
static bfd_boolean stripped_excluded_sections = FALSE;
57
58
static lang_output_section_statement_type *default_common_section;
59
60
static bfd_vma print_dot;
60
61
static lang_input_statement_type *first_file;
61
62
static const char *current_target;
62
static const char *output_target;
63
63
static lang_statement_list_type statement_list;
64
64
static struct bfd_hash_table lang_definedness_table;
65
65
static lang_statement_list_type *stat_save[10];
86
86
(struct bfd_elf_version_expr_head *);
88
88
/* Exported variables. */
89
const char *output_target;
89
90
lang_output_section_statement_type *abs_output_section;
90
91
lang_statement_list_type lang_output_section_statement;
91
92
lang_statement_list_type *stat_ptr = &statement_list;
92
93
lang_statement_list_type file_chain = { NULL, NULL };
93
94
lang_statement_list_type input_file_chain;
94
95
struct bfd_sym_chain entry_symbol = { NULL, NULL };
95
static const char *entry_symbol_default = "start";
96
96
const char *entry_section = ".text";
97
97
bfd_boolean entry_from_cmdline;
98
98
bfd_boolean lang_has_input_file = FALSE;
950
950
lang_statement_list_type *list)
952
lang_statement_union_type *new;
952
lang_statement_union_type *new_stmt;
954
new = stat_alloc (size);
955
new->header.type = type;
956
new->header.next = NULL;
957
lang_statement_append (list, new, &new->header.next);
954
new_stmt = (lang_statement_union_type *) stat_alloc (size);
955
new_stmt->header.type = type;
956
new_stmt->header.next = NULL;
957
lang_statement_append (list, new_stmt, &new_stmt->header.next);
961
961
/* Build a new input file node for the language. There are several
976
976
lang_input_statement_type *p;
979
p = new_stat (lang_input_statement, stat_ptr);
979
p = (lang_input_statement_type *) new_stat (lang_input_statement, stat_ptr);
982
p = stat_alloc (sizeof (lang_input_statement_type));
982
p = (lang_input_statement_type *)
983
stat_alloc (sizeof (lang_input_statement_type));
983
984
p->header.type = lang_input_statement_enum;
984
985
p->header.next = NULL;
1221
1222
lang_memory_region_name *n;
1222
1223
lang_memory_region_type *r;
1223
lang_memory_region_type *new;
1224
lang_memory_region_type *new_region;
1225
1226
/* NAME is NULL for LMA memspecs if no region was specified. */
1226
1227
if (name == NULL)
1239
1240
if (!create && strcmp (name, DEFAULT_MEMORY_REGION))
1240
1241
einfo (_("%P:%S: warning: memory region `%s' not declared\n"), name);
1242
new = stat_alloc (sizeof (lang_memory_region_type));
1244
new->name_list.name = xstrdup (name);
1245
new->name_list.next = NULL;
1248
new->length = ~(bfd_size_type) 0;
1250
new->last_os = NULL;
1253
new->had_full_message = FALSE;
1255
*lang_memory_region_list_tail = new;
1256
lang_memory_region_list_tail = &new->next;
1243
new_region = (lang_memory_region_type *)
1244
stat_alloc (sizeof (lang_memory_region_type));
1246
new_region->name_list.name = xstrdup (name);
1247
new_region->name_list.next = NULL;
1248
new_region->next = NULL;
1249
new_region->origin = 0;
1250
new_region->length = ~(bfd_size_type) 0;
1251
new_region->current = 0;
1252
new_region->last_os = NULL;
1253
new_region->flags = 0;
1254
new_region->not_flags = 0;
1255
new_region->had_full_message = FALSE;
1257
*lang_memory_region_list_tail = new_region;
1258
lang_memory_region_list_tail = &new_region->next;
2056
2060
if (!link_info.reduce_memory_overheads)
2058
fat_section_userdata_type *new
2059
= stat_alloc (sizeof (fat_section_userdata_type));
2060
memset (new, 0, sizeof (fat_section_userdata_type));
2061
get_userdata (s->bfd_section) = new;
2062
fat_section_userdata_type *new_userdata = (fat_section_userdata_type *)
2063
stat_alloc (sizeof (fat_section_userdata_type));
2064
memset (new_userdata, 0, sizeof (fat_section_userdata_type));
2065
get_userdata (s->bfd_section) = new_userdata;
2064
2068
/* If there is a base address, make sure that any sections it might
2244
2248
/* Add a section reference to the list. */
2245
new = new_stat (lang_input_section, ptr);
2249
new_section = new_stat (lang_input_section, ptr);
2247
new->section = section;
2251
new_section->section = section;
2248
2252
section->output_section = output->bfd_section;
2250
2254
/* If final link, don't copy the SEC_LINK_ONCE flags, they've
3249
3253
ldlang_add_undef (const char *const name)
3251
ldlang_undef_chain_list_type *new =
3252
stat_alloc (sizeof (ldlang_undef_chain_list_type));
3254
new->next = ldlang_undef_chain_list_head;
3255
ldlang_undef_chain_list_head = new;
3257
new->name = xstrdup (name);
3255
ldlang_undef_chain_list_type *new_undef = (ldlang_undef_chain_list_type *)
3256
stat_alloc (sizeof (ldlang_undef_chain_list_type));
3258
new_undef->next = ldlang_undef_chain_list_head;
3259
ldlang_undef_chain_list_head = new_undef;
3261
new_undef->name = xstrdup (name);
3259
3263
if (link_info.output_bfd != NULL)
3260
insert_undefined (new->name);
3264
insert_undefined (new_undef->name);
3263
3267
/* Insert NAME as undefined in the symbol table. */
3957
hash_entry_addr_cmp (const void *a, const void *b)
3959
const struct bfd_link_hash_entry *l = *(const struct bfd_link_hash_entry **)a;
3960
const struct bfd_link_hash_entry *r = *(const struct bfd_link_hash_entry **)b;
3962
if (l->u.def.value < r->u.def.value)
3964
else if (l->u.def.value > r->u.def.value)
3953
3971
print_all_symbols (asection *sec)
3955
3973
struct fat_user_section_struct *ud = get_userdata (sec);
3956
3974
struct map_symbol_def *def;
3975
struct bfd_link_hash_entry **entries;
3961
3981
*ud->map_symbol_def_tail = 0;
3962
for (def = ud->map_symbol_def_head; def; def = def->next)
3963
print_one_symbol (def->entry, sec);
3983
/* Sort the symbols by address. */
3984
entries = obstack_alloc (&map_obstack,
3985
ud->map_symbol_def_count * sizeof (*entries));
3987
for (i = 0, def = ud->map_symbol_def_head; def; def = def->next, i++)
3988
entries[i] = def->entry;
3990
qsort (entries, ud->map_symbol_def_count, sizeof (*entries),
3991
hash_entry_addr_cmp);
3993
/* Print the symbols. */
3994
for (i = 0; i < ud->map_symbol_def_count; i++)
3995
print_one_symbol (entries[i], sec);
3997
obstack_free (&map_obstack, entries);
3966
4000
/* Print information about an input section to the map file. */
5979
6013
lang_final (void)
5981
lang_output_statement_type *new;
5983
new = new_stat (lang_output_statement, stat_ptr);
5984
new->name = output_filename;
6015
lang_output_statement_type *new_stmt;
6017
new_stmt = new_stat (lang_output_statement, stat_ptr);
6018
new_stmt->name = output_filename;
5987
6022
/* Reset the current counters in the regions. */
6160
6195
/* Relax all sections until bfd_relax_section gives up. */
6163
relax_sections (void)
6198
lang_relax_sections (bfd_boolean need_layout)
6165
/* Keep relaxing until bfd_relax_section gives up. */
6166
bfd_boolean relax_again;
6168
link_info.relax_trip = -1;
6171
relax_again = FALSE;
6172
link_info.relax_trip++;
6174
/* Note: pe-dll.c does something like this also. If you find
6175
you need to change this code, you probably need to change
6176
pe-dll.c also. DJ */
6178
/* Do all the assignments with our current guesses as to
6200
if (command_line.relax)
6202
/* We may need more than one relaxation pass. */
6203
int i = link_info.relax_pass;
6205
/* The backend can use it to determine the current pass. */
6206
link_info.relax_pass = 0;
6210
/* Keep relaxing until bfd_relax_section gives up. */
6211
bfd_boolean relax_again;
6213
link_info.relax_trip = -1;
6216
link_info.relax_trip++;
6218
/* Note: pe-dll.c does something like this also. If you find
6219
you need to change this code, you probably need to change
6220
pe-dll.c also. DJ */
6222
/* Do all the assignments with our current guesses as to
6224
lang_do_assignments ();
6226
/* We must do this after lang_do_assignments, because it uses
6228
lang_reset_memory_regions ();
6230
/* Perform another relax pass - this time we know where the
6231
globals are, so can make a better guess. */
6232
relax_again = FALSE;
6233
lang_size_sections (&relax_again, FALSE);
6235
while (relax_again);
6237
link_info.relax_pass++;
6244
/* Final extra sizing to report errors. */
6180
6245
lang_do_assignments ();
6182
/* We must do this after lang_do_assignments, because it uses
6184
6246
lang_reset_memory_regions ();
6186
/* Perform another relax pass - this time we know where the
6187
globals are, so can make a better guess. */
6188
lang_size_sections (&relax_again, FALSE);
6247
lang_size_sections (NULL, TRUE);
6190
while (relax_again);
6293
6351
/* Size up the sections. */
6294
6352
lang_size_sections (NULL, !command_line.relax);
6296
/* Now run around and relax if we can. */
6297
if (command_line.relax)
6299
/* We may need more than one relaxation pass. */
6300
int i = link_info.relax_pass;
6302
/* The backend can use it to determine the current pass. */
6303
link_info.relax_pass = 0;
6308
link_info.relax_pass++;
6311
/* Final extra sizing to report errors. */
6312
lang_do_assignments ();
6313
lang_reset_memory_regions ();
6314
lang_size_sections (NULL, TRUE);
6317
6354
/* See if anything special should be done now we know how big
6355
everything is. This is where relaxation is done. */
6319
6356
ldemul_after_allocation ();
6321
6358
/* Fix any .startof. or .sizeof. symbols. */
6343
6380
bfd_boolean keep_sections)
6345
6382
struct wildcard_list *curr, *next;
6346
lang_wild_statement_type *new;
6383
lang_wild_statement_type *new_stmt;
6348
6385
/* Reverse the list as the parser puts it back to front. */
6349
6386
for (curr = section_list, section_list = NULL;
6365
6402
lang_has_input_file = TRUE;
6368
new = new_stat (lang_wild_statement, stat_ptr);
6369
new->filename = NULL;
6370
new->filenames_sorted = FALSE;
6405
new_stmt = new_stat (lang_wild_statement, stat_ptr);
6406
new_stmt->filename = NULL;
6407
new_stmt->filenames_sorted = FALSE;
6371
6408
if (filespec != NULL)
6373
new->filename = filespec->name;
6374
new->filenames_sorted = filespec->sorted == by_name;
6410
new_stmt->filename = filespec->name;
6411
new_stmt->filenames_sorted = filespec->sorted == by_name;
6376
new->section_list = section_list;
6377
new->keep_sections = keep_sections;
6378
lang_list_init (&new->children);
6379
analyze_walk_wild_section_handler (new);
6413
new_stmt->section_list = section_list;
6414
new_stmt->keep_sections = keep_sections;
6415
lang_list_init (&new_stmt->children);
6416
analyze_walk_wild_section_handler (new_stmt);
6422
6459
lang_add_target (const char *name)
6424
lang_target_statement_type *new;
6461
lang_target_statement_type *new_stmt;
6426
new = new_stat (lang_target_statement, stat_ptr);
6463
new_stmt = new_stat (lang_target_statement, stat_ptr);
6464
new_stmt->target = name;
6446
6483
lang_add_fill (fill_type *fill)
6448
lang_fill_statement_type *new;
6485
lang_fill_statement_type *new_stmt;
6450
new = new_stat (lang_fill_statement, stat_ptr);
6487
new_stmt = new_stat (lang_fill_statement, stat_ptr);
6488
new_stmt->fill = fill;
6455
6492
lang_add_data (int type, union etree_union *exp)
6457
lang_data_statement_type *new;
6494
lang_data_statement_type *new_stmt;
6459
new = new_stat (lang_data_statement, stat_ptr);
6496
new_stmt = new_stat (lang_data_statement, stat_ptr);
6497
new_stmt->exp = exp;
6498
new_stmt->type = type;
6464
6501
/* Create a new reloc statement. RELOC is the BFD relocation type to
6491
6528
lang_assignment_statement_type *
6492
6529
lang_add_assignment (etree_type *exp)
6494
lang_assignment_statement_type *new;
6531
lang_assignment_statement_type *new_stmt;
6496
new = new_stat (lang_assignment_statement, stat_ptr);
6533
new_stmt = new_stat (lang_assignment_statement, stat_ptr);
6534
new_stmt->exp = exp;
6681
6718
lang_add_insert (const char *where, int is_before)
6683
lang_insert_statement_type *new;
6720
lang_insert_statement_type *new_stmt;
6685
new = new_stat (lang_insert_statement, stat_ptr);
6687
new->is_before = is_before;
6722
new_stmt = new_stat (lang_insert_statement, stat_ptr);
6723
new_stmt->where = where;
6724
new_stmt->is_before = is_before;
6688
6725
saved_script_handle = previous_script_handle;
7230
/* This is called for each variable name or match expression. NEW is
7267
/* This is called for each variable name or match expression. NEW_NAME is
7231
7268
the name of the symbol to match, or, if LITERAL_P is FALSE, a glob
7232
7269
pattern to be matched against symbol names. */
7234
7271
struct bfd_elf_version_expr *
7235
7272
lang_new_vers_pattern (struct bfd_elf_version_expr *orig,
7273
const char *new_name,
7237
7274
const char *lang,
7238
7275
bfd_boolean literal_p)
7240
7277
struct bfd_elf_version_expr *ret;
7242
ret = xmalloc (sizeof *ret);
7279
ret = (struct bfd_elf_version_expr *) xmalloc (sizeof *ret);
7243
7280
ret->next = orig;
7244
7281
ret->symver = 0;
7245
7282
ret->script = 0;
7246
7283
ret->literal = TRUE;
7247
ret->pattern = literal_p ? new : realsymbol (new);
7284
ret->pattern = literal_p ? new_name : realsymbol (new_name);
7248
7285
if (ret->pattern == NULL)
7287
ret->pattern = new_name;
7251
7288
ret->literal = FALSE;