lang_input_statement_type statement (reached via input_statement field in a
lang_statement_union). */
lang_statement_list_type input_file_chain;
+static const char *current_input_file;
+struct bfd_elf_dynamic_list **current_dynamic_list_p;
struct bfd_sym_chain entry_symbol = { NULL, NULL };
const char *entry_section = ".text";
struct lang_input_statement_flags input_flags;
#define outside_symbol_address(q) \
((q)->value + outside_section_address (q->section))
-#define SECTION_NAME_MAP_LENGTH (16)
-
/* CTF sections smaller than this are not compressed: compression of
dictionaries this small doesn't gain much, and this lets consumers mmap the
sections directly out of the ELF file and use them with no decompression
return strcmp (pattern, name);
}
+static char *
+ldirname (const char *name)
+{
+ const char *base = lbasename (name);
+ char *dirname;
+
+ while (base > name && IS_DIR_SEPARATOR (base[-1]))
+ --base;
+ if (base == name)
+ return strdup (".");
+ dirname = strdup (name);
+ dirname[base - name] = '\0';
+ return dirname;
+}
+
/* If PATTERN is of the form archive:file, return a pointer to the
separator. If not, return NULL. */
if (sep != file_spec)
{
- const char *aname = f->the_bfd->my_archive->filename;
+ const char *aname = bfd_get_filename (f->the_bfd->my_archive);
*sep = 0;
match = name_match (file_spec, aname) == 0;
*sep = link_info.path_separator;
else if (file->the_bfd != NULL
&& file->the_bfd->my_archive != NULL
&& name_match (list_tmp->name,
- file->the_bfd->my_archive->filename) == 0)
+ bfd_get_filename (file->the_bfd->my_archive)) == 0)
return TRUE;
}
static lang_input_statement_type *
new_afile (const char *name,
lang_input_file_enum_type file_type,
- const char *target)
+ const char *target,
+ const char *from_filename)
{
lang_input_statement_type *p;
p = new_stat (lang_input_statement, stat_ptr);
memset (&p->the_bfd, 0,
sizeof (*p) - offsetof (lang_input_statement_type, the_bfd));
+ p->extra_search_path = NULL;
p->target = target;
p->flags.dynamic = input_flags.dynamic;
p->flags.add_DT_NEEDED_for_dynamic = input_flags.add_DT_NEEDED_for_dynamic;
case lang_input_file_is_search_file_enum:
p->filename = name;
p->local_sym_name = name;
+ /* If name is a relative path, search the directory of the current linker
+ script first. */
+ if (from_filename && !IS_ABSOLUTE_PATH (name))
+ p->extra_search_path = ldirname (from_filename);
p->flags.real = TRUE;
p->flags.search_dirs = TRUE;
break;
within the sysroot subdirectory.) */
unsigned int outer_sysrooted = input_flags.sysrooted;
input_flags.sysrooted = 0;
- ret = new_afile (sysrooted_name, file_type, target);
+ ret = new_afile (sysrooted_name, file_type, target, NULL);
input_flags.sysrooted = outer_sysrooted;
return ret;
}
- return new_afile (name, file_type, target);
+ return new_afile (name, file_type, target, current_input_file);
}
struct out_section_hash_entry
/* This prevents future calls from assigning this section. */
section->output_section = bfd_abs_section_ptr;
}
+ else if (link_info.non_contiguous_regions_warnings)
+ einfo (_("%P:%pS: warning: --enable-non-contiguous-regions makes "
+ "section `%pA' from '%pB' match /DISCARD/ clause.\n"),
+ NULL, section, section->owner);
+
return;
}
}
if (section->output_section != NULL)
- return;
+ {
+ if (!link_info.non_contiguous_regions)
+ return;
+
+ /* SECTION has already been handled in a special way
+ (eg. LINK_ONCE): skip it. */
+ if (bfd_is_abs_section (section->output_section))
+ return;
+
+ /* Already assigned to the same output section, do not process
+ it again, to avoid creating loops between duplicate sections
+ later. */
+ if (section->output_section == output->bfd_section)
+ return;
+
+ if (link_info.non_contiguous_regions_warnings && output->bfd_section)
+ einfo (_("%P:%pS: warning: --enable-non-contiguous-regions may "
+ "change behaviour for section `%pA' from '%pB' (assigned to "
+ "%pA, but additional match: %pA)\n"),
+ NULL, section, section->owner, section->output_section,
+ output->bfd_section);
+
+ /* SECTION has already been assigned to an output section, but
+ the user allows it to be mapped to another one in case it
+ overflows. We'll later update the actual output section in
+ size_input_section as appropriate. */
+ }
/* We don't copy the SEC_NEVER_LOAD flag from an input section
to an output section, because we want to be able to include a
}
else
{
- ln = ls->section->owner->filename;
+ ln = bfd_get_filename (ls->section->owner);
la = FALSE;
}
if (fa)
fn = file->filename;
if (la)
- ln = ls->section->owner->filename;
+ ln = bfd_get_filename (ls->section->owner);
i = filename_cmp (fn, ln);
if (i > 0)
lang_statement_union_type *rest = *after;
stat_ptr->tail = after;
search = new_afile (name, lang_input_file_is_search_file_enum,
- default_target);
+ default_target, NULL);
*stat_ptr->tail = rest;
if (*tail == NULL)
stat_ptr->tail = tail;
while (lib)
{
int len = strlen (lib->name);
- const char *filename = lbasename (abfd->filename);
+ const char *filename = lbasename (bfd_get_filename (abfd));
if (strcmp (lib->name, "ALL") == 0)
{
ldfile_assumed_script = TRUE;
parser_input = input_script;
+ current_input_file = entry->filename;
yyparse ();
+ current_input_file = NULL;
ldfile_assumed_script = FALSE;
/* missing_file is sticky. sysrooted will already have been
lang_statement_union_type **ptr;
lang_statement_union_type *first;
+ if (link_info.non_contiguous_regions)
+ {
+ einfo (_("warning: INSERT statement in linker script is "
+ "incompatible with --enable-non-contiguous-regions.\n"));
+ }
+
where = lang_output_section_find (i->where);
if (where != NULL && i->is_before)
{
/* Print all symbols defined in a particular section. This is called
via bfd_link_hash_traverse, or by print_all_symbols. */
-static bfd_boolean
+bfd_boolean
print_one_symbol (struct bfd_link_hash_entry *hash_entry, void *ptr)
{
asection *sec = (asection *) ptr;
/* Print the symbols. */
for (i = 0; i < ud->map_symbol_def_count; i++)
- print_one_symbol (entries[i], sec);
+ ldemul_print_symbol (entries[i], sec);
obstack_free (&map_obstack, entries);
}
&& i->output_section->owner == link_info.output_bfd)
{
if (link_info.reduce_memory_overheads)
- bfd_link_hash_traverse (link_info.hash, print_one_symbol, i);
+ bfd_link_hash_traverse (link_info.hash, ldemul_print_symbol, i);
else
print_all_symbols (i);
(lang_statement_union_type **this_ptr,
lang_output_section_statement_type *output_section_statement,
fill_type *fill,
+ bfd_boolean *removed,
bfd_vma dot)
{
lang_input_section_type *is = &((*this_ptr)->input_section);
asection *i = is->section;
asection *o = output_section_statement->bfd_section;
+ *removed = 0;
+
+ if (link_info.non_contiguous_regions)
+ {
+ /* If the input section I has already been successfully assigned
+ to an output section other than O, don't bother with it and
+ let the caller remove it from the list. Keep processing in
+ case we have already handled O, because the repeated passes
+ have reinitialized its size. */
+ if (i->already_assigned && i->already_assigned != o)
+ {
+ *removed = 1;
+ return dot;
+ }
+ }
if (i->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
i->output_offset = i->vma - o->vma;
dot += alignment_needed;
}
+ if (link_info.non_contiguous_regions)
+ {
+ /* If I would overflow O, let the caller remove I from the
+ list. */
+ if (output_section_statement->region)
+ {
+ bfd_vma end = output_section_statement->region->origin
+ + output_section_statement->region->length;
+
+ if (dot + TO_ADDR (i->size) > end)
+ {
+ if (i->flags & SEC_LINKER_CREATED)
+ einfo (_("%F%P: Output section '%s' not large enough for the "
+ "linker-created stubs section '%s'.\n"),
+ i->output_section->name, i->name);
+
+ if (i->rawsize && i->rawsize != i->size)
+ einfo (_("%F%P: Relaxation not supported with "
+ "--enable-non-contiguous-regions (section '%s' "
+ "would overflow '%s' after it changed size).\n"),
+ i->name, i->output_section->name);
+
+ *removed = 1;
+ dot = end;
+ i->output_section = NULL;
+ return dot;
+ }
+ }
+ }
+
/* Remember where in the output section this input section goes. */
i->output_offset = dot - o->vma;
dot += TO_ADDR (i->size);
if (!(o->flags & SEC_FIXED_SIZE))
o->size = TO_SIZE (dot - o->vma);
+
+ if (link_info.non_contiguous_regions)
+ {
+ /* Record that I was successfully assigned to O, and update
+ its actual output section too. */
+ i->already_assigned = o;
+ i->output_section = o;
+ }
}
return dot;
bfd_boolean check_regions)
{
lang_statement_union_type *s;
+ lang_statement_union_type *prev_s = NULL;
+ bfd_boolean removed_prev_s = FALSE;
/* Size up the sections from their constituent parts. */
- for (s = *prev; s != NULL; s = s->header.next)
+ for (s = *prev; s != NULL; prev_s = s, s = s->header.next)
{
+ bfd_boolean removed=FALSE;
+
switch (s->header.type)
{
case lang_output_section_statement_enum:
if (lang_sizing_iteration == 1)
diff = dotdelta;
else if (lang_sizing_iteration > 1)
- diff = newdot - os->bfd_section->vma;
+ {
+ /* Only report adjustments that would change
+ alignment from what we have already reported. */
+ diff = newdot - os->bfd_section->vma;
+ if (!(diff & (((bfd_vma) 1 << section_alignment) - 1)))
+ diff = 0;
+ }
if (diff != 0
&& (config.warn_section_align
|| os->addr_tree != NULL))
*relax = TRUE;
}
dot = size_input_section (prev, output_section_statement,
- fill, dot);
+ fill, &removed, dot);
}
break;
FAIL ();
break;
}
- prev = &s->header.next;
+
+ /* If an input section doesn't fit in the current output
+ section, remove it from the list. Handle the case where we
+ have to remove an input_section statement here: there is a
+ special case to remove the first element of the list. */
+ if (link_info.non_contiguous_regions && removed)
+ {
+ /* If we removed the first element during the previous
+ iteration, override the loop assignment of prev_s. */
+ if (removed_prev_s)
+ prev_s = NULL;
+
+ if (prev_s)
+ {
+ /* If there was a real previous input section, just skip
+ the current one. */
+ prev_s->header.next=s->header.next;
+ s = prev_s;
+ removed_prev_s = FALSE;
+ }
+ else
+ {
+ /* Remove the first input section of the list. */
+ *prev = s->header.next;
+ removed_prev_s = TRUE;
+ }
+
+ /* Move to next element, unless we removed the head of the
+ list. */
+ if (!removed_prev_s)
+ prev = &s->header.next;
+ }
+ else
+ {
+ prev = &s->header.next;
+ removed_prev_s = FALSE;
+ }
}
return dot;
}
bfd_printable_name (input_bfd), input_bfd,
bfd_printable_name (link_info.output_bfd));
}
- else if (bfd_count_sections (input_bfd))
- {
- /* If the input bfd has no contents, it shouldn't set the
- private data of the output bfd. */
+ /* If the input bfd has no contents, it shouldn't set the
+ private data of the output bfd. */
+ else if ((input_bfd->flags & DYNAMIC) != 0
+ || bfd_count_sections (input_bfd) != 0)
+ {
bfd_error_handler_type pfn = NULL;
/* If we aren't supposed to warn about mismatched input
/* Append the list of dynamic symbols to the existing one. */
void
-lang_append_dynamic_list (struct bfd_elf_version_expr *dynamic)
+lang_append_dynamic_list (struct bfd_elf_dynamic_list **list_p,
+ struct bfd_elf_version_expr *dynamic)
{
- if (link_info.dynamic_list)
+ if (*list_p)
{
struct bfd_elf_version_expr *tail;
for (tail = dynamic; tail->next != NULL; tail = tail->next)
;
- tail->next = link_info.dynamic_list->head.list;
- link_info.dynamic_list->head.list = dynamic;
+ tail->next = (*list_p)->head.list;
+ (*list_p)->head.list = dynamic;
}
else
{
d = (struct bfd_elf_dynamic_list *) xcalloc (1, sizeof *d);
d->head.list = dynamic;
d->match = lang_vers_match;
- link_info.dynamic_list = d;
+ *list_p = d;
}
}
dynamic = lang_new_vers_pattern (dynamic, symbols [i], "C++",
FALSE);
- lang_append_dynamic_list (dynamic);
+ lang_append_dynamic_list (&link_info.dynamic_list, dynamic);
}
/* Append the list of C++ operator new and delete dynamic symbols to the
dynamic = lang_new_vers_pattern (dynamic, symbols [i], "C++",
FALSE);
- lang_append_dynamic_list (dynamic);
+ lang_append_dynamic_list (&link_info.dynamic_list, dynamic);
}
/* Scan a space and/or comma separated string of features. */