diff options
author | Alan Modra <amodra@gmail.com> | 2009-02-16 07:25:52 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2009-02-16 07:25:52 +0000 |
commit | bde18da45e5dea021d600aadeab702a6f7e31cb2 (patch) | |
tree | e570a5dab586d03eb27b2864e97118cde2f5e9fa /ld/ldlang.c | |
parent | 959b87241d85b42da82c45ecc4bc904895092730 (diff) | |
download | gdb-bde18da45e5dea021d600aadeab702a6f7e31cb2.zip gdb-bde18da45e5dea021d600aadeab702a6f7e31cb2.tar.gz gdb-bde18da45e5dea021d600aadeab702a6f7e31cb2.tar.bz2 |
* ldlang.c (push_stat_ptr, pop_stat_ptr): New functions.
(stat_save, stat_save_ptr): New variables.
(lang_insert_orphan): Use push_stat_ptr and pop_stat_ptr.
(load_symbols): Likewise. Delete dead "bad_load" code.
(open_input_bfds): Warn on script containing output sections.
(lang_enter_output_section_statement): Use push_stat_ptr.
(lang_enter_group): Likewise.
(lang_leave_output_section_statement): Use pop_stat_ptr.
(lang_leave_group): Likewise.
* ldlang.h (push_stat_ptr, pop_stat_ptr): Declare.
* ldctor.c (ldctor_build_sets): Use push_stat_ptr and pop_stat_ptr.
* emultempl/beos.em (gld_${EMULATION_NAME}_set_symbols): Likewise.
* emultempl/pe.em (gld_${EMULATION_NAME}_set_symbols): Likewise.
* emultempl/pep.em (gld_${EMULATION_NAME}_set_symbols): Likewise.
* emultempl/spuelf.em (spu_place_special_section): Likewise.
* emultempl/xtensaelf.em (ld_xtensa_insert_page_offsets): Likewise.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r-- | ld/ldlang.c | 83 |
1 files changed, 53 insertions, 30 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c index 095bb3f..0bd82cb 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -1,6 +1,6 @@ /* Linker command language support. Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 + 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of the GNU Binutils. @@ -64,6 +64,8 @@ static const char *current_target; static const char *output_target; static lang_statement_list_type statement_list; static struct bfd_hash_table lang_definedness_table; +static lang_statement_list_type *stat_save[10]; +static lang_statement_list_type **stat_save_ptr = &stat_save[0]; /* Forward declarations. */ static void exp_init_os (etree_type *); @@ -925,6 +927,23 @@ lang_list_init (lang_statement_list_type *list) list->tail = &list->head; } +void +push_stat_ptr (lang_statement_list_type *new_ptr) +{ + if (stat_save_ptr >= stat_save + sizeof (stat_save) / sizeof (stat_save[0])) + abort (); + *stat_save_ptr++ = stat_ptr; + stat_ptr = new_ptr; +} + +void +pop_stat_ptr (void) +{ + if (stat_save_ptr <= stat_save) + abort (); + stat_ptr = *--stat_save_ptr; +} + /* Build a new statement node for the parse tree. */ static lang_statement_union_type * @@ -1586,23 +1605,18 @@ lang_insert_orphan (asection *s, etree_type *address, lang_statement_list_type *add_child) { - lang_statement_list_type *old; lang_statement_list_type add; const char *ps; lang_output_section_statement_type *os; lang_output_section_statement_type **os_tail; - /* Start building a list of statements for this section. - First save the current statement pointer. */ - old = stat_ptr; - /* If we have found an appropriate place for the output section statements for this orphan, add them to our own private list, inserting them later into the global statement list. */ if (after != NULL) { - stat_ptr = &add; - lang_list_init (stat_ptr); + lang_list_init (&add); + push_stat_ptr (&add); } ps = NULL; @@ -1648,11 +1662,6 @@ lang_insert_orphan (asection *s, { char *symname; - /* lang_leave_ouput_section_statement resets stat_ptr. - Put stat_ptr back where we want it. */ - if (after != NULL) - stat_ptr = &add; - symname = (char *) xmalloc (ps - secname + sizeof "__stop_" + 1); symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); sprintf (symname + (symname[0] != 0), "__stop_%s", secname); @@ -1663,7 +1672,7 @@ lang_insert_orphan (asection *s, /* Restore the global list pointer. */ if (after != NULL) - stat_ptr = old; + pop_stat_ptr (); if (after != NULL && os->bfd_section != NULL) { @@ -1749,8 +1758,8 @@ lang_insert_orphan (asection *s, /* Fix the global list pointer if we happened to tack our new list at the tail. */ - if (*old->tail == add.head) - old->tail = add.tail; + if (*stat_ptr->tail == add.head) + stat_ptr->tail = add.tail; /* Save the end of this list. */ place->stmt = add.tail; @@ -2481,8 +2490,6 @@ load_symbols (lang_input_statement_type *entry, && ! bfd_check_format_matches (entry->the_bfd, bfd_object, &matching)) { bfd_error_type err; - lang_statement_list_type *hold; - bfd_boolean bad_load = TRUE; bfd_boolean save_ldlang_sysrooted_script; bfd_boolean save_as_needed, save_add_needed; @@ -2505,8 +2512,6 @@ load_symbols (lang_input_statement_type *entry, else if (err != bfd_error_file_not_recognized || place == NULL) einfo (_("%F%B: file not recognized: %E\n"), entry->the_bfd); - else - bad_load = FALSE; bfd_close (entry->the_bfd); entry->the_bfd = NULL; @@ -2514,8 +2519,7 @@ load_symbols (lang_input_statement_type *entry, /* Try to interpret the file as a linker script. */ ldfile_open_command_file (entry->filename); - hold = stat_ptr; - stat_ptr = place; + push_stat_ptr (place); save_ldlang_sysrooted_script = ldlang_sysrooted_script; ldlang_sysrooted_script = entry->sysrooted; save_as_needed = as_needed; @@ -2534,9 +2538,9 @@ load_symbols (lang_input_statement_type *entry, ldlang_sysrooted_script = save_ldlang_sysrooted_script; as_needed = save_as_needed; add_needed = save_add_needed; - stat_ptr = hold; + pop_stat_ptr (); - return ! bad_load; + return TRUE; } if (ldemul_recognized_file (entry)) @@ -3008,6 +3012,7 @@ open_input_bfds (lang_statement_union_type *s, bfd_boolean force) case lang_input_statement_enum: if (s->input_statement.real) { + lang_statement_union_type **os_tail; lang_statement_list_type add; s->input_statement.target = current_target; @@ -3023,6 +3028,7 @@ open_input_bfds (lang_statement_union_type *s, bfd_boolean force) bfd_archive)) s->input_statement.loaded = FALSE; + os_tail = lang_output_section_statement.tail; lang_list_init (&add); if (! load_symbols (&s->input_statement, &add)) @@ -3030,8 +3036,25 @@ open_input_bfds (lang_statement_union_type *s, bfd_boolean force) if (add.head != NULL) { - *add.tail = s->header.next; - s->header.next = add.head; + /* If this was a script with output sections then + tack any added statements on to the end of the + list. This avoids having to reorder the output + section statement list. Very likely the user + forgot -T, and whatever we do here will not meet + naive user expectations. */ + if (os_tail != lang_output_section_statement.tail) + { + einfo (_("%P: warning: %s contains output sections;" + " did you forget -T?\n"), + s->input_statement.filename); + *stat_ptr->tail = add.head; + stat_ptr->tail = add.tail; + } + else + { + *add.tail = s->header.next; + s->header.next = add.head; + } } } break; @@ -5860,7 +5883,7 @@ lang_enter_output_section_statement (const char *output_section_statement_name, os->block_value = 1; /* Make next things chain into subchain of this. */ - stat_ptr = &os->children; + push_stat_ptr (&os->children); os->subsection_alignment = topower (exp_get_value_int (subalign, -1, "subsection alignment")); @@ -6468,7 +6491,7 @@ lang_leave_output_section_statement (fill_type *fill, const char *memspec, current_section->addr_tree != NULL); current_section->fill = fill; current_section->phdrs = phdrs; - stat_ptr = &statement_list; + pop_stat_ptr (); } /* Create an absolute symbol with the given name with the value of the @@ -6585,7 +6608,7 @@ lang_enter_group (void) g = new_stat (lang_group_statement, stat_ptr); lang_list_init (&g->children); - stat_ptr = &g->children; + push_stat_ptr (&g->children); } /* Leave a group. This just resets stat_ptr to start writing to the @@ -6596,7 +6619,7 @@ lang_enter_group (void) void lang_leave_group (void) { - stat_ptr = &statement_list; + pop_stat_ptr (); } /* Add a new program header. This is called for each entry in a PHDRS |