Support arbitrary length fill patterns.

* linker.c (bfd_new_link_order): Zero all fields with bfd_zalloc.
	(_bfd_default_link_order): Remove bfd_fill_link_order code.
	Call default_data_link_order.
	(default_fill_link_order): Delete.
	(default_data_link_order): New function.
	* elf32-mips.c (_bfd_mips_elf_final_link): Replace occurrences
	of bfd_fill_link_order with bfd_data_link_order.
	* elf64-alpha.c (elf64_alpha_final_link): Likewise.
	* elf64-mips.c (mips_elf64_final_link): Likewise.
This commit is contained in:
Alan Modra
2002-02-15 02:10:35 +00:00
parent 9a1b9f826d
commit fd96f80fc8
5 changed files with 57 additions and 42 deletions

@ -1,5 +1,16 @@
2002-02-15 Alan Modra <amodra@bigpond.net.au> 2002-02-15 Alan Modra <amodra@bigpond.net.au>
Support arbitrary length fill patterns.
* linker.c (bfd_new_link_order): Zero all fields with bfd_zalloc.
(_bfd_default_link_order): Remove bfd_fill_link_order code.
Call default_data_link_order.
(default_fill_link_order): Delete.
(default_data_link_order): New function.
* elf32-mips.c (_bfd_mips_elf_final_link): Replace occurrences
of bfd_fill_link_order with bfd_data_link_order.
* elf64-alpha.c (elf64_alpha_final_link): Likewise.
* elf64-mips.c (mips_elf64_final_link): Likewise.
* bfd.c (bfd_scan_vma): Clamp overflows to max bfd_vma value. * bfd.c (bfd_scan_vma): Clamp overflows to max bfd_vma value.
Correct value returned in "end" for "0x<non-hex>". Correct value returned in "end" for "0x<non-hex>".

@ -5271,7 +5271,7 @@ _bfd_mips_elf_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }
@ -5398,7 +5398,7 @@ _bfd_mips_elf_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }
@ -5554,7 +5554,7 @@ _bfd_mips_elf_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }
@ -5634,7 +5634,7 @@ _bfd_mips_elf_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }

@ -4105,7 +4105,7 @@ elf64_alpha_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }

@ -6518,7 +6518,7 @@ mips_elf64_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }
@ -6655,7 +6655,7 @@ mips_elf64_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }
@ -6734,7 +6734,7 @@ mips_elf64_final_link (abfd, info)
if (p->type != bfd_indirect_link_order) if (p->type != bfd_indirect_link_order)
{ {
if (p->type == bfd_fill_link_order) if (p->type == bfd_data_link_order)
continue; continue;
abort (); abort ();
} }

@ -1,5 +1,5 @@
/* linker.c -- BFD linker routines /* linker.c -- BFD linker routines
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
Free Software Foundation, Inc. Free Software Foundation, Inc.
Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support
@ -426,7 +426,7 @@ static void set_symbol_from_hash
PARAMS ((asymbol *, struct bfd_link_hash_entry *)); PARAMS ((asymbol *, struct bfd_link_hash_entry *));
static boolean generic_add_output_symbol static boolean generic_add_output_symbol
PARAMS ((bfd *, size_t *psymalloc, asymbol *)); PARAMS ((bfd *, size_t *psymalloc, asymbol *));
static boolean default_fill_link_order static boolean default_data_link_order
PARAMS ((bfd *, struct bfd_link_info *, asection *, PARAMS ((bfd *, struct bfd_link_info *, asection *,
struct bfd_link_order *)); struct bfd_link_order *));
static boolean default_indirect_link_order static boolean default_indirect_link_order
@ -2608,14 +2608,13 @@ bfd_new_link_order (abfd, section)
asection *section; asection *section;
{ {
bfd_size_type amt = sizeof (struct bfd_link_order); bfd_size_type amt = sizeof (struct bfd_link_order);
struct bfd_link_order *new = (struct bfd_link_order *) bfd_alloc (abfd, amt); struct bfd_link_order *new;
new = (struct bfd_link_order *) bfd_zalloc (abfd, amt);
if (!new) if (!new)
return NULL; return NULL;
new->type = bfd_undefined_link_order; new->type = bfd_undefined_link_order;
new->offset = 0;
new->size = 0;
new->next = (struct bfd_link_order *) NULL;
if (section->link_order_tail != (struct bfd_link_order *) NULL) if (section->link_order_tail != (struct bfd_link_order *) NULL)
section->link_order_tail->next = new; section->link_order_tail->next = new;
@ -2637,8 +2636,6 @@ _bfd_default_link_order (abfd, info, sec, link_order)
asection *sec; asection *sec;
struct bfd_link_order *link_order; struct bfd_link_order *link_order;
{ {
file_ptr loc;
switch (link_order->type) switch (link_order->type)
{ {
case bfd_undefined_link_order: case bfd_undefined_link_order:
@ -2649,29 +2646,23 @@ _bfd_default_link_order (abfd, info, sec, link_order)
case bfd_indirect_link_order: case bfd_indirect_link_order:
return default_indirect_link_order (abfd, info, sec, link_order, return default_indirect_link_order (abfd, info, sec, link_order,
false); false);
case bfd_fill_link_order:
return default_fill_link_order (abfd, info, sec, link_order);
case bfd_data_link_order: case bfd_data_link_order:
loc = link_order->offset * bfd_octets_per_byte (abfd); return default_data_link_order (abfd, info, sec, link_order);
return bfd_set_section_contents (abfd, sec,
(PTR) link_order->u.data.contents,
loc, link_order->size);
} }
} }
/* Default routine to handle a bfd_fill_link_order. */ /* Default routine to handle a bfd_data_link_order. */
static boolean static boolean
default_fill_link_order (abfd, info, sec, link_order) default_data_link_order (abfd, info, sec, link_order)
bfd *abfd; bfd *abfd;
struct bfd_link_info *info ATTRIBUTE_UNUSED; struct bfd_link_info *info ATTRIBUTE_UNUSED;
asection *sec; asection *sec;
struct bfd_link_order *link_order; struct bfd_link_order *link_order;
{ {
bfd_size_type size; bfd_size_type size;
unsigned char *space; size_t fill_size;
size_t i; bfd_byte *fill;
unsigned int fill;
file_ptr loc; file_ptr loc;
boolean result; boolean result;
@ -2681,24 +2672,37 @@ default_fill_link_order (abfd, info, sec, link_order)
if (size == 0) if (size == 0)
return true; return true;
space = (unsigned char *) bfd_malloc (size); fill = link_order->u.data.contents;
if (space == NULL) fill_size = link_order->u.data.size;
if (fill_size != 0 && fill_size < size)
{
bfd_byte *p;
fill = (bfd_byte *) bfd_malloc (size);
if (fill == NULL)
return false; return false;
p = fill;
fill = link_order->u.fill.value; if (fill_size == 1)
for (i = 0; i < size; i += 4) memset (p, (int) link_order->u.data.contents[0], (size_t) size);
space[i] = fill >> 24; else
for (i = 1; i < size; i += 4) {
space[i] = fill >> 16; do
for (i = 2; i < size; i += 4) {
space[i] = fill >> 8; memcpy (p, link_order->u.data.contents, fill_size);
for (i = 3; i < size; i += 4) p += fill_size;
space[i] = fill; size -= fill_size;
}
while (size >= fill_size);
if (size != 0)
memcpy (p, link_order->u.data.contents, (size_t) size);
size = link_order->size;
}
}
loc = link_order->offset * bfd_octets_per_byte (abfd); loc = link_order->offset * bfd_octets_per_byte (abfd);
result = bfd_set_section_contents (abfd, sec, space, loc, size); result = bfd_set_section_contents (abfd, sec, fill, loc, size);
free (space); if (fill != link_order->u.data.contents)
free (fill);
return result; return result;
} }