else
{
p = stat_alloc (sizeof (lang_input_statement_type));
+ p->header.type = lang_input_statement_enum;
p->header.next = NULL;
}
(lang_statement_union_type *) &ret->os,
&ret->os.header.next);
+ ret->os.prev = &((*lang_output_section_statement.tail)
+ ->output_section_statement);
/* GCC's strict aliasing rules prevent us from just casting the
address, so we store the pointer in a variable and cast that
instead. */
lang_output_section_statement_type *
lang_output_section_find_by_flags (const asection *sec,
- lang_output_section_statement_type **exact)
+ lang_output_section_statement_type **exact,
+ lang_match_sec_type_func match_type)
{
lang_output_section_statement_type *first, *look, *found;
flagword flags;
if (look->bfd_section != NULL)
{
flags = look->bfd_section->flags;
- if (!bfd_match_sections_by_type (output_bfd,
- look->bfd_section,
- sec->owner, sec))
+ if (match_type && !match_type (output_bfd, look->bfd_section,
+ sec->owner, sec))
continue;
}
flags ^= sec->flags;
}
if (found != NULL)
{
- *exact = found;
+ if (exact != NULL)
+ *exact = found;
return found;
}
if (look->bfd_section != NULL)
{
flags = look->bfd_section->flags;
- if (!bfd_match_sections_by_type (output_bfd,
- look->bfd_section,
- sec->owner, sec))
+ if (match_type && !match_type (output_bfd, look->bfd_section,
+ sec->owner, sec))
continue;
}
flags ^= sec->flags;
| SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL)))
found = look;
}
- return found;
}
-
- if (sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL))
+ else if (sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL))
{
/* .rodata can go after .text, .sdata2 after .rodata. */
for (look = first; look; look = look->next)
if (look->bfd_section != NULL)
{
flags = look->bfd_section->flags;
- if (!bfd_match_sections_by_type (output_bfd,
- look->bfd_section,
- sec->owner, sec))
+ if (match_type && !match_type (output_bfd, look->bfd_section,
+ sec->owner, sec))
continue;
}
flags ^= sec->flags;
&& !(look->flags & (SEC_SMALL_DATA | SEC_THREAD_LOCAL)))
found = look;
}
- return found;
}
-
- if (sec->flags & SEC_SMALL_DATA)
+ else if (sec->flags & SEC_SMALL_DATA)
{
/* .sdata goes after .data, .sbss after .sdata. */
for (look = first; look; look = look->next)
if (look->bfd_section != NULL)
{
flags = look->bfd_section->flags;
- if (!bfd_match_sections_by_type (output_bfd,
- look->bfd_section,
- sec->owner, sec))
+ if (match_type && !match_type (output_bfd, look->bfd_section,
+ sec->owner, sec))
continue;
}
flags ^= sec->flags;
&& !(sec->flags & SEC_HAS_CONTENTS)))
found = look;
}
- return found;
}
-
- if (sec->flags & SEC_HAS_CONTENTS)
+ else if (sec->flags & SEC_HAS_CONTENTS)
{
/* .data goes after .rodata. */
for (look = first; look; look = look->next)
if (look->bfd_section != NULL)
{
flags = look->bfd_section->flags;
- if (!bfd_match_sections_by_type (output_bfd,
- look->bfd_section,
- sec->owner, sec))
+ if (match_type && !match_type (output_bfd, look->bfd_section,
+ sec->owner, sec))
continue;
}
flags ^= sec->flags;
| SEC_SMALL_DATA | SEC_THREAD_LOCAL)))
found = look;
}
- return found;
}
-
- /* .bss goes last. */
- for (look = first; look; look = look->next)
+ else
{
- flags = look->flags;
- if (look->bfd_section != NULL)
+ /* .bss goes last. */
+ for (look = first; look; look = look->next)
{
- flags = look->bfd_section->flags;
- if (!bfd_match_sections_by_type (output_bfd,
- look->bfd_section,
- sec->owner, sec))
- continue;
+ flags = look->flags;
+ if (look->bfd_section != NULL)
+ {
+ flags = look->bfd_section->flags;
+ if (match_type && !match_type (output_bfd, look->bfd_section,
+ sec->owner, sec))
+ continue;
+ }
+ flags ^= sec->flags;
+ if (!(flags & SEC_ALLOC))
+ found = look;
}
- flags ^= sec->flags;
- if (!(flags & SEC_ALLOC))
- found = look;
}
- return found;
+ if (found || !match_type)
+ return found;
+
+ return lang_output_section_find_by_flags (sec, NULL, NULL);
}
/* Find the last output section before given output statement.
static asection *
output_prev_sec_find (lang_output_section_statement_type *os)
{
- asection *s = (asection *) NULL;
lang_output_section_statement_type *lookup;
- for (lookup = &lang_output_section_statement.head->output_section_statement;
- lookup != NULL;
- lookup = lookup->next)
+ for (lookup = os->prev; lookup != NULL; lookup = lookup->prev)
{
if (lookup->constraint == -1)
continue;
- if (lookup == os)
- return s;
if (lookup->bfd_section != NULL && lookup->bfd_section->owner != NULL)
- s = lookup->bfd_section;
+ return lookup->bfd_section;
}
return NULL;
}
lang_output_section_statement_type *
-lang_insert_orphan (lang_input_statement_type *file,
- asection *s,
+lang_insert_orphan (asection *s,
const char *secname,
lang_output_section_statement_type *after,
struct orphan_save *place,
if (add_child == NULL)
add_child = &os->children;
- lang_add_section (add_child, s, os, file);
+ lang_add_section (add_child, s, os);
lang_leave_output_section_statement (0, "*default*", NULL, NULL);
{
lang_statement_union_type **where;
lang_statement_union_type **assign = NULL;
+ bfd_boolean ignore_first;
/* Look for a suitable place for the new statement list.
The idea is to skip over anything that might be inside
a SECTIONS {} statement in a script, before we find
another output_section_statement. Assignments to "dot"
before an output section statement are assumed to
- belong to it. */
+ belong to it. An exception to this rule is made for
+ the first assignment to dot, otherwise we might put an
+ orphan before . = . + SIZEOF_HEADERS or similar
+ assignments that set the initial address. */
+
+ ignore_first = after == (&lang_output_section_statement.head
+ ->output_section_statement);
for (where = &after->header.next;
*where != NULL;
where = &(*where)->header.next)
ass = &(*where)->assignment_statement;
if (ass->exp->type.node_class != etree_assert
&& ass->exp->assign.dst[0] == '.'
- && ass->exp->assign.dst[1] == 0)
+ && ass->exp->assign.dst[1] == 0
+ && !ignore_first)
assign = where;
}
+ ignore_first = FALSE;
continue;
case lang_wild_statement_enum:
case lang_input_section_enum:
if (s->load_base != NULL)
exp_init_os (s->load_base);
+ /* If supplied an alignment, set it. */
+ if (s->section_alignment != -1)
+ s->bfd_section->alignment_power = s->section_alignment;
+
if (isec)
bfd_init_private_section_data (isec->owner, isec,
output_bfd, s->bfd_section,
void
lang_add_section (lang_statement_list_type *ptr,
asection *section,
- lang_output_section_statement_type *output,
- lang_input_statement_type *file)
+ lang_output_section_statement_type *output)
{
flagword flags = section->flags;
bfd_boolean discard;
new = new_stat (lang_input_section, ptr);
new->section = section;
- new->ifile = file;
section->output_section = output->bfd_section;
flags = section->flags;
if (section->alignment_power > output->bfd_section->alignment_power)
output->bfd_section->alignment_power = section->alignment_power;
- /* If supplied an alignment, then force it. */
- if (output->section_alignment != -1)
- output->bfd_section->alignment_power = output->section_alignment;
-
if (bfd_get_arch (section->owner) == bfd_arch_tic54x
&& (section->flags & SEC_TIC54X_BLOCK) != 0)
{
fa = FALSE;
}
- if (ls->ifile->the_bfd != NULL
- && bfd_my_archive (ls->ifile->the_bfd) != NULL)
+ if (bfd_my_archive (ls->section->owner) != NULL)
{
- ln = bfd_get_filename (bfd_my_archive (ls->ifile->the_bfd));
+ ln = bfd_get_filename (bfd_my_archive (ls->section->owner));
la = TRUE;
}
else
{
- ln = ls->ifile->filename;
+ ln = ls->section->owner->filename;
la = FALSE;
}
if (fa)
fn = file->filename;
if (la)
- ln = ls->ifile->filename;
+ ln = ls->section->owner->filename;
i = strcmp (fn, ln);
if (i > 0)
if (before == NULL)
lang_add_section (&ptr->children, section,
- (lang_output_section_statement_type *) output,
- file);
+ (lang_output_section_statement_type *) output);
else
{
lang_statement_list_type list;
lang_list_init (&list);
lang_add_section (&list, section,
- (lang_output_section_statement_type *) output,
- file);
+ (lang_output_section_statement_type *) output);
/* If we are discarding the section, LIST.HEAD will
be NULL. */
lang_input_section_type *is = &((*this_ptr)->input_section);
asection *i = is->section;
- if (!is->ifile->just_syms_flag && (i->flags & SEC_EXCLUDE) == 0)
+ if (!((lang_input_statement_type *) i->owner->usrdata)->just_syms_flag
+ && (i->flags & SEC_EXCLUDE) == 0)
{
unsigned int alignment_needed;
asection *o;
}
else
{
+ int align;
+
if (os->addr_tree == NULL)
{
/* No address specified for this section, get one
}
newdot = os->region->current;
-
- if (os->section_alignment == -1)
- {
- bfd_vma savedot = newdot;
- newdot = align_power (newdot,
- os->bfd_section->alignment_power);
-
- if (newdot != savedot
- && config.warn_section_align
- && expld.phase != lang_mark_phase_enum)
- einfo (_("%P: warning: changing start of section"
- " %s by %lu bytes\n"),
- os->name, (unsigned long) (newdot - savedot));
- }
+ align = os->bfd_section->alignment_power;
}
+ else
+ align = os->section_alignment;
- /* The section starts here.
- First, align to what the section needs. */
+ /* Align to what the section needs. */
+ if (align > 0)
+ {
+ bfd_vma savedot = newdot;
+ newdot = align_power (newdot, align);
- if (os->section_alignment != -1)
- newdot = align_power (newdot, os->section_alignment);
+ if (newdot != savedot
+ && (config.warn_section_align
+ || os->addr_tree != NULL)
+ && expld.phase != lang_mark_phase_enum)
+ einfo (_("%P: warning: changing start of section"
+ " %s by %lu bytes\n"),
+ os->name, (unsigned long) (newdot - savedot));
+ }
bfd_set_section_vma (0, os->bfd_section, newdot);
}
lang_add_section (&default_common_section->children, s,
- default_common_section, file);
+ default_common_section);
}
}
- else if (ldemul_place_orphan (file, s))
+ else if (ldemul_place_orphan (s))
;
else
{
lang_output_section_statement_type *os;
os = lang_output_section_statement_lookup (s->name);
- lang_add_section (&os->children, s, os, file);
+ lang_add_section (&os->children, s, os);
}
}
}
{
lang_output_section_statement_type *os;
- current_section =
- os =
- lang_output_section_statement_lookup_1 (output_section_statement_name,
- constraint);
+ os = lang_output_section_statement_lookup_1 (output_section_statement_name,
+ constraint);
+ current_section = os;
/* Make next things chain into subchain of this. */
void
lang_final (void)
{
- lang_output_statement_type *new =
- new_stat (lang_output_statement, stat_ptr);
+ lang_output_statement_type *new;
+ new = new_stat (lang_output_statement, stat_ptr);
new->name = output_filename;
}
void
lang_add_target (const char *name)
{
- lang_target_statement_type *new = new_stat (lang_target_statement,
- stat_ptr);
+ lang_target_statement_type *new;
+ new = new_stat (lang_target_statement, stat_ptr);
new->target = name;
-
}
void
void
lang_add_fill (fill_type *fill)
{
- lang_fill_statement_type *new = new_stat (lang_fill_statement,
- stat_ptr);
+ lang_fill_statement_type *new;
+ new = new_stat (lang_fill_statement, stat_ptr);
new->fill = fill;
}
void
lang_add_data (int type, union etree_union *exp)
{
+ lang_data_statement_type *new;
- lang_data_statement_type *new = new_stat (lang_data_statement,
- stat_ptr);
-
+ new = new_stat (lang_data_statement, stat_ptr);
new->exp = exp;
new->type = type;
-
}
/* Create a new reloc statement. RELOC is the BFD relocation type to
lang_assignment_statement_type *
lang_add_assignment (etree_type *exp)
{
- lang_assignment_statement_type *new = new_stat (lang_assignment_statement,
- stat_ptr);
+ lang_assignment_statement_type *new;
+ new = new_stat (lang_assignment_statement, stat_ptr);
new->exp = exp;
return new;
}
void
lang_add_attribute (enum statement_enum attribute)
{
- new_statement (attribute, sizeof (lang_statement_union_type), stat_ptr);
+ new_statement (attribute, sizeof (lang_statement_header_type), stat_ptr);
}
void