Apply Tim walls octest vs bytes patch

This commit is contained in:
Nick Clifton 2000-01-13 22:10:36 +00:00
parent f45fbf876d
commit 9a968f4332
9 changed files with 155 additions and 53 deletions

View File

@ -1,3 +1,34 @@
2000-01-13 Timothy Wall (twall@tiac.net>
* archures.c (bfd_octets_per_byte): New function: Return
target byte size.
(bfd_arch_mach_octets_per_byte): New function: Return target
byte size.
* section.c: Distinguish between octets and bytes for usage of
_cooked_size, _raw_size, and output_offset. Clarify
description of bfd_set_section_contents.
* bfd-in2.h: Regenerate.
* coffgen.c: Indicate that the offset parameter is in bytes, not
octets.
* cofflink.c (bfd_coff_link_input_bfd): Use bfd_octets_per_byte
where appropriate to get the octet offset when calling
bfd_set_section_contents.
(bfd_coff_reloc_link_order): Ditto.
* linker.c (bfd_generic_reloc_link_order): Ditto.
(_bfd_default_link_order): Ditto.
* reloc.c (bfd_perform_relocation): Distinguish between octets
and bytes. Use octets when indexing into octet data; use bytes
when calculating target addresses.
(bfd_install_relocation): Ditto.
* srec.c (srec_write_section): Ditto.
2000-01-13 Nick Clifton <nickc@cygnus.com>
* coff-mcore.c (COFF_DEFAULT_SECTION_ALIGNMENT_POWER): Change from

View File

@ -897,9 +897,59 @@ bfd_printable_arch_mach (arch, machine)
enum bfd_architecture arch;
unsigned long machine;
{
const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
const bfd_arch_info_type * ap = bfd_lookup_arch (arch, machine);
if (ap)
return ap->printable_name;
return "UNKNOWN!";
}
/*
FUNCTION
bfd_octets_per_byte
SYNOPSIS
int bfd_octets_per_byte(bfd *abfd);
DESCRIPTION
Return the number of octets (8-bit quantities) per target byte
(minimum addressable unit). In most cases, this will be one, but some
DSP targets have 16, 32, or even 48 bits per byte.
*/
int
bfd_octets_per_byte (abfd)
bfd * abfd;
{
return bfd_arch_mach_octets_per_byte (bfd_get_arch (abfd),
bfd_get_mach (abfd));
}
/*
FUNCTION
bfd_arch_mach_octets_per_byte
SYNOPSIS
int bfd_arch_mach_octets_per_byte(enum bfd_architecture arch,
unsigned long machine);
DESCRIPTION
See bfd_octets_per_byte.
This routine is provided for those cases where a bfd * is not
available
*/
int
bfd_arch_mach_octets_per_byte (arch, mach)
enum bfd_architecture arch;
unsigned long mach;
{
const bfd_arch_info_type * ap = bfd_lookup_arch (arch, mach);
if (ap)
return ap->bits_per_byte / 8;
return 1;
}

View File

@ -1066,22 +1066,25 @@ typedef struct sec
bfd_vma lma;
/* The size of the section in bytes, as it will be output.
contains a value even if the section has no contents (e.g., the
size of <<.bss>>). This will be filled in after relocation */
/* The size of the section in octets, as it will be output.
Contains a value even if the section has no contents (e.g., the
size of <<.bss>>). This will be filled in after relocation. */
bfd_size_type _cooked_size;
/* The original size on disk of the section, in bytes. Normally this
/* The original size on disk of the section, in octets. Normally this
value is the same as the size, but if some relaxing has
been done, then this value will be bigger. */
bfd_size_type _raw_size;
/* If this section is going to be output, then this value is the
offset into the output section of the first byte in the input
section. E.g., if this was going to start at the 100th byte in
the output section, this value would be 100. */
offset in *bytes* into the output section of the first byte in the
input section (byte ==> smallest addressable unit on the
target). In most cases, if this was going to start at the
100th octet (8-bit quantity) in the output section, this value
would be 100. However, if the target byte size is 16 bits
(bfd_octets_per_byte is "2"), this value would be 50. */
bfd_vma output_offset;
@ -1446,6 +1449,13 @@ const char *
bfd_printable_arch_mach
PARAMS ((enum bfd_architecture arch, unsigned long machine));
int
bfd_octets_per_byte PARAMS ((bfd *abfd));
int
bfd_arch_mach_octets_per_byte PARAMS ((enum bfd_architecture arch,
unsigned long machine));
typedef enum bfd_reloc_status
{
/* No errors detected */

View File

@ -2136,10 +2136,9 @@ _bfd_coff_is_local_label_name (abfd, name)
return name[0] == '.' && name[1] == 'L';
}
/* Provided a BFD, a section and an offset into the section, calculate
and return the name of the source file and the line nearest to the
wanted location. */
/* Provided a BFD, a section and an offset (in bytes, not octets) into the
section, calculate and return the name of the source file and the line
nearest to the wanted location. */
/*ARGSUSED*/
boolean
coff_find_nearest_line (abfd, section, symbols, offset, filename_ptr,

View File

@ -2425,7 +2425,10 @@ _bfd_coff_link_input_bfd (finfo, input_bfd)
if (secdata == NULL || secdata->stab_info == NULL)
{
if (! bfd_set_section_contents (output_bfd, o->output_section,
contents, o->output_offset,
contents,
(file_ptr)
(o->output_offset *
bfd_octets_per_byte (output_bfd)),
(o->_cooked_size != 0
? o->_cooked_size
: o->_raw_size)))
@ -2737,7 +2740,9 @@ _bfd_coff_reloc_link_order (output_bfd, finfo, output_section, link_order)
break;
}
ok = bfd_set_section_contents (output_bfd, output_section, (PTR) buf,
(file_ptr) link_order->offset, size);
(file_ptr)
(link_order->offset *
bfd_octets_per_byte (output_bfd)), size);
free (buf);
if (! ok)
return false;

View File

@ -2524,7 +2524,9 @@ _bfd_generic_reloc_link_order (abfd, info, sec, link_order)
break;
}
ok = bfd_set_section_contents (abfd, sec, (PTR) buf,
(file_ptr) link_order->offset, size);
(file_ptr)
(link_order->offset *
bfd_octets_per_byte (abfd)), size);
free (buf);
if (! ok)
return false;
@ -2592,7 +2594,9 @@ _bfd_default_link_order (abfd, info, sec, link_order)
case bfd_data_link_order:
return bfd_set_section_contents (abfd, sec,
(PTR) link_order->u.data.contents,
(file_ptr) link_order->offset,
(file_ptr)
(link_order->offset *
bfd_octets_per_byte (abfd)),
link_order->size);
}
}
@ -2626,7 +2630,9 @@ default_fill_link_order (abfd, info, sec, link_order)
for (i = 1; i < size; i += 2)
space[i] = fill;
result = bfd_set_section_contents (abfd, sec, space,
(file_ptr) link_order->offset,
(file_ptr)
(link_order->offset *
bfd_octets_per_byte (abfd)),
link_order->size);
free (space);
return result;

View File

@ -592,7 +592,7 @@ bfd_perform_relocation (abfd, reloc_entry, data, input_section, output_bfd,
{
bfd_vma relocation;
bfd_reloc_status_type flag = bfd_reloc_ok;
bfd_size_type addr = reloc_entry->address;
bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
asection *reloc_target_output_section;
@ -628,7 +628,8 @@ bfd_perform_relocation (abfd, reloc_entry, data, input_section, output_bfd,
}
/* Is the address of the relocation really within the section? */
if (reloc_entry->address > input_section->_cooked_size)
if (reloc_entry->address > input_section->_cooked_size /
bfd_octets_per_byte (abfd))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targetted at and the
@ -897,41 +898,41 @@ space consuming. For each target:
{
case 0:
{
char x = bfd_get_8 (abfd, (char *) data + addr);
char x = bfd_get_8 (abfd, (char *) data + octets);
DOIT (x);
bfd_put_8 (abfd, x, (unsigned char *) data + addr);
bfd_put_8 (abfd, x, (unsigned char *) data + octets);
}
break;
case 1:
{
short x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
short x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
DOIT (x);
bfd_put_16 (abfd, x, (unsigned char *) data + addr);
bfd_put_16 (abfd, x, (unsigned char *) data + octets);
}
break;
case 2:
{
long x = bfd_get_32 (abfd, (bfd_byte *) data + addr);
long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
DOIT (x);
bfd_put_32 (abfd, x, (bfd_byte *) data + addr);
bfd_put_32 (abfd, x, (bfd_byte *) data + octets);
}
break;
case -2:
{
long x = bfd_get_32 (abfd, (bfd_byte *) data + addr);
long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
relocation = -relocation;
DOIT (x);
bfd_put_32 (abfd, x, (bfd_byte *) data + addr);
bfd_put_32 (abfd, x, (bfd_byte *) data + octets);
}
break;
case -1:
{
long x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
long x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
relocation = -relocation;
DOIT (x);
bfd_put_16 (abfd, x, (bfd_byte *) data + addr);
bfd_put_16 (abfd, x, (bfd_byte *) data + octets);
}
break;
@ -942,9 +943,9 @@ space consuming. For each target:
case 4:
#ifdef BFD64
{
bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data + addr);
bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data + octets);
DOIT (x);
bfd_put_64 (abfd, x, (bfd_byte *) data + addr);
bfd_put_64 (abfd, x, (bfd_byte *) data + octets);
}
#else
abort ();
@ -994,7 +995,7 @@ bfd_install_relocation (abfd, reloc_entry, data_start, data_start_offset,
{
bfd_vma relocation;
bfd_reloc_status_type flag = bfd_reloc_ok;
bfd_size_type addr = reloc_entry->address;
bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
asection *reloc_target_output_section;
@ -1283,7 +1284,7 @@ space consuming. For each target:
#define DOIT(x) \
x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
data = (bfd_byte *) data_start + (addr - data_start_offset);
data = (bfd_byte *) data_start + (octets - data_start_offset);
switch (howto->size)
{

View File

@ -369,22 +369,25 @@ CODE_FRAGMENT
.
. bfd_vma lma;
.
. {* The size of the section in bytes, as it will be output.
. contains a value even if the section has no contents (e.g., the
. size of <<.bss>>). This will be filled in after relocation *}
. {* The size of the section in octets, as it will be output.
. Contains a value even if the section has no contents (e.g., the
. size of <<.bss>>). This will be filled in after relocation. *}
.
. bfd_size_type _cooked_size;
.
. {* The original size on disk of the section, in bytes. Normally this
. {* The original size on disk of the section, in octets. Normally this
. value is the same as the size, but if some relaxing has
. been done, then this value will be bigger. *}
.
. bfd_size_type _raw_size;
.
. {* If this section is going to be output, then this value is the
. offset into the output section of the first byte in the input
. section. E.g., if this was going to start at the 100th byte in
. the output section, this value would be 100. *}
. offset in *bytes* into the output section of the first byte in the
. input section (byte ==> smallest addressable unit on the
. target). In most cases, if this was going to start at the
. 100th octet (8-bit quantity) in the output section, this value
. would be 100. However, if the target byte size is 16 bits
. (bfd_octets_per_byte is "2"), this value would be 50. *}
.
. bfd_vma output_offset;
.
@ -920,7 +923,7 @@ DESCRIPTION
Sets the contents of the section @var{section} in BFD
@var{abfd} to the data starting in memory at @var{data}. The
data is written to the output section starting at offset
@var{offset} for @var{count} bytes.
@var{offset} for @var{count} octets.

View File

@ -1000,31 +1000,28 @@ srec_write_section (abfd, tdata, list)
tdata_type *tdata;
srec_data_list_type *list;
{
unsigned int bytes_written = 0;
unsigned int octets_written = 0;
bfd_byte *location = list->data;
while (bytes_written < list->size)
while (octets_written < list->size)
{
bfd_vma address;
unsigned int octets_this_chunk = list->size - octets_written;
unsigned int bytes_this_chunk = list->size - bytes_written;
if (octets_this_chunk > CHUNK)
octets_this_chunk = CHUNK;
if (bytes_this_chunk > CHUNK)
{
bytes_this_chunk = CHUNK;
}
address = list->where + bytes_written;
address = list->where + octets_written / bfd_octets_per_byte (abfd);
if (! srec_write_record (abfd,
tdata->type,
address,
location,
location + bytes_this_chunk))
location + octets_this_chunk))
return false;
bytes_written += bytes_this_chunk;
location += bytes_this_chunk;
octets_written += octets_this_chunk;
location += octets_this_chunk;
}
return true;