/* Linker command language support.
Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003
+ 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
This file is part of GLD, the Gnu Linker.
}
}
+/* Convert between addresses in bytes and sizes in octets.
+ For currently supported targets, octets_per_byte is always a power
+ of two, so we can use shifts. */
+#define TO_ADDR(X) ((X) >> opb_shift)
+#define TO_SIZE(X) ((X) << opb_shift)
+
+/* Support the above. */
+static unsigned int opb_shift = 0;
+
+static void
+init_opb (void)
+{
+ unsigned x = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
+ ldfile_output_machine);
+ opb_shift = 0;
+ if (x > 1)
+ while ((x & 1) == 0)
+ {
+ x >>= 1;
+ ++opb_shift;
+ }
+ ASSERT (x == 1);
+}
+
/* Open all the input files. */
static void
{
asection *i = in->section;
bfd_size_type size = i->_cooked_size != 0 ? i->_cooked_size : i->_raw_size;
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
+
+ init_opb ();
if (size != 0)
{
print_space ();
}
minfo ("0x%V %W %B\n",
- i->output_section->vma + i->output_offset, size / opb,
+ i->output_section->vma + i->output_offset, TO_ADDR (size),
i->owner);
if (i->_cooked_size != 0 && i->_cooked_size != i->_raw_size)
bfd_link_hash_traverse (link_info.hash, print_one_symbol, i);
- print_dot = i->output_section->vma + i->output_offset + size / opb;
+ print_dot = (i->output_section->vma + i->output_offset
+ + TO_ADDR (size));
}
}
}
bfd_vma addr;
bfd_size_type size;
const char *name;
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
+ init_opb ();
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
print_space ();
print_nl ();
- print_dot = addr + size / opb;
-
+ print_dot = addr + TO_ADDR (size);
}
/* Print an address statement. These are generated by options like
int i;
bfd_vma addr;
bfd_size_type size;
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
+ init_opb ();
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
print_space ();
print_nl ();
- print_dot = addr + size / opb;
+ print_dot = addr + TO_ADDR (size);
}
static void
{
int len;
bfd_vma addr;
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
+ init_opb ();
minfo (" *fill*");
len = sizeof " *fill*" - 1;
print_nl ();
- print_dot = addr + s->size / opb;
+ print_dot = addr + TO_ADDR (s->size);
}
static void
if (!is->ifile->just_syms_flag)
{
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
unsigned int alignment_needed;
asection *o;
if (alignment_needed != 0)
{
- insert_pad (this_ptr, fill, alignment_needed * opb, o, dot);
+ insert_pad (this_ptr, fill, TO_SIZE (alignment_needed), o, dot);
dot += alignment_needed;
}
/* Mark how big the output section must be to contain this now. */
if (i->_cooked_size != 0)
- dot += i->_cooked_size / opb;
+ dot += TO_ADDR (i->_cooked_size);
else
- dot += i->_raw_size / opb;
- o->_raw_size = (dot - o->vma) * opb;
+ dot += TO_ADDR (i->_raw_size);
+ o->_raw_size = TO_SIZE (dot - o->vma);
}
else
{
lang_check_section_addresses (void)
{
asection *s;
- unsigned opb = bfd_octets_per_byte (output_bfd);
/* Scan all sections in the output list. */
for (s = output_bfd->sections; s != NULL; s = s->next)
/* We must check the sections' LMA addresses not their
VMA addresses because overlay sections can have
overlapping VMAs but they must have distinct LMAs. */
- s_start = bfd_section_lma (output_bfd, s);
+ s_start = bfd_section_lma (output_bfd, s);
os_start = bfd_section_lma (output_bfd, os);
- s_end = s_start + bfd_section_size (output_bfd, s) / opb - 1;
- os_end = os_start + bfd_section_size (output_bfd, os) / opb - 1;
+ s_end = s_start + TO_ADDR (bfd_section_size (output_bfd, s)) - 1;
+ os_end = os_start + TO_ADDR (bfd_section_size (output_bfd, os)) - 1;
/* Look for an overlap. */
if ((s_end < os_start) || (s_start > os_end))
bfd_boolean *relax,
bfd_boolean check_regions)
{
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
-
/* Size up the sections from their constituent parts. */
for (; s != NULL; s = s->header.next)
{
/* Put the section within the requested block size, or
align at the block boundary. */
- after = align_n (os->bfd_section->vma
- + os->bfd_section->_raw_size / opb,
- (bfd_vma) os->block_value);
+ after = ((os->bfd_section->vma
+ + TO_ADDR (os->bfd_section->_raw_size)
+ + os->block_value - 1)
+ & - (bfd_vma) os->block_value);
if (bfd_is_abs_section (os->bfd_section))
ASSERT (after == os->bfd_section->vma);
&& ! link_info.relocatable)
os->bfd_section->_raw_size = 0;
else
- os->bfd_section->_raw_size =
- (after - os->bfd_section->vma) * opb;
+ os->bfd_section->_raw_size
+ = TO_SIZE (after - os->bfd_section->vma);
- dot = os->bfd_section->vma + os->bfd_section->_raw_size / opb;
+ dot = os->bfd_section->vma + TO_ADDR (os->bfd_section->_raw_size);
os->processed = TRUE;
if (os->update_dot_tree != 0)
/* Set load_base, which will be handled later. */
os->load_base = exp_intop (os->lma_region->current);
os->lma_region->current +=
- os->bfd_section->_raw_size / opb;
+ TO_ADDR (os->bfd_section->_raw_size);
if (check_regions)
os_region_check (os, os->lma_region, NULL,
os->bfd_section->lma);
size = BYTE_SIZE;
break;
}
- if (size < opb)
- size = opb;
- dot += size / opb;
+ if (size < TO_SIZE ((unsigned) 1))
+ size = TO_SIZE ((unsigned) 1);
+ dot += TO_ADDR (size);
output_section_statement->bfd_section->_raw_size += size;
/* The output section gets contents, and then we inspect for
any flags set in the input script which override any ALLOC. */
s->reloc_statement.output_section =
output_section_statement->bfd_section;
size = bfd_get_reloc_size (s->reloc_statement.howto);
- dot += size / opb;
+ dot += TO_ADDR (size);
output_section_statement->bfd_section->_raw_size += size;
}
break;
/* Insert a pad after this statement. We can't
put the pad before when relaxing, in case the
assignment references dot. */
- insert_pad (&s->header.next, fill, (newdot - dot) * opb,
+ insert_pad (&s->header.next, fill, TO_SIZE (newdot - dot),
output_section_statement->bfd_section, dot);
/* Don't neuter the pad below when relaxing. */
fill_type *fill,
bfd_vma dot)
{
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
-
for (; s != NULL; s = s->header.next)
{
switch (s->header.type)
dot = os->bfd_section->vma;
(void) lang_do_assignments_1 (os->children.head, os,
os->fill, dot);
- dot = os->bfd_section->vma + os->bfd_section->_raw_size / opb;
+ dot = (os->bfd_section->vma
+ + TO_ADDR (os->bfd_section->_raw_size));
}
if (os->load_base)
size = BYTE_SIZE;
break;
}
- if (size < opb)
- size = opb;
- dot += size / opb;
+ if (size < TO_SIZE ((unsigned) 1))
+ size = TO_SIZE ((unsigned) 1);
+ dot += TO_ADDR (size);
}
break;
if (!value.valid_p)
einfo (_("%F%P: invalid reloc statement\n"));
}
- dot += bfd_get_reloc_size (s->reloc_statement.howto) / opb;
+ dot += TO_ADDR (bfd_get_reloc_size (s->reloc_statement.howto));
break;
case lang_input_section_enum:
asection *in = s->input_section.section;
if (in->_cooked_size != 0)
- dot += in->_cooked_size / opb;
+ dot += TO_ADDR (in->_cooked_size);
else
- dot += in->_raw_size / opb;
+ dot += TO_ADDR (in->_raw_size);
}
break;
break;
case lang_padding_statement_enum:
- dot += s->padding_statement.size / opb;
+ dot += TO_ADDR (s->padding_statement.size);
break;
case lang_group_statement_enum:
void
lang_do_assignments (lang_statement_union_type *s,
- lang_output_section_statement_type
- *output_section_statement,
+ lang_output_section_statement_type *output_section_statement,
fill_type *fill,
bfd_vma dot)
{
h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE);
if (h != NULL && h->type == bfd_link_hash_undefined)
{
- unsigned opb;
-
- opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
h->type = bfd_link_hash_defined;
if (s->_cooked_size != 0)
- h->u.def.value = s->_cooked_size / opb;
+ h->u.def.value = TO_ADDR (s->_cooked_size);
else
- h->u.def.value = s->_raw_size / opb;
+ h->u.def.value = TO_ADDR (s->_raw_size);
h->u.def.section = bfd_abs_section_ptr;
}
unsigned int power_of_two;
bfd_vma size;
asection *section;
- unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
- ldfile_output_machine);
if (h->type != bfd_link_hash_common)
return TRUE;
section = h->u.c.p->section;
- /* Increase the size of the section. */
- section->_cooked_size = align_n ((section->_cooked_size + opb - 1) / opb,
- (bfd_vma) 1 << power_of_two) * opb;
+ /* Increase the size of the section to align the common sym. */
+ section->_cooked_size += ((bfd_vma) 1 << (power_of_two + opb_shift)) - 1;
+ section->_cooked_size &= (- (bfd_vma) 1 << (power_of_two + opb_shift));
/* Adjust the alignment if necessary. */
if (power_of_two > section->alignment_power)
lang_enter_output_section_statement (const char *output_section_statement_name,
etree_type *address_exp,
enum section_type sectype,
- bfd_vma block_value,
etree_type *align,
etree_type *subalign,
etree_type *ebase)
os->flags = SEC_NO_FLAGS;
else
os->flags = SEC_NEVER_LOAD;
- os->block_value = block_value ? block_value : 1;
+ os->block_value = 1;
stat_ptr = &os->children;
os->subsection_alignment =
/* Open the output file. */
lang_for_each_statement (ldlang_open_output);
+ init_opb ();
ldemul_create_output_section_statements ();
h->u.def.value = 0;
else
h->u.def.value = (bfd_get_section_vma (output_bfd, sec)
- + bfd_section_size (output_bfd, sec) /
- bfd_octets_per_byte (output_bfd));
+ + TO_ADDR (bfd_section_size (output_bfd, sec)));
h->u.def.section = bfd_abs_section_ptr;
}
etree_type *size;
lang_enter_output_section_statement (name, overlay_vma, normal_section,
- 0, 0, overlay_subalign, 0);
+ 0, overlay_subalign, 0);
/* If this is the first section, then base the VMA of future
sections on this one. This will work correctly even if `.' is