/* 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.
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+#include <limits.h>
+
#include "sysdep.h"
#include "bfd.h"
#include "libiberty.h"
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 *);
return obstack_alloc (&stat_obstack, size);
}
-bfd_boolean
+static int
+name_match (const char *pattern, const char *name)
+{
+ if (wildcardp (pattern))
+ return fnmatch (pattern, name, 0);
+ return strcmp (pattern, name);
+}
+
+/* If PATTERN is of the form archive:file, return a pointer to the
+ separator. If not, return NULL. */
+
+static char *
+archive_path (const char *pattern)
+{
+ char *p = NULL;
+
+ if (link_info.path_separator == 0)
+ return p;
+
+ p = strchr (pattern, link_info.path_separator);
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ if (p == NULL || link_info.path_separator != ':')
+ return p;
+
+ /* Assume a match on the second char is part of drive specifier,
+ as in "c:\silly.dos". */
+ if (p == pattern + 1 && ISALPHA (*pattern))
+ p = strchr (p + 1, link_info.path_separator);
+#endif
+ return p;
+}
+
+/* Given that FILE_SPEC results in a non-NULL SEP result from archive_path,
+ return whether F matches FILE_SPEC. */
+
+static bfd_boolean
+input_statement_is_archive_path (const char *file_spec, char *sep,
+ lang_input_statement_type *f)
+{
+ bfd_boolean match = FALSE;
+
+ if ((*(sep + 1) == 0
+ || name_match (sep + 1, f->filename) == 0)
+ && ((sep != file_spec)
+ == (f->the_bfd != NULL && f->the_bfd->my_archive != NULL)))
+ {
+ match = TRUE;
+
+ if (sep != file_spec)
+ {
+ const char *aname = f->the_bfd->my_archive->filename;
+ *sep = 0;
+ match = name_match (file_spec, aname) == 0;
+ *sep = link_info.path_separator;
+ }
+ }
+ return match;
+}
+
+static bfd_boolean
unique_section_p (const asection *sec)
{
struct unique_sections *unam;
secnam = sec->name;
for (unam = unique_section_list; unam; unam = unam->next)
- if (wildcardp (unam->name)
- ? fnmatch (unam->name, secnam, 0) == 0
- : strcmp (unam->name, secnam) == 0)
- {
- return TRUE;
- }
+ if (name_match (unam->name, secnam) == 0)
+ return TRUE;
return FALSE;
}
callback_t callback,
void *data)
{
- bfd_boolean skip = FALSE;
struct name_list *list_tmp;
- /* Don't process sections from files which were
- excluded. */
+ /* Don't process sections from files which were excluded. */
for (list_tmp = sec->spec.exclude_name_list;
list_tmp;
list_tmp = list_tmp->next)
{
- bfd_boolean is_wildcard = wildcardp (list_tmp->name);
- if (is_wildcard)
- skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
- else
- skip = strcmp (list_tmp->name, file->filename) == 0;
+ char *p = archive_path (list_tmp->name);
- /* If this file is part of an archive, and the archive is
- excluded, exclude this file. */
- if (! skip && file->the_bfd != NULL
- && file->the_bfd->my_archive != NULL
- && file->the_bfd->my_archive->filename != NULL)
+ if (p != NULL)
{
- if (is_wildcard)
- skip = fnmatch (list_tmp->name,
- file->the_bfd->my_archive->filename,
- 0) == 0;
- else
- skip = strcmp (list_tmp->name,
- file->the_bfd->my_archive->filename) == 0;
+ if (input_statement_is_archive_path (list_tmp->name, p, file))
+ return;
}
- if (skip)
- break;
+ else if (name_match (list_tmp->name, file->filename) == 0)
+ return;
+
+ /* FIXME: Perhaps remove the following at some stage? Matching
+ unadorned archives like this was never documented and has
+ been superceded by the archive:path syntax. */
+ else if (file->the_bfd != NULL
+ && file->the_bfd->my_archive != NULL
+ && name_match (list_tmp->name,
+ file->the_bfd->my_archive->filename) == 0)
+ return;
}
- if (!skip)
- (*callback) (ptr, sec, s, file, data);
+ (*callback) (ptr, sec, s, file, data);
}
/* Lowest common denominator routine that can handle everything correctly,
{
const char *sname = bfd_get_section_name (file->the_bfd, s);
- if (wildcardp (sec->spec.name))
- skip = fnmatch (sec->spec.name, sname, 0) != 0;
- else
- skip = strcmp (sec->spec.name, sname) != 0;
+ skip = name_match (sec->spec.name, sname) != 0;
}
if (!skip)
walk_wild (lang_wild_statement_type *s, callback_t callback, void *data)
{
const char *file_spec = s->filename;
+ char *p;
if (file_spec == NULL)
{
walk_wild_file (s, f, callback, data);
}
}
+ else if ((p = archive_path (file_spec)) != NULL)
+ {
+ LANG_FOR_EACH_INPUT_STATEMENT (f)
+ {
+ if (input_statement_is_archive_path (file_spec, p, f))
+ walk_wild_file (s, f, callback, data);
+ }
+ }
else if (wildcardp (file_spec))
{
LANG_FOR_EACH_INPUT_STATEMENT (f)
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 *
FAIL ();
}
p->the_bfd = NULL;
- p->asymbols = NULL;
p->next_real_file = NULL;
p->next = NULL;
- p->symbol_count = 0;
p->dynamic = config.dynamic_link;
p->add_needed = add_needed;
p->as_needed = as_needed;
first_file = lang_add_input_file (NULL, lang_input_file_is_marker_enum,
NULL);
abs_output_section =
- lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME);
+ lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME, 0, TRUE);
abs_output_section->bfd_section = bfd_abs_section_ptr;
In this case it is probably an error to create a region that has
already been created. If we are not inside a MEMORY block it is
dubious to use an undeclared region name (except DEFAULT_MEMORY_REGION)
- and so we issue a warning. */
+ and so we issue a warning.
+
+ Each region has at least one name. The first name is either
+ DEFAULT_MEMORY_REGION or the name given in the MEMORY block. You can add
+ alias names to an existing region within a script with
+ REGION_ALIAS (alias, region_name). Each name corresponds to at most one
+ region. */
static lang_memory_region_type *lang_memory_region_list;
static lang_memory_region_type **lang_memory_region_list_tail
lang_memory_region_type *
lang_memory_region_lookup (const char *const name, bfd_boolean create)
{
- lang_memory_region_type *p;
+ lang_memory_region_name *n;
+ lang_memory_region_type *r;
lang_memory_region_type *new;
/* NAME is NULL for LMA memspecs if no region was specified. */
if (name == NULL)
return NULL;
- for (p = lang_memory_region_list; p != NULL; p = p->next)
- if (strcmp (p->name, name) == 0)
- {
- if (create)
- einfo (_("%P:%S: warning: redeclaration of memory region '%s'\n"),
- name);
- return p;
- }
+ for (r = lang_memory_region_list; r != NULL; r = r->next)
+ for (n = &r->name_list; n != NULL; n = n->next)
+ if (strcmp (n->name, name) == 0)
+ {
+ if (create)
+ einfo (_("%P:%S: warning: redeclaration of memory region `%s'\n"),
+ name);
+ return r;
+ }
if (!create && strcmp (name, DEFAULT_MEMORY_REGION))
- einfo (_("%P:%S: warning: memory region %s not declared\n"), name);
+ einfo (_("%P:%S: warning: memory region `%s' not declared\n"), name);
new = stat_alloc (sizeof (lang_memory_region_type));
- new->name = xstrdup (name);
+ new->name_list.name = xstrdup (name);
+ new->name_list.next = NULL;
new->next = NULL;
new->origin = 0;
new->length = ~(bfd_size_type) 0;
return new;
}
+void
+lang_memory_region_alias (const char * alias, const char * region_name)
+{
+ lang_memory_region_name * n;
+ lang_memory_region_type * r;
+ lang_memory_region_type * region;
+
+ /* The default region must be unique. This ensures that it is not necessary
+ to iterate through the name list if someone wants the check if a region is
+ the default memory region. */
+ if (strcmp (region_name, DEFAULT_MEMORY_REGION) == 0
+ || strcmp (alias, DEFAULT_MEMORY_REGION) == 0)
+ einfo (_("%F%P:%S: error: alias for default memory region\n"));
+
+ /* Look for the target region and check if the alias is not already
+ in use. */
+ region = NULL;
+ for (r = lang_memory_region_list; r != NULL; r = r->next)
+ for (n = &r->name_list; n != NULL; n = n->next)
+ {
+ if (region == NULL && strcmp (n->name, region_name) == 0)
+ region = r;
+ if (strcmp (n->name, alias) == 0)
+ einfo (_("%F%P:%S: error: redefinition of memory region "
+ "alias `%s'\n"),
+ alias);
+ }
+
+ /* Check if the target region exists. */
+ if (region == NULL)
+ einfo (_("%F%P:%S: error: memory region `%s' "
+ "for alias `%s' does not exist\n"),
+ region_name,
+ alias);
+
+ /* Add alias to region name list. */
+ n = stat_alloc (sizeof (lang_memory_region_name));
+ n->name = xstrdup (alias);
+ n->next = region->name_list.next;
+ region->name_list.next = n;
+}
+
static lang_memory_region_type *
-lang_memory_default (asection *section)
+lang_memory_default (asection * section)
{
lang_memory_region_type *p;
}
lang_output_section_statement_type *
-lang_output_section_find (const char *const name)
+lang_output_section_statement_lookup (const char *const name,
+ int constraint,
+ bfd_boolean create)
{
struct out_section_hash_entry *entry;
- unsigned long hash;
entry = ((struct out_section_hash_entry *)
bfd_hash_lookup (&output_section_statement_table, name,
- FALSE, FALSE));
+ create, FALSE));
if (entry == NULL)
- return NULL;
-
- hash = entry->root.hash;
- do
{
- if (entry->s.output_section_statement.constraint != -1)
- return &entry->s.output_section_statement;
- entry = (struct out_section_hash_entry *) entry->root.next;
- }
- while (entry != NULL
- && entry->root.hash == hash
- && strcmp (name, entry->s.output_section_statement.name) == 0);
-
- return NULL;
-}
-
-static lang_output_section_statement_type *
-lang_output_section_statement_lookup_1 (const char *const name, int constraint)
-{
- struct out_section_hash_entry *entry;
- struct out_section_hash_entry *last_ent;
- unsigned long hash;
-
- entry = ((struct out_section_hash_entry *)
- bfd_hash_lookup (&output_section_statement_table, name,
- TRUE, FALSE));
- if (entry == NULL)
- {
- einfo (_("%P%F: failed creating section `%s': %E\n"), name);
+ if (create)
+ einfo (_("%P%F: failed creating section `%s': %E\n"), name);
return NULL;
}
{
/* We have a section of this name, but it might not have the correct
constraint. */
- hash = entry->root.hash;
- do
- {
- if (entry->s.output_section_statement.constraint != -1
- && (constraint == 0
- || (constraint == entry->s.output_section_statement.constraint
- && constraint != SPECIAL)))
- return &entry->s.output_section_statement;
- last_ent = entry;
- entry = (struct out_section_hash_entry *) entry->root.next;
- }
- while (entry != NULL
- && entry->root.hash == hash
- && strcmp (name, entry->s.output_section_statement.name) == 0);
+ struct out_section_hash_entry *last_ent;
+ unsigned long hash = entry->root.hash;
+
+ if (create && constraint == SPECIAL)
+ /* Not traversing to the end reverses the order of the second
+ and subsequent SPECIAL sections in the hash table chain,
+ but that shouldn't matter. */
+ last_ent = entry;
+ else
+ do
+ {
+ if (entry->s.output_section_statement.constraint >= 0
+ && (constraint == 0
+ || (constraint
+ == entry->s.output_section_statement.constraint)))
+ return &entry->s.output_section_statement;
+ last_ent = entry;
+ entry = (struct out_section_hash_entry *) entry->root.next;
+ }
+ while (entry != NULL
+ && entry->root.hash == hash
+ && strcmp (name, entry->s.output_section_statement.name) == 0);
+
+ if (!create)
+ return NULL;
entry
= ((struct out_section_hash_entry *)
return &entry->s.output_section_statement;
}
-lang_output_section_statement_type *
-lang_output_section_statement_lookup (const char *const name)
-{
- return lang_output_section_statement_lookup_1 (name, 0);
-}
-
/* A variant of lang_output_section_find used by place_orphan.
Returns the output statement that should precede a new output
statement for SEC. If an exact match is found on certain flags,
return found;
}
- if (sec->flags & SEC_CODE)
+ if ((sec->flags & SEC_CODE) != 0
+ && (sec->flags & SEC_ALLOC) != 0)
{
/* Try for a rw code section. */
for (look = first; look; look = look->next)
found = look;
}
}
- else if (sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL))
+ else if ((sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL)) != 0
+ && (sec->flags & SEC_ALLOC) != 0)
{
/* .rodata can go after .text, .sdata2 after .rodata. */
for (look = first; look; look = look->next)
found = look;
}
}
- else if (sec->flags & SEC_SMALL_DATA)
+ else if ((sec->flags & SEC_SMALL_DATA) != 0
+ && (sec->flags & SEC_ALLOC) != 0)
{
/* .sdata goes after .data, .sbss after .sdata. */
for (look = first; look; look = look->next)
found = look;
}
}
- else if (sec->flags & SEC_HAS_CONTENTS)
+ else if ((sec->flags & SEC_HAS_CONTENTS) != 0
+ && (sec->flags & SEC_ALLOC) != 0)
{
/* .data goes after .rodata. */
for (look = first; look; look = look->next)
found = look;
}
}
- else
+ else if ((sec->flags & SEC_ALLOC) != 0)
{
- /* .bss goes last. */
+ /* .bss goes after any other alloc section. */
for (look = first; look; look = look->next)
{
flags = look->flags;
found = look;
}
}
+ else
+ {
+ /* non-alloc go last. */
+ for (look = first; look; look = look->next)
+ {
+ flags = look->flags;
+ if (look->bfd_section != NULL)
+ flags = look->bfd_section->flags;
+ flags ^= sec->flags;
+ if (!(flags & SEC_DEBUGGING))
+ found = look;
+ }
+ return found;
+ }
if (found || !match_type)
return found;
for (lookup = os->prev; lookup != NULL; lookup = lookup->prev)
{
- if (lookup->constraint == -1)
+ if (lookup->constraint < 0)
continue;
if (lookup->bfd_section != NULL && lookup->bfd_section->owner != NULL)
lang_output_section_statement_type *
lang_insert_orphan (asection *s,
const char *secname,
+ int constraint,
lang_output_section_statement_type *after,
struct orphan_save *place,
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;
os_tail = ((lang_output_section_statement_type **)
lang_output_section_statement.tail);
os = lang_enter_output_section_statement (secname, address, 0, NULL, NULL,
- NULL, 0);
+ NULL, constraint);
if (add_child == NULL)
add_child = &os->children;
{
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);
/* Restore the global list pointer. */
if (after != NULL)
- stat_ptr = old;
+ pop_stat_ptr ();
if (after != NULL && os->bfd_section != NULL)
{
/* 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;
char buf[100];
int len;
- fprintf (config.map_file, "%-16s ", m->name);
+ fprintf (config.map_file, "%-16s ", m->name_list.name);
sprintf_vma (buf, m->origin);
minfo ("0x%s ", buf);
}
static void
-init_map_userdata (abfd, sec, data)
- bfd *abfd ATTRIBUTE_UNUSED;
- asection *sec;
- void *data ATTRIBUTE_UNUSED;
+init_map_userdata (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *sec,
+ void *data ATTRIBUTE_UNUSED)
{
fat_section_userdata_type *new_data
= ((fat_section_userdata_type *) (stat_alloc
}
static bfd_boolean
-sort_def_symbol (hash_entry, info)
- struct bfd_link_hash_entry *hash_entry;
- void *info ATTRIBUTE_UNUSED;
+sort_def_symbol (struct bfd_link_hash_entry *hash_entry,
+ void *info ATTRIBUTE_UNUSED)
{
if (hash_entry->type == bfd_link_hash_defined
|| hash_entry->type == bfd_link_hash_defweak)
if (strcmp (s->name, DISCARD_SECTION_NAME) == 0)
einfo (_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME);
- s->bfd_section = bfd_get_section_by_name (link_info.output_bfd, s->name);
+ if (s->constraint != SPECIAL)
+ s->bfd_section = bfd_get_section_by_name (link_info.output_bfd, s->name);
if (s->bfd_section == NULL)
- s->bfd_section = bfd_make_section_with_flags (link_info.output_bfd,
- s->name, flags);
+ s->bfd_section = bfd_make_section_anyway_with_flags (link_info.output_bfd,
+ s->name, flags);
if (s->bfd_section == NULL)
{
einfo (_("%P%F: output format %s cannot represent section called %s\n"),
&& ! 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;
}
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;
+ einfo (_("%F%B: file not recognized: %E\n"), entry->the_bfd);
bfd_close (entry->the_bfd);
entry->the_bfd = NULL;
/* 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;
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))
if (target->flavour != original->flavour)
return 0;
+ /* Ignore generic big and little endian elf vectors. */
+ if (strcmp (target->name, "elf32-big") == 0
+ || strcmp (target->name, "elf64-big") == 0
+ || strcmp (target->name, "elf32-little") == 0
+ || strcmp (target->name, "elf64-little") == 0)
+ return 0;
+
/* If we have not found a potential winner yet, then record this one. */
if (winner == NULL)
{
case lang_wild_statement_enum:
/* Maybe we should load the file's symbols. */
if (s->wild_statement.filename
- && ! wildcardp (s->wild_statement.filename))
+ && !wildcardp (s->wild_statement.filename)
+ && !archive_path (s->wild_statement.filename))
lookup_name (s->wild_statement.filename);
open_input_bfds (s->wild_statement.children.head, force);
break;
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;
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))
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;
for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
{
switch (s->header.type)
- {
- case lang_wild_statement_enum:
- walk_wild (&s->wild_statement, check_section_callback,
- output_section_statement);
- if (! output_section_statement->all_input_readonly)
- return;
- break;
- case lang_constructors_statement_enum:
- check_input_sections (constructor_list.head,
- output_section_statement);
- if (! output_section_statement->all_input_readonly)
- return;
- break;
- case lang_group_statement_enum:
- check_input_sections (s->group_statement.children.head,
- output_section_statement);
- if (! output_section_statement->all_input_readonly)
- return;
- break;
- default:
- break;
- }
+ {
+ case lang_wild_statement_enum:
+ walk_wild (&s->wild_statement, check_section_callback,
+ output_section_statement);
+ if (! output_section_statement->all_input_readonly)
+ return;
+ break;
+ case lang_constructors_statement_enum:
+ check_input_sections (constructor_list.head,
+ output_section_statement);
+ if (! output_section_statement->all_input_readonly)
+ return;
+ break;
+ case lang_group_statement_enum:
+ check_input_sections (s->group_statement.children.head,
+ output_section_statement);
+ if (! output_section_statement->all_input_readonly)
+ return;
+ break;
+ default:
+ break;
+ }
}
}
break;
case lang_address_statement_enum:
/* Mark the specified section with the supplied address.
-
If this section was actually a segment marker, then the
directive is ignored if the linker script explicitly
processed the segment marker. Originally, the linker
{
lang_output_section_statement_type *aos
= (lang_output_section_statement_lookup
- (s->address_statement.section_name));
+ (s->address_statement.section_name, 0, TRUE));
if (aos->bfd_section == NULL)
init_os (aos, NULL, 0);
lang_statement_union_type **s;
lang_output_section_statement_type *first_os = NULL;
lang_output_section_statement_type *last_os = NULL;
+ lang_output_section_statement_type *os;
/* "start of list" is actually the statement immediately after
the special abs_section output statement, so that it isn't
{
/* Keep pointers to the first and last output section
statement in the sequence we may be about to move. */
- last_os = &(*s)->output_section_statement;
+ os = &(*s)->output_section_statement;
+
+ ASSERT (last_os == NULL || last_os->next == os);
+ last_os = os;
+
+ /* Set constraint negative so that lang_output_section_find
+ won't match this output section statement. At this
+ stage in linking constraint has values in the range
+ [-1, ONLY_IN_RW]. */
+ last_os->constraint = -2 - last_os->constraint;
if (first_os == NULL)
first_os = last_os;
}
{
lang_insert_statement_type *i = &(*s)->insert_statement;
lang_output_section_statement_type *where;
- lang_output_section_statement_type *os;
lang_statement_union_type **ptr;
lang_statement_union_type *first;
where = lang_output_section_find (i->where);
if (where != NULL && i->is_before)
{
- do
+ do
where = where->prev;
- while (where != NULL && where->constraint == -1);
+ while (where != NULL && where->constraint < 0);
}
if (where == NULL)
{
- einfo (_("%X%P: %s not found for insert\n"), i->where);
- continue;
- }
- /* You can't insert into the list you are moving. */
- for (os = first_os; os != NULL; os = os->next)
- if (os == where || os == last_os)
- break;
- if (os == where)
- {
- einfo (_("%X%P: %s not found for insert\n"), i->where);
- continue;
+ einfo (_("%F%P: %s not found for insert\n"), i->where);
+ return;
}
/* Deal with reordering the output section statement list. */
last_sec = NULL;
for (os = first_os; os != NULL; os = os->next)
{
+ os->constraint = -2 - os->constraint;
if (os->bfd_section != NULL
&& os->bfd_section->owner != NULL)
{
s = &lang_output_section_statement.head;
}
}
+
+ /* Undo constraint twiddling. */
+ for (os = first_os; os != NULL; os = os->next)
+ {
+ os->constraint = -2 - os->constraint;
+ if (os == last_os)
+ break;
+ }
}
/* An output section might have been removed after its statement was
asection *output_section;
bfd_boolean exclude;
- if (os->constraint == -1)
+ if (os->constraint < 0)
continue;
output_section = os->bfd_section;
if (section->vma != section->lma)
minfo (_(" load address 0x%V"), section->lma);
+
+ if (output_section_statement->update_dot_tree != NULL)
+ exp_fold_tree (output_section_statement->update_dot_tree,
+ bfd_abs_section_ptr, &print_dot);
}
print_nl ();
static void
print_input_statement (lang_input_statement_type *statm)
{
- if (statm->filename != NULL)
- {
- fprintf (config.map_file, "LOAD %s\n", statm->filename);
- }
+ if (statm->filename != NULL
+ && (statm->the_bfd == NULL
+ || (statm->the_bfd->flags & BFD_LINKER_CREATED) == 0))
+ fprintf (config.map_file, "LOAD %s\n", statm->filename);
}
/* Print all symbols defined in a particular section. This is called
else
print_all_symbols (i);
- print_dot = addr + TO_ADDR (size);
+ /* Update print_dot, but make sure that we do not move it
+ backwards - this could happen if we have overlays and a
+ later overlay is shorter than an earier one. */
+ if (addr + TO_ADDR (size) > print_dot)
+ print_dot = addr + TO_ADDR (size);
}
}
/* Use the existing pad statement. */
}
else if ((pad = *ptr) != NULL
- && pad->header.type == lang_padding_statement_enum
- && pad->padding_statement.output_section == output_section)
+ && pad->header.type == lang_padding_statement_enum
+ && pad->padding_statement.output_section == output_section)
{
/* Use the existing pad statement. */
}
a bfd_vma quantity in decimal. */
for (m = lang_memory_region_list; m; m = m->next)
if (m->had_full_message)
- einfo (_("%X%P: region %s overflowed by %ld bytes\n"),
- m->name, (long)(m->current - (m->origin + m->length)));
+ einfo (_("%X%P: region `%s' overflowed by %ld bytes\n"),
+ m->name_list.name, (long)(m->current - (m->origin + m->length)));
}
{
if (tree != NULL)
{
- einfo (_("%X%P: address 0x%v of %B section %s"
- " is not within region %s\n"),
+ einfo (_("%X%P: address 0x%v of %B section `%s'"
+ " is not within region `%s'\n"),
region->current,
os->bfd_section->owner,
os->bfd_section->name,
- region->name);
+ region->name_list.name);
}
else if (!region->had_full_message)
{
region->had_full_message = TRUE;
- einfo (_("%X%P: %B section %s will not fit in region %s\n"),
+ einfo (_("%X%P: %B section `%s' will not fit in region `%s'\n"),
os->bfd_section->owner,
os->bfd_section->name,
- region->name);
+ region->name_list.name);
}
}
}
from the region specification. */
if (os->region == NULL
|| ((os->bfd_section->flags & (SEC_ALLOC | SEC_LOAD))
- && os->region->name[0] == '*'
- && strcmp (os->region->name,
+ && os->region->name_list.name[0] == '*'
+ && strcmp (os->region->name_list.name,
DEFAULT_MEMORY_REGION) == 0))
{
os->region = lang_memory_default (os->bfd_section);
&& !IGNORE_SECTION (os->bfd_section)
&& ! link_info.relocatable
&& check_regions
- && strcmp (os->region->name,
+ && strcmp (os->region->name_list.name,
DEFAULT_MEMORY_REGION) == 0
&& lang_memory_region_list != NULL
- && (strcmp (lang_memory_region_list->name,
+ && (strcmp (lang_memory_region_list->name_list.name,
DEFAULT_MEMORY_REGION) != 0
|| lang_memory_region_list->next != NULL)
&& expld.phase != lang_mark_phase_enum)
os->name, (unsigned long) (newdot - savedot));
}
- bfd_set_section_vma (0, os->bfd_section, newdot);
+ /* PR 6945: Do not update the vma's of output sections
+ when performing a relocatable link on COFF objects. */
+ if (! link_info.relocatable
+ || (bfd_get_flavour (link_info.output_bfd)
+ != bfd_target_coff_flavour))
+ bfd_set_section_vma (0, os->bfd_section, newdot);
os->bfd_section->output_offset = 0;
}
os_region_check (os, os->region, os->addr_tree,
os->bfd_section->vma);
- if (os->lma_region != NULL && os->lma_region != os->region)
+ if (os->lma_region != NULL && os->lma_region != os->region
+ && (os->bfd_section->flags & SEC_LOAD))
{
os->lma_region->current
= os->bfd_section->lma + TO_ADDR (os->bfd_section->size);
{
/* If DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END pair was seen, try
to put expld.dataseg.relro on a (common) page boundary. */
- bfd_vma old_min_base, relro_end, maxpage;
+ bfd_vma min_base, old_base, relro_end, maxpage;
expld.dataseg.phase = exp_dataseg_relro_adjust;
- old_min_base = expld.dataseg.min_base;
maxpage = expld.dataseg.maxpagesize;
+ /* MIN_BASE is the absolute minimum address we are allowed to start the
+ read-write segment (byte before will be mapped read-only). */
+ min_base = (expld.dataseg.min_base + maxpage - 1) & ~(maxpage - 1);
+ /* OLD_BASE is the address for a feasible minimum address which will
+ still not cause a data overlap inside MAXPAGE causing file offset skip
+ by MAXPAGE. */
+ old_base = expld.dataseg.base;
expld.dataseg.base += (-expld.dataseg.relro_end
& (expld.dataseg.pagesize - 1));
/* Compute the expected PT_GNU_RELRO segment end. */
- relro_end = (expld.dataseg.relro_end + expld.dataseg.pagesize - 1)
- & ~(expld.dataseg.pagesize - 1);
- if (old_min_base + maxpage < expld.dataseg.base)
+ relro_end = ((expld.dataseg.relro_end + expld.dataseg.pagesize - 1)
+ & ~(expld.dataseg.pagesize - 1));
+ if (min_base + maxpage < expld.dataseg.base)
{
expld.dataseg.base -= maxpage;
relro_end -= maxpage;
{
/* The alignment of sections between DATA_SEGMENT_ALIGN
and DATA_SEGMENT_RELRO_END caused huge padding to be
- inserted at DATA_SEGMENT_RELRO_END. Try some other base. */
+ inserted at DATA_SEGMENT_RELRO_END. Try to start a bit lower so
+ that the section alignments will fit in. */
asection *sec;
unsigned int max_alignment_power = 0;
if (((bfd_vma) 1 << max_alignment_power) < expld.dataseg.pagesize)
{
- if (expld.dataseg.base - (1 << max_alignment_power)
- < old_min_base)
+ if (expld.dataseg.base - (1 << max_alignment_power) < old_base)
expld.dataseg.base += expld.dataseg.pagesize;
expld.dataseg.base -= (1 << max_alignment_power);
lang_reset_memory_regions ();
|| (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0
|| link_info.relocatable)
dot += TO_ADDR (os->bfd_section->size);
+
+ if (os->update_dot_tree != NULL)
+ exp_fold_tree (os->update_dot_tree, bfd_abs_section_ptr, &dot);
}
}
break;
bfd_boolean warn;
if ((link_info.relocatable && !link_info.gc_sections)
- || link_info.shared)
+ || (link_info.shared && !link_info.executable))
warn = entry_from_cmdline;
else
warn = TRUE;
/* Look through all the global common symbols and attach them to the
correct section. The -sort-common command line switch may be used
- to roughly sort the entries by size. */
+ to roughly sort the entries by alignment. */
static void
lang_common (void)
bfd_link_hash_traverse (link_info.hash, lang_one_common, NULL);
else
{
- int power;
+ unsigned int power;
+
+ if (config.sort_common == sort_descending)
+ {
+ for (power = 4; power > 0; power--)
+ bfd_link_hash_traverse (link_info.hash, lang_one_common, &power);
- for (power = 4; power >= 0; power--)
- bfd_link_hash_traverse (link_info.hash, lang_one_common, &power);
+ power = 0;
+ bfd_link_hash_traverse (link_info.hash, lang_one_common, &power);
+ }
+ else
+ {
+ for (power = 0; power <= 4; power++)
+ bfd_link_hash_traverse (link_info.hash, lang_one_common, &power);
+
+ power = UINT_MAX;
+ bfd_link_hash_traverse (link_info.hash, lang_one_common, &power);
+ }
}
}
size = h->u.c.size;
power_of_two = h->u.c.p->alignment_power;
- if (config.sort_common
- && power_of_two < (unsigned int) *(int *) info)
+ if (config.sort_common == sort_descending
+ && power_of_two < *(unsigned int *) info)
+ return TRUE;
+ else if (config.sort_common == sort_ascending
+ && power_of_two > *(unsigned int *) info)
return TRUE;
section = h->u.c.p->section;
|| command_line.force_common_definition)
{
if (default_common_section == NULL)
- {
- default_common_section =
- lang_output_section_statement_lookup (".bss");
-
- }
+ default_common_section
+ = lang_output_section_statement_lookup (".bss", 0,
+ TRUE);
lang_add_section (&default_common_section->children, s,
default_common_section);
}
}
- else if (ldemul_place_orphan (s))
- ;
else
{
- lang_output_section_statement_type *os;
+ const char *name = s->name;
+ int constraint = 0;
+
+ if (config.unique_orphan_sections || unique_section_p (s))
+ constraint = SPECIAL;
- os = lang_output_section_statement_lookup (s->name);
- lang_add_section (&os->children, s, os);
+ if (!ldemul_place_orphan (s, name, constraint))
+ {
+ lang_output_section_statement_type *os;
+ os = lang_output_section_statement_lookup (name,
+ constraint,
+ TRUE);
+ lang_add_section (&os->children, s, os);
+ }
}
}
}
{
lang_output_section_statement_type *os;
- os = lang_output_section_statement_lookup_1 (output_section_statement_name,
- constraint);
- current_section = os;
-
- /* Make next things chain into subchain of this. */
+ os = lang_output_section_statement_lookup (output_section_statement_name,
+ constraint, TRUE);
+ current_section = os;
if (os->addr_tree == NULL)
{
else
os->flags = SEC_NEVER_LOAD;
os->block_value = 1;
- stat_ptr = &os->children;
+
+ /* Make next things chain into subchain of this. */
+ push_stat_ptr (&os->children);
os->subsection_alignment =
topower (exp_get_value_int (subalign, -1, "subsection alignment"));
ldemul_finish ();
/* Make sure that the section addresses make sense. */
- if (! link_info.relocatable
- && command_line.check_section_addresses)
+ if (command_line.check_section_addresses)
lang_check_section_addresses ();
lang_end ();
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
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
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
{
lang_output_section_phdr_list *pl;
- if (os->constraint == -1)
+ if (os->constraint < 0)
continue;
pl = os->phdrs;
|| (os->bfd_section->flags & SEC_ALLOC) == 0)
continue;
+ /* Don't add orphans to PT_INTERP header. */
+ if (l->type == 3)
+ continue;
+
if (last == NULL)
{
lang_output_section_statement_type * tmp_os;
{
lang_output_section_phdr_list *pl;
- if (os->constraint == -1
+ if (os->constraint < 0
|| os->bfd_section == NULL)
continue;
java_sym = sym;
}
- if (head->htab && (prev == NULL || prev->symbol))
+ if (head->htab && (prev == NULL || prev->literal))
{
struct bfd_elf_version_expr e;
switch (prev ? prev->mask : 0)
{
- case 0:
- if (head->mask & BFD_ELF_VERSION_C_TYPE)
- {
- e.symbol = sym;
- expr = htab_find (head->htab, &e);
- while (expr && strcmp (expr->symbol, sym) == 0)
- if (expr->mask == BFD_ELF_VERSION_C_TYPE)
- goto out_ret;
- else
- expr = expr->next;
- }
- /* Fallthrough */
- case BFD_ELF_VERSION_C_TYPE:
- if (head->mask & BFD_ELF_VERSION_CXX_TYPE)
- {
- e.symbol = cxx_sym;
- expr = htab_find (head->htab, &e);
- while (expr && strcmp (expr->symbol, cxx_sym) == 0)
- if (expr->mask == BFD_ELF_VERSION_CXX_TYPE)
- goto out_ret;
- else
- expr = expr->next;
- }
- /* Fallthrough */
- case BFD_ELF_VERSION_CXX_TYPE:
- if (head->mask & BFD_ELF_VERSION_JAVA_TYPE)
- {
- e.symbol = java_sym;
- expr = htab_find (head->htab, &e);
- while (expr && strcmp (expr->symbol, java_sym) == 0)
- if (expr->mask == BFD_ELF_VERSION_JAVA_TYPE)
- goto out_ret;
- else
- expr = expr->next;
- }
- /* Fallthrough */
- default:
- break;
+ case 0:
+ if (head->mask & BFD_ELF_VERSION_C_TYPE)
+ {
+ e.pattern = sym;
+ expr = htab_find (head->htab, &e);
+ while (expr && strcmp (expr->pattern, sym) == 0)
+ if (expr->mask == BFD_ELF_VERSION_C_TYPE)
+ goto out_ret;
+ else
+ expr = expr->next;
+ }
+ /* Fallthrough */
+ case BFD_ELF_VERSION_C_TYPE:
+ if (head->mask & BFD_ELF_VERSION_CXX_TYPE)
+ {
+ e.pattern = cxx_sym;
+ expr = htab_find (head->htab, &e);
+ while (expr && strcmp (expr->pattern, cxx_sym) == 0)
+ if (expr->mask == BFD_ELF_VERSION_CXX_TYPE)
+ goto out_ret;
+ else
+ expr = expr->next;
+ }
+ /* Fallthrough */
+ case BFD_ELF_VERSION_CXX_TYPE:
+ if (head->mask & BFD_ELF_VERSION_JAVA_TYPE)
+ {
+ e.pattern = java_sym;
+ expr = htab_find (head->htab, &e);
+ while (expr && strcmp (expr->pattern, java_sym) == 0)
+ if (expr->mask == BFD_ELF_VERSION_JAVA_TYPE)
+ goto out_ret;
+ else
+ expr = expr->next;
+ }
+ /* Fallthrough */
+ default:
+ break;
}
}
/* Finally, try the wildcards. */
- if (prev == NULL || prev->symbol)
+ if (prev == NULL || prev->literal)
expr = head->remaining;
else
expr = prev->next;
break;
}
-out_ret:
+ out_ret:
if (cxx_sym != sym)
free ((char *) cxx_sym);
if (java_sym != sym)
}
/* Return NULL if the PATTERN argument is a glob pattern, otherwise,
- return a string pointing to the symbol name. */
+ return a pointer to the symbol name with any backslash quotes removed. */
static const char *
realsymbol (const char *pattern)
{
/* It is a glob pattern only if there is no preceding
backslash. */
- if (! backslash && (*p == '?' || *p == '*' || *p == '['))
- {
- free (symbol);
- return NULL;
- }
-
if (backslash)
{
/* Remove the preceding backslash. */
*(s - 1) = *p;
+ backslash = FALSE;
changed = TRUE;
}
else
- *s++ = *p;
+ {
+ if (*p == '?' || *p == '*' || *p == '[')
+ {
+ free (symbol);
+ return NULL;
+ }
- backslash = *p == '\\';
+ *s++ = *p;
+ backslash = *p == '\\';
+ }
}
if (changed)
ret = xmalloc (sizeof *ret);
ret->next = orig;
- ret->pattern = literal_p ? NULL : new;
ret->symver = 0;
ret->script = 0;
- ret->symbol = literal_p ? new : realsymbol (new);
+ ret->literal = TRUE;
+ ret->pattern = literal_p ? new : realsymbol (new);
+ if (ret->pattern == NULL)
+ {
+ ret->pattern = new;
+ ret->literal = FALSE;
+ }
if (lang == NULL || strcasecmp (lang, "C") == 0)
ret->mask = BFD_ELF_VERSION_C_TYPE;
{
const struct bfd_elf_version_expr *e = p;
- return htab_hash_string (e->symbol);
+ return htab_hash_string (e->pattern);
}
static int
const struct bfd_elf_version_expr *e1 = p1;
const struct bfd_elf_version_expr *e2 = p2;
- return strcmp (e1->symbol, e2->symbol) == 0;
+ return strcmp (e1->pattern, e2->pattern) == 0;
}
static void
for (e = head->list; e; e = e->next)
{
- if (e->symbol)
+ if (e->literal)
count++;
head->mask |= e->mask;
}
for (e = head->list; e; e = next)
{
next = e->next;
- if (!e->symbol)
+ if (!e->literal)
{
*remaining_loc = e;
remaining_loc = &e->next;
last = e1;
e1 = e1->next;
}
- while (e1 && strcmp (e1->symbol, e->symbol) == 0);
+ while (e1 && strcmp (e1->pattern, e->pattern) == 0);
if (last == NULL)
{
/* This is a duplicate. */
/* FIXME: Memory leak. Sometimes pattern is not
xmalloced alone, but in larger chunk of memory. */
- /* free (e->symbol); */
+ /* free (e->pattern); */
free (e);
}
else
{
struct bfd_elf_version_expr *e2;
- if (t->locals.htab && e1->symbol)
+ if (t->locals.htab && e1->literal)
{
e2 = htab_find (t->locals.htab, e1);
- while (e2 && strcmp (e1->symbol, e2->symbol) == 0)
+ while (e2 && strcmp (e1->pattern, e2->pattern) == 0)
{
if (e1->mask == e2->mask)
einfo (_("%X%P: duplicate expression `%s'"
- " in version information\n"), e1->symbol);
+ " in version information\n"), e1->pattern);
e2 = e2->next;
}
}
- else if (!e1->symbol)
+ else if (!e1->literal)
for (e2 = t->locals.remaining; e2 != NULL; e2 = e2->next)
if (strcmp (e1->pattern, e2->pattern) == 0
&& e1->mask == e2->mask)
{
struct bfd_elf_version_expr *e2;
- if (t->globals.htab && e1->symbol)
+ if (t->globals.htab && e1->literal)
{
e2 = htab_find (t->globals.htab, e1);
- while (e2 && strcmp (e1->symbol, e2->symbol) == 0)
+ while (e2 && strcmp (e1->pattern, e2->pattern) == 0)
{
if (e1->mask == e2->mask)
einfo (_("%X%P: duplicate expression `%s'"
" in version information\n"),
- e1->symbol);
+ e1->pattern);
e2 = e2->next;
}
}
- else if (!e1->symbol)
+ else if (!e1->literal)
for (e2 = t->globals.remaining; e2 != NULL; e2 = e2->next)
if (strcmp (e1->pattern, e2->pattern) == 0
&& e1->mask == e2->mask)