aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2000-01-13 22:10:36 +0000
committerNick Clifton <nickc@redhat.com>2000-01-13 22:10:36 +0000
commit9a968f43323ca8e2e800d0382bac9fbf9ad9b396 (patch)
treee849045af355b8a60a7a21fea3575bafcf380ec3
parentf45fbf876deab0568bd359788dbdaeabf4f22967 (diff)
downloadgdb-9a968f43323ca8e2e800d0382bac9fbf9ad9b396.zip
gdb-9a968f43323ca8e2e800d0382bac9fbf9ad9b396.tar.gz
gdb-9a968f43323ca8e2e800d0382bac9fbf9ad9b396.tar.bz2
Apply Tim walls octest vs bytes patch
-rw-r--r--bfd/ChangeLog31
-rw-r--r--bfd/archures.c52
-rw-r--r--bfd/bfd-in2.h24
-rw-r--r--bfd/coffgen.c7
-rw-r--r--bfd/cofflink.c9
-rw-r--r--bfd/linker.c12
-rw-r--r--bfd/reloc.c33
-rw-r--r--bfd/section.c19
-rw-r--r--bfd/srec.c21
9 files changed, 155 insertions, 53 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 2887aed..ff57158 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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
diff --git a/bfd/archures.c b/bfd/archures.c
index dac223a..95d5d39 100644
--- a/bfd/archures.c
+++ b/bfd/archures.c
@@ -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;
+}
+
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 93c9b7e..a9b981c 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -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 */
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 547a15f..9884e92 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -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,
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index 1ab416d..1ad7c98 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -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;
diff --git a/bfd/linker.c b/bfd/linker.c
index edf96fe..cd7c4e1 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -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;
diff --git a/bfd/reloc.c b/bfd/reloc.c
index a0db15f..856994b 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -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)
{
diff --git a/bfd/section.c b/bfd/section.c
index e2ca443..c0bf60d 100644
--- a/bfd/section.c
+++ b/bfd/section.c
@@ -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.
diff --git a/bfd/srec.c b/bfd/srec.c
index aefdc64..bce2efe 100644
--- a/bfd/srec.c
+++ b/bfd/srec.c
@@ -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;