+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
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;
+}
+
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;
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 */
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,
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)))
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;
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;
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);
}
}
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;
{
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;
}
/* 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
{
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;
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 ();
{
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;
#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)
{
.
. 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;
.
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.
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;