Add octets vs bytes functionality to LD.

This commit is contained in:
Timothy Wall
2000-02-03 18:24:46 +00:00
parent bea9907b2a
commit 4cbfc3ac19
3 changed files with 106 additions and 51 deletions

View File

@ -1,3 +1,24 @@
2000-02-03 Timothy Wall <twall@redhat.com>
* ld/ldexp.c (fold_name): Make SIZEOF operator return byte count, not
octet count.
* ld/ldlang.c (print_input_section, print_data_statement,
print_reloc_statement, print_padding_statement): Print target
address values and section sizes as bytes, not octets.
(insert_pad) Calculate padding size in octets, and adjust "dot"
by bytes.
(size_input_section) Always adjust "dot" by bytes, not octets.
(lang_check_section_addresses, lang_do_assignments) Adjust
"dot" by bytes, not octets. Use the larger of the directive size
or octets_per_byte for the number of octets actually allocated in
the output section.
(lang_set_startof) Make sure STARTOF returns a target address.
(lang_one_common) Record size changes in octets.
(lang_abs_symbol_at_end_of) Section end symbol's value is
recorded in target bytes.
* ld.texinfo: Updated description of BYTE, SHORT, LONG, etc.
to be clear about behavior when an octet is smaller than one byte.
2000-01-27 Alan Modra <alan@spri.levels.unisa.edu.au> 2000-01-27 Alan Modra <alan@spri.levels.unisa.edu.au>
* ldcref.c (output_cref): Don't pass message strings to printf * ldcref.c (output_cref): Don't pass message strings to printf

View File

@ -456,11 +456,12 @@ fold_name (tree, current_section, allocation_done, dot)
case SIZEOF: case SIZEOF:
if (allocation_done != lang_first_phase_enum) if (allocation_done != lang_first_phase_enum)
{ {
int opb = bfd_octets_per_byte (output_bfd);
lang_output_section_statement_type *os; lang_output_section_statement_type *os;
os = lang_output_section_find (tree->name.name); os = lang_output_section_find (tree->name.name);
check (os, tree->name.name, "SIZEOF"); check (os, tree->name.name, "SIZEOF");
result = new_abs (os->bfd_section->_raw_size); result = new_abs (os->bfd_section->_raw_size / opb);
} }
else else
result = invalid (); result = invalid ();

View File

@ -2168,7 +2168,8 @@ print_input_section (in)
{ {
asection *i = in->section; asection *i = in->section;
bfd_size_type size = i->_cooked_size != 0 ? i->_cooked_size : i->_raw_size; bfd_size_type size = i->_cooked_size != 0 ? i->_cooked_size : i->_raw_size;
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
if (size != 0) if (size != 0)
{ {
print_space (); print_space ();
@ -2192,7 +2193,7 @@ print_input_section (in)
} }
minfo ("0x%V %W %B\n", minfo ("0x%V %W %B\n",
i->output_section->vma + i->output_offset, size, i->output_section->vma + i->output_offset, size / opb,
i->owner); i->owner);
if (i->_cooked_size != 0 && i->_cooked_size != i->_raw_size) if (i->_cooked_size != 0 && i->_cooked_size != i->_raw_size)
@ -2214,7 +2215,7 @@ print_input_section (in)
bfd_link_hash_traverse (link_info.hash, print_one_symbol, (PTR) i); bfd_link_hash_traverse (link_info.hash, print_one_symbol, (PTR) i);
print_dot = i->output_section->vma + i->output_offset + size; print_dot = i->output_section->vma + i->output_offset + size / opb;
} }
} }
} }
@ -2234,6 +2235,8 @@ print_data_statement (data)
bfd_vma addr; bfd_vma addr;
bfd_size_type size; bfd_size_type size;
const char *name; const char *name;
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
print_space (); print_space ();
@ -2278,7 +2281,8 @@ print_data_statement (data)
print_nl (); print_nl ();
print_dot = addr + size; print_dot = addr + size / opb;
} }
/* Print an address statement. These are generated by options like /* Print an address statement. These are generated by options like
@ -2302,6 +2306,8 @@ print_reloc_statement (reloc)
int i; int i;
bfd_vma addr; bfd_vma addr;
bfd_size_type size; bfd_size_type size;
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++) for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
print_space (); print_space ();
@ -2323,7 +2329,7 @@ print_reloc_statement (reloc)
print_nl (); print_nl ();
print_dot = addr + size; print_dot = addr + size / opb;
} }
static void static void
@ -2332,6 +2338,8 @@ print_padding_statement (s)
{ {
int len; int len;
bfd_vma addr; bfd_vma addr;
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
minfo (" *fill*"); minfo (" *fill*");
@ -2352,7 +2360,7 @@ print_padding_statement (s)
print_nl (); print_nl ();
print_dot = addr + s->size; print_dot = addr + s->size / opb;
} }
static void static void
@ -2547,6 +2555,8 @@ insert_pad (this_ptr, fill, power, output_section_statement, dot)
inserting a magic 'padding' statement. inserting a magic 'padding' statement.
*/ */
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
unsigned int alignment_needed = align_power (dot, power) - dot; unsigned int alignment_needed = align_power (dot, power) - dot;
if (alignment_needed != 0) if (alignment_needed != 0)
@ -2563,7 +2573,7 @@ insert_pad (this_ptr, fill, power, output_section_statement, dot)
new->padding_statement.output_offset = new->padding_statement.output_offset =
dot - output_section_statement->vma; dot - output_section_statement->vma;
new->padding_statement.fill = fill; new->padding_statement.fill = fill;
new->padding_statement.size = alignment_needed; new->padding_statement.size = alignment_needed * opb;
} }
@ -2572,9 +2582,9 @@ insert_pad (this_ptr, fill, power, output_section_statement, dot)
{ {
output_section_statement->alignment_power = power; output_section_statement->alignment_power = power;
} }
output_section_statement->_raw_size += alignment_needed; output_section_statement->_raw_size += alignment_needed * opb;
return alignment_needed + dot;
return dot + alignment_needed;
} }
/* Work out how much this section will move the dot point */ /* Work out how much this section will move the dot point */
@ -2588,6 +2598,8 @@ size_input_section (this_ptr, output_section_statement, fill, dot, relax)
{ {
lang_input_section_type *is = &((*this_ptr)->input_section); lang_input_section_type *is = &((*this_ptr)->input_section);
asection *i = is->section; asection *i = is->section;
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
if (is->ifile->just_syms_flag == false) if (is->ifile->just_syms_flag == false)
{ {
@ -2605,10 +2617,11 @@ size_input_section (this_ptr, output_section_statement, fill, dot, relax)
/* Mark how big the output section must be to contain this now /* Mark how big the output section must be to contain this now
*/ */
if (i->_cooked_size != 0) if (i->_cooked_size != 0)
dot += i->_cooked_size; dot += i->_cooked_size / opb;
else else
dot += i->_raw_size; dot += i->_raw_size / opb;
output_section_statement->bfd_section->_raw_size = dot - output_section_statement->bfd_section->vma; output_section_statement->bfd_section->_raw_size =
(dot - output_section_statement->bfd_section->vma) * opb;
} }
else else
{ {
@ -2629,6 +2642,7 @@ static void
lang_check_section_addresses () lang_check_section_addresses ()
{ {
asection * s; asection * s;
int opb = bfd_octets_per_byte (output_bfd);
/* Scan all sections in the output list. */ /* Scan all sections in the output list. */
for (s = output_bfd->sections; s != NULL; s = s->next) for (s = output_bfd->sections; s != NULL; s = s->next)
@ -2692,6 +2706,9 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
bfd_vma dot; bfd_vma dot;
boolean relax; boolean relax;
{ {
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
/* Size up the sections from their constituent parts. */ /* Size up the sections from their constituent parts. */
for (; s != (lang_statement_union_type *) NULL; s = s->next) for (; s != (lang_statement_union_type *) NULL; s = s->next)
{ {
@ -2805,19 +2822,19 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
(void) lang_size_sections (os->children.head, os, &os->children.head, (void) lang_size_sections (os->children.head, os, &os->children.head,
os->fill, dot, relax); os->fill, dot, relax);
/* Ignore the size of the input sections, use the vma and size to /* put the section within the requested block size, or align at
align against. */ the block boundary */
after = ALIGN_N (os->bfd_section->vma,
after = ALIGN_N (os->bfd_section->vma + os->bfd_section->_raw_size / opb,
os->bfd_section->_raw_size,
/* The coercion here is important, see ld.h. */ /* The coercion here is important, see ld.h. */
(bfd_vma) os->block_value); (bfd_vma) os->block_value);
if (bfd_is_abs_section (os->bfd_section)) if (bfd_is_abs_section (os->bfd_section))
ASSERT (after == os->bfd_section->vma); ASSERT (after == os->bfd_section->vma);
else else
os->bfd_section->_raw_size = after - os->bfd_section->vma; os->bfd_section->_raw_size =
dot = os->bfd_section->vma + os->bfd_section->_raw_size; (after - os->bfd_section->vma) * opb;
dot = os->bfd_section->vma + os->bfd_section->_raw_size / opb;
os->processed = true; os->processed = true;
/* Update dot in the region ? /* Update dot in the region ?
@ -2903,8 +2920,9 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
size = BYTE_SIZE; size = BYTE_SIZE;
break; break;
} }
if (size < opb)
dot += size; size = opb;
dot += size / opb;
output_section_statement->bfd_section->_raw_size += size; output_section_statement->bfd_section->_raw_size += size;
/* The output section gets contents, and then we inspect for /* The output section gets contents, and then we inspect for
any flags set in the input script which override any ALLOC. */ any flags set in the input script which override any ALLOC. */
@ -2924,7 +2942,7 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
s->reloc_statement.output_section = s->reloc_statement.output_section =
output_section_statement->bfd_section; output_section_statement->bfd_section;
size = bfd_get_reloc_size (s->reloc_statement.howto); size = bfd_get_reloc_size (s->reloc_statement.howto);
dot += size; dot += size / opb;
output_section_statement->bfd_section->_raw_size += size; output_section_statement->bfd_section->_raw_size += size;
} }
break; break;
@ -3012,7 +3030,7 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
new->padding_statement.output_offset = new->padding_statement.output_offset =
dot - output_section_statement->bfd_section->vma; dot - output_section_statement->bfd_section->vma;
new->padding_statement.fill = fill; new->padding_statement.fill = fill;
new->padding_statement.size = newdot - dot; new->padding_statement.size = (newdot - dot) * opb;
output_section_statement->bfd_section->_raw_size += output_section_statement->bfd_section->_raw_size +=
new->padding_statement.size; new->padding_statement.size;
} }
@ -3030,7 +3048,7 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
pass than it did at this point in the previous pass. */ pass than it did at this point in the previous pass. */
s->padding_statement.output_offset = s->padding_statement.output_offset =
dot - output_section_statement->bfd_section->vma; dot - output_section_statement->bfd_section->vma;
dot += s->padding_statement.size; dot += s->padding_statement.size / opb;
output_section_statement->bfd_section->_raw_size += output_section_statement->bfd_section->_raw_size +=
s->padding_statement.size; s->padding_statement.size;
break; break;
@ -3063,6 +3081,9 @@ lang_do_assignments (s, output_section_statement, fill, dot)
fill_type fill; fill_type fill;
bfd_vma dot; bfd_vma dot;
{ {
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
for (; s != (lang_statement_union_type *) NULL; s = s->next) for (; s != (lang_statement_union_type *) NULL; s = s->next)
{ {
switch (s->header.type) switch (s->header.type)
@ -3084,7 +3105,8 @@ lang_do_assignments (s, output_section_statement, fill, dot)
dot = os->bfd_section->vma; dot = os->bfd_section->vma;
(void) lang_do_assignments (os->children.head, os, (void) lang_do_assignments (os->children.head, os,
os->fill, dot); os->fill, dot);
dot = os->bfd_section->vma + os->bfd_section->_raw_size; dot = os->bfd_section->vma + os->bfd_section->_raw_size / opb;
} }
if (os->load_base) if (os->load_base)
{ {
@ -3124,22 +3146,28 @@ lang_do_assignments (s, output_section_statement, fill, dot)
if (value.valid_p == false) if (value.valid_p == false)
einfo (_("%F%P: invalid data statement\n")); einfo (_("%F%P: invalid data statement\n"));
} }
{
int size;
switch (s->data_statement.type) switch (s->data_statement.type)
{ {
case QUAD: case QUAD:
case SQUAD: case SQUAD:
dot += QUAD_SIZE; size = QUAD_SIZE;
break; break;
case LONG: case LONG:
dot += LONG_SIZE; size = LONG_SIZE;
break; break;
case SHORT: case SHORT:
dot += SHORT_SIZE; size = SHORT_SIZE;
break; break;
case BYTE: case BYTE:
dot += BYTE_SIZE; size = BYTE_SIZE;
break; break;
} }
if (size < opb)
size = opb;
dot += size / opb;
}
break; break;
case lang_reloc_statement_enum: case lang_reloc_statement_enum:
@ -3153,7 +3181,7 @@ lang_do_assignments (s, output_section_statement, fill, dot)
if (value.valid_p == false) if (value.valid_p == false)
einfo (_("%F%P: invalid reloc statement\n")); einfo (_("%F%P: invalid reloc statement\n"));
} }
dot += bfd_get_reloc_size (s->reloc_statement.howto); dot += bfd_get_reloc_size (s->reloc_statement.howto) / opb;
break; break;
case lang_input_section_enum: case lang_input_section_enum:
@ -3161,9 +3189,9 @@ lang_do_assignments (s, output_section_statement, fill, dot)
asection *in = s->input_section.section; asection *in = s->input_section.section;
if (in->_cooked_size != 0) if (in->_cooked_size != 0)
dot += in->_cooked_size; dot += in->_cooked_size / opb;
else else
dot += in->_raw_size; dot += in->_raw_size / opb;
} }
break; break;
@ -3183,7 +3211,7 @@ lang_do_assignments (s, output_section_statement, fill, dot)
break; break;
case lang_padding_statement_enum: case lang_padding_statement_enum:
dot += s->padding_statement.size; dot += s->padding_statement.size / opb;
break; break;
case lang_group_statement_enum: case lang_group_statement_enum:
@ -3241,11 +3269,13 @@ lang_set_startof ()
h = bfd_link_hash_lookup (link_info.hash, buf, false, false, true); h = bfd_link_hash_lookup (link_info.hash, buf, false, false, true);
if (h != NULL && h->type == bfd_link_hash_undefined) if (h != NULL && h->type == bfd_link_hash_undefined)
{ {
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
h->type = bfd_link_hash_defined; h->type = bfd_link_hash_defined;
if (s->_cooked_size != 0) if (s->_cooked_size != 0)
h->u.def.value = s->_cooked_size; h->u.def.value = s->_cooked_size / opb;
else else
h->u.def.value = s->_raw_size; h->u.def.value = s->_raw_size / opb;
h->u.def.section = bfd_abs_section_ptr; h->u.def.section = bfd_abs_section_ptr;
} }
@ -3422,6 +3452,8 @@ lang_one_common (h, info)
unsigned int power_of_two; unsigned int power_of_two;
bfd_vma size; bfd_vma size;
asection *section; asection *section;
int opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
ldfile_output_machine);
if (h->type != bfd_link_hash_common) if (h->type != bfd_link_hash_common)
return true; return true;
@ -3436,8 +3468,8 @@ lang_one_common (h, info)
section = h->u.c.p->section; section = h->u.c.p->section;
/* Increase the size of the section. */ /* Increase the size of the section. */
section->_cooked_size = ALIGN_N (section->_cooked_size, section->_cooked_size = ALIGN_N ((section->_cooked_size + opb - 1) / opb,
(bfd_size_type) (1 << power_of_two)); (bfd_size_type) (1 << power_of_two)) * opb;
/* Adjust the alignment if necessary. */ /* Adjust the alignment if necessary. */
if (power_of_two > section->alignment_power) if (power_of_two > section->alignment_power)
@ -4297,7 +4329,8 @@ lang_abs_symbol_at_end_of (secname, name)
h->u.def.value = 0; h->u.def.value = 0;
else else
h->u.def.value = (bfd_get_section_vma (output_bfd, sec) h->u.def.value = (bfd_get_section_vma (output_bfd, sec)
+ bfd_section_size (output_bfd, sec)); + bfd_section_size (output_bfd, sec) /
bfd_octets_per_byte (output_bfd));
h->u.def.section = bfd_abs_section_ptr; h->u.def.section = bfd_abs_section_ptr;
} }