This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
reloc address checks
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Tue, 29 Jun 2004 23:12:31 +0930
- Subject: reloc address checks
Reloc address checking the way I should have written it in my 2004-06-24
change. Easier to tweak at some future point, eg. when I set rawsize on
elf linker relaxed sections in order to print size before relaxation.
* bfd-in.h (bfd_get_section_limit): Define.
* reloc.c (bfd_perform_relocation, bfd_install_relocation)
(_bfd_final_link_relocate): Use bfd_get_section_limit.
* aout-tic30.c (tic30_aout_final_link_relocate): Likewise.
* coff-arm.c (coff_arm_relocate_section): Likewise.
* coff-mips.c (mips_refhi_reloc, mips_gprel_reloc): Likewise.
* cpu-ns32k.c (do_ns32k_reloc): Likewise.
(bfd_ns32k_final_link_relocate): Likewise.
* elf32-d30v.c (bfd_elf_d30v_reloc, bfd_elf_d30v_reloc_21): Likwise.
* elf32-dlx.c (_bfd_dlx_elf_hi16_reloc): Likewise.
* elf32-i860.c (i860_howto_pc26_reloc, i860_howto_pc16_reloc)
(i860_howto_highadj_reloc, i860_howto_splitn_reloc): Likewise.
* elf32-m32r.c (m32r_elf_do_10_pcrel_reloc, m32r_elf_hi16_reloc)
(m32r_elf_generic_reloc, m32r_elf_relocate_section): Likewise.
* elf32-m68hc1x.c (m68hc11_elf_special_reloc): Likewise.
* elf32-mips.c (gprel32_with_gp, mips16_gprel_reloc): Likewise.
* elf32-or32.c (or32_elf_consth_reloc): Likewise.
* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Likewise.
* elf32-s390.c (s390_elf_ldisp_reloc): Likewise.
* elf32-sh.c (sh_elf_reloc_loop): Likewise.
* elf32-sparc.c (sparc_elf_wdisp16_reloc): Likewise.
(sparc_elf_hix22_reloc, sparc_elf_lox10_reloc): Likwise.
* elf32-v850.c (v850_elf_reloc): Likewise.
* elf32-xstormy16.c (xstormy16_elf_24_reloc): Likewise.
* elf32-xtensa.c (bfd_elf_xtensa_reloc): Likewise.
* elf64-alpha.c (elf64_alpha_reloc_gpdisp): Likewise.
* elf64-mips.c (mips_elf64_gprel32_reloc)
(mips16_gprel_reloc): Likewise.
* elf64-mmix.c (mmix_elf_reloc): Likewise.
* elf64-s390.c (s390_elf_ldisp_reloc): Likewise.
* elf64-sparc.c (init_insn_reloc): Likewise.
* elfn32-mips.c (gprel32_with_gp, mips16_gprel_reloc): Likewise.
* elfxx-mips.c (_bfd_mips_elf_gprel16_with_gp)
(_bfd_mips_elf_hi16_reloc, _bfd_mips_elf_lo16_reloc)
(_bfd_mips_elf_generic_reloc): Likewise.
* bfd-in2.h: Regenerate.
Index: bfd/aout-tic30.c
===================================================================
RCS file: /cvs/src/src/bfd/aout-tic30.c,v
retrieving revision 1.24
diff -u -p -r1.24 aout-tic30.c
--- bfd/aout-tic30.c 24 Jun 2004 04:46:14 -0000 1.24
+++ bfd/aout-tic30.c 29 Jun 2004 12:50:48 -0000
@@ -402,10 +402,8 @@ tic30_aout_final_link_relocate (howto, i
bfd_vma addend;
{
bfd_vma relocation;
- bfd_size_type sz;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (address > sz)
+ if (address > bfd_get_section_limit (input_bfd, input_section))
return bfd_reloc_outofrange;
relocation = value + addend;
Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.84
diff -u -p -r1.84 bfd-in.h
--- bfd/bfd-in.h 28 Jun 2004 13:57:58 -0000 1.84
+++ bfd/bfd-in.h 29 Jun 2004 12:50:49 -0000
@@ -321,6 +321,10 @@ typedef struct bfd_section *sec_ptr;
#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE), TRUE)
#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE)
#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),TRUE)
+/* Find the address one past the end of SEC. */
+#define bfd_get_section_limit(bfd, sec) \
+ (((sec)->rawsize ? (sec)->rawsize : (sec)->size) \
+ / bfd_octets_per_byte (bfd))
typedef struct stat stat_type;
Index: bfd/coff-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-arm.c,v
retrieving revision 1.52
diff -u -p -r1.52 coff-arm.c
--- bfd/coff-arm.c 24 Jun 2004 04:46:15 -0000 1.52
+++ bfd/coff-arm.c 29 Jun 2004 12:50:55 -0000
@@ -1202,6 +1202,7 @@ coff_arm_relocate_section (output_bfd, i
{
struct internal_reloc * rel;
struct internal_reloc * relend;
+ bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
rel = relocs;
relend = rel + input_section->reloc_count;
@@ -1635,12 +1636,8 @@ coff_arm_relocate_section (output_bfd, i
code. */
bfd_vma address = rel->r_vaddr - input_section->vma;
- bfd_size_type sz;
- sz = (input_section->rawsize
- ? input_section->rawsize
- : input_section->size);
- if (address > sz)
+ if (address > high_address)
rstat = bfd_reloc_outofrange;
else
{
Index: bfd/coff-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-mips.c,v
retrieving revision 1.25
diff -u -p -r1.25 coff-mips.c
--- bfd/coff-mips.c 24 Jun 2004 04:46:15 -0000 1.25
+++ bfd/coff-mips.c 29 Jun 2004 12:50:55 -0000
@@ -473,7 +473,6 @@ mips_refhi_reloc (abfd,
{
bfd_reloc_status_type ret;
bfd_vma relocation;
- bfd_size_type sz;
struct mips_hi *n;
/* If we're relocating, and this an external symbol, we don't want
@@ -500,8 +499,7 @@ mips_refhi_reloc (abfd,
relocation += symbol->section->output_offset;
relocation += reloc_entry->addend;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Save the information, and let REFLO do the actual relocation. */
@@ -610,7 +608,6 @@ mips_gprel_reloc (abfd,
bfd_boolean relocatable;
bfd_vma gp;
bfd_vma relocation;
- bfd_size_type sz;
unsigned long val;
unsigned long insn;
@@ -700,8 +697,7 @@ mips_gprel_reloc (abfd,
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
Index: bfd/cpu-ns32k.c
===================================================================
RCS file: /cvs/src/src/bfd/cpu-ns32k.c,v
retrieving revision 1.14
diff -u -p -r1.14 cpu-ns32k.c
--- bfd/cpu-ns32k.c 24 Jun 2004 04:46:16 -0000 1.14
+++ bfd/cpu-ns32k.c 29 Jun 2004 12:50:57 -0000
@@ -170,7 +170,6 @@ do_ns32k_reloc (abfd, reloc_entry, symbo
bfd_vma relocation;
bfd_reloc_status_type flag = bfd_reloc_ok;
bfd_size_type addr = reloc_entry->address;
- bfd_size_type sz;
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
asection *reloc_target_output_section;
@@ -192,8 +191,7 @@ do_ns32k_reloc (abfd, reloc_entry, symbo
flag = bfd_reloc_undefined;
/* Is the address of the relocation really within the section? */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
@@ -804,11 +802,9 @@ _bfd_ns32k_final_link_relocate (howto, i
bfd_vma addend;
{
bfd_vma relocation;
- bfd_size_type sz;
/* Sanity check the address. */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (address > sz)
+ if (address > bfd_get_section_limit (input_bfd, input_section))
return bfd_reloc_outofrange;
/* This function assumes that we are dealing with a basic relocation
Index: bfd/elf32-d30v.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-d30v.c,v
retrieving revision 1.13
diff -u -p -r1.13 elf32-d30v.c
--- bfd/elf32-d30v.c 24 Jun 2004 04:46:18 -0000 1.13
+++ bfd/elf32-d30v.c 29 Jun 2004 12:50:58 -0000
@@ -266,7 +266,6 @@ bfd_elf_d30v_reloc (abfd, reloc_entry, s
bfd_reloc_status_type r;
asection *reloc_target_output_section;
bfd_size_type addr = reloc_entry->address;
- bfd_size_type sz;
bfd_reloc_status_type flag = bfd_reloc_ok;
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
@@ -291,8 +290,7 @@ bfd_elf_d30v_reloc (abfd, reloc_entry, s
flag = bfd_reloc_undefined;
/* Is the address of the relocation really within the section? */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
@@ -377,7 +375,6 @@ bfd_elf_d30v_reloc_21 (abfd, reloc_entry
bfd_reloc_status_type r;
asection *reloc_target_output_section;
bfd_size_type addr = reloc_entry->address;
- bfd_size_type sz;
bfd_reloc_status_type flag = bfd_reloc_ok;
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
@@ -402,8 +399,7 @@ bfd_elf_d30v_reloc_21 (abfd, reloc_entry
flag = bfd_reloc_undefined;
/* Is the address of the relocation really within the section? */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
Index: bfd/elf32-dlx.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-dlx.c,v
retrieving revision 1.9
diff -u -p -r1.9 elf32-dlx.c
--- bfd/elf32-dlx.c 24 Jun 2004 04:46:18 -0000 1.9
+++ bfd/elf32-dlx.c 29 Jun 2004 12:50:58 -0000
@@ -257,7 +257,6 @@ _bfd_dlx_elf_hi16_reloc (abfd, reloc_ent
{
bfd_reloc_status_type ret;
bfd_vma relocation;
- bfd_size_type sz;
/* If the skip flag is set then we simply do the generic relocating, this
is more of a hack for dlx gas/gld, so we do not need to do the %hi/%lo
@@ -308,8 +307,7 @@ _bfd_dlx_elf_hi16_reloc (abfd, reloc_ent
relocation += reloc_entry->addend;
relocation += bfd_get_16 (abfd, (bfd_byte *)data + reloc_entry->address);
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
#if 0
Index: bfd/elf32-i860.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i860.c,v
retrieving revision 1.31
diff -u -p -r1.31 elf32-i860.c
--- bfd/elf32-i860.c 24 Jun 2004 04:46:19 -0000 1.31
+++ bfd/elf32-i860.c 29 Jun 2004 12:50:58 -0000
@@ -38,7 +38,6 @@ i860_howto_pc26_reloc (bfd *abfd ATTRIBU
{
bfd_vma insn;
bfd_vma relocation;
- bfd_size_type sz;
bfd_byte *addr;
if (output_bfd != NULL
@@ -64,8 +63,7 @@ i860_howto_pc26_reloc (bfd *abfd ATTRIBU
relocation += symbol->section->output_offset;
relocation += reloc_entry->addend;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Adjust for PC-relative relocation. */
@@ -103,7 +101,6 @@ i860_howto_pc16_reloc (bfd *abfd,
{
bfd_vma insn;
bfd_vma relocation;
- bfd_size_type sz;
bfd_byte *addr;
if (output_bfd != NULL
@@ -129,8 +126,7 @@ i860_howto_pc16_reloc (bfd *abfd,
relocation += symbol->section->output_offset;
relocation += reloc_entry->addend;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Adjust for PC-relative relocation. */
@@ -169,7 +165,6 @@ i860_howto_highadj_reloc (bfd *abfd,
{
bfd_vma insn;
bfd_vma relocation;
- bfd_size_type sz;
bfd_byte *addr;
if (output_bfd != NULL
@@ -196,8 +191,7 @@ i860_howto_highadj_reloc (bfd *abfd,
relocation += reloc_entry->addend;
relocation += 0x8000;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
addr = (bfd_byte *) data + reloc_entry->address;
@@ -224,7 +218,6 @@ i860_howto_splitn_reloc (bfd *abfd,
{
bfd_vma insn;
bfd_vma relocation;
- bfd_size_type sz;
bfd_byte *addr;
if (output_bfd != NULL
@@ -250,8 +243,7 @@ i860_howto_splitn_reloc (bfd *abfd,
relocation += symbol->section->output_offset;
relocation += reloc_entry->addend;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
addr = (bfd_byte *) data + reloc_entry->address;
Index: bfd/elf32-m32r.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m32r.c,v
retrieving revision 1.46
diff -u -p -r1.46 elf32-m32r.c
--- bfd/elf32-m32r.c 25 Jun 2004 16:11:07 -0000 1.46
+++ bfd/elf32-m32r.c 29 Jun 2004 12:51:01 -0000
@@ -901,13 +901,11 @@ m32r_elf_do_10_pcrel_reloc (abfd, howto,
bfd_vma addend;
{
bfd_signed_vma relocation;
- bfd_size_type sz;
unsigned long x;
bfd_reloc_status_type status;
/* Sanity check the address (offset in section). */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (offset > sz)
+ if (offset > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = symbol_value + addend;
@@ -972,7 +970,6 @@ m32r_elf_hi16_reloc (abfd, reloc_entry,
{
bfd_reloc_status_type ret;
bfd_vma relocation;
- bfd_size_type sz;
struct m32r_hi16 *n;
/* This part is from bfd_elf_generic_reloc.
@@ -987,8 +984,7 @@ m32r_elf_hi16_reloc (abfd, reloc_entry,
}
/* Sanity check the address (offset in section). */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
ret = bfd_reloc_ok;
@@ -1141,7 +1137,6 @@ m32r_elf_generic_reloc (input_bfd, reloc
{
bfd_reloc_status_type ret;
bfd_vma relocation;
- bfd_size_type sz;
bfd_byte *inplace_address;
/* This part is from bfd_elf_generic_reloc.
@@ -1162,8 +1157,7 @@ m32r_elf_generic_reloc (input_bfd, reloc
a section relative addend which is wrong. */
/* Sanity check the address (offset in section). */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
return bfd_reloc_outofrange;
ret = bfd_reloc_ok;
@@ -2578,6 +2572,7 @@ m32r_elf_relocate_section (output_bfd, i
bfd *dynobj;
bfd_vma *local_got_offsets;
asection *sgot, *splt, *sreloc;
+ bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
dynobj = htab->root.dynobj;
local_got_offsets = elf_local_got_offsets (input_bfd);
@@ -2695,7 +2690,6 @@ m32r_elf_relocate_section (output_bfd, i
else
{
bfd_vma relocation;
- bfd_size_type sz;
/* This is a final link. */
sym = NULL;
@@ -2830,10 +2824,7 @@ m32r_elf_relocate_section (output_bfd, i
}
/* Sanity check the address. */
- sz = (input_section->rawsize
- ? input_section->rawsize
- : input_section->size);
- if (offset > input_section->size)
+ if (offset > high_address)
{
r = bfd_reloc_outofrange;
goto check_reloc;
Index: bfd/elf32-m68hc1x.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m68hc1x.c,v
retrieving revision 1.14
diff -u -p -r1.14 elf32-m68hc1x.c
--- bfd/elf32-m68hc1x.c 24 Jun 2004 04:46:20 -0000 1.14
+++ bfd/elf32-m68hc1x.c 29 Jun 2004 12:51:02 -0000
@@ -790,8 +790,6 @@ m68hc11_elf_special_reloc (bfd *abfd ATT
bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
- bfd_size_type sz;
-
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0
&& (! reloc_entry->howto->partial_inplace
@@ -804,8 +802,7 @@ m68hc11_elf_special_reloc (bfd *abfd ATT
if (output_bfd != NULL)
return bfd_reloc_continue;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
abort();
Index: bfd/elf32-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-mips.c,v
retrieving revision 1.177
diff -u -p -r1.177 elf32-mips.c
--- bfd/elf32-mips.c 24 Jun 2004 04:46:20 -0000 1.177
+++ bfd/elf32-mips.c 29 Jun 2004 12:51:03 -0000
@@ -824,7 +824,6 @@ gprel32_with_gp (bfd *abfd, asymbol *sym
{
bfd_vma relocation;
bfd_vma val;
- bfd_size_type sz;
if (bfd_is_com_section (symbol->section))
relocation = 0;
@@ -834,8 +833,7 @@ gprel32_with_gp (bfd *abfd, asymbol *sym
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Set val to the offset into the section or symbol. */
@@ -943,7 +941,6 @@ mips16_gprel_reloc (bfd *abfd, arelent *
unsigned short insn = 0;
bfd_signed_vma val;
bfd_vma relocation;
- bfd_size_type sz;
/* If we're relocating, and this is an external symbol, we don't want
to change anything. */
@@ -968,8 +965,7 @@ mips16_gprel_reloc (bfd *abfd, arelent *
if (ret != bfd_reloc_ok)
return ret;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
if (bfd_is_com_section (symbol->section))
Index: bfd/elf32-or32.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-or32.c,v
retrieving revision 1.6
diff -u -p -r1.6 elf32-or32.c
--- bfd/elf32-or32.c 24 Jun 2004 04:46:20 -0000 1.6
+++ bfd/elf32-or32.c 29 Jun 2004 12:51:03 -0000
@@ -400,7 +400,6 @@ or32_elf_consth_reloc (abfd, reloc_entry
{
bfd_reloc_status_type ret;
bfd_vma relocation;
- bfd_size_type sz;
struct or32_consth *n;
ret = bfd_reloc_ok;
@@ -418,8 +417,7 @@ or32_elf_consth_reloc (abfd, reloc_entry
relocation += symbol->section->output_offset;
relocation += reloc_entry->addend;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Save the information, and let LO16 do the actual relocation. */
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.122
diff -u -p -r1.122 elf32-ppc.c
--- bfd/elf32-ppc.c 24 Jun 2004 04:46:20 -0000 1.122
+++ bfd/elf32-ppc.c 29 Jun 2004 12:51:06 -0000
@@ -2157,7 +2157,6 @@ ppc_elf_addr16_ha_reloc (bfd *abfd ATTRI
char **error_message ATTRIBUTE_UNUSED)
{
bfd_vma relocation;
- bfd_size_type sz;
if (output_bfd != NULL)
{
@@ -2165,8 +2164,7 @@ ppc_elf_addr16_ha_reloc (bfd *abfd ATTRI
return bfd_reloc_ok;
}
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
if (bfd_is_com_section (symbol->section))
Index: bfd/elf32-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-s390.c,v
retrieving revision 1.62
diff -u -p -r1.62 elf32-s390.c
--- bfd/elf32-s390.c 24 Jun 2004 04:46:21 -0000 1.62
+++ bfd/elf32-s390.c 29 Jun 2004 12:51:09 -0000
@@ -398,7 +398,6 @@ s390_elf_ldisp_reloc (abfd, reloc_entry,
reloc_howto_type *howto = reloc_entry->howto;
bfd_vma relocation;
bfd_vma insn;
- bfd_size_type sz;
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0
@@ -412,8 +411,7 @@ s390_elf_ldisp_reloc (abfd, reloc_entry,
if (output_bfd != NULL)
return bfd_reloc_continue;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = (symbol->value
Index: bfd/elf32-sh.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sh.c,v
retrieving revision 1.107
diff -u -p -r1.107 elf32-sh.c
--- bfd/elf32-sh.c 24 Jun 2004 04:46:21 -0000 1.107
+++ bfd/elf32-sh.c 29 Jun 2004 12:51:11 -0000
@@ -1843,12 +1843,10 @@ sh_elf_reloc_loop (int r_type ATTRIBUTE_
bfd_byte *start_ptr, *ptr, *last_ptr;
int diff, cum_diff;
bfd_signed_vma x;
- bfd_size_type sz;
int insn;
/* Sanity check the address. */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (addr > sz)
+ if (addr > bfd_get_section_limit (input_bfd, input_section))
return bfd_reloc_outofrange;
/* We require the start and end relocations to be processed consecutively -
Index: bfd/elf32-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sparc.c,v
retrieving revision 1.69
diff -u -p -r1.69 elf32-sparc.c
--- bfd/elf32-sparc.c 24 Jun 2004 04:46:21 -0000 1.69
+++ bfd/elf32-sparc.c 29 Jun 2004 12:51:13 -0000
@@ -374,7 +374,6 @@ sparc_elf_wdisp16_reloc (abfd,
{
bfd_vma relocation;
bfd_vma x;
- bfd_size_type sz;
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0
@@ -388,8 +387,7 @@ sparc_elf_wdisp16_reloc (abfd,
if (output_bfd != NULL)
return bfd_reloc_continue;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = (symbol->value
@@ -432,7 +430,6 @@ sparc_elf_hix22_reloc (abfd,
{
bfd_vma relocation;
bfd_vma insn;
- bfd_size_type sz;
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0)
@@ -444,8 +441,7 @@ sparc_elf_hix22_reloc (abfd,
if (output_bfd != NULL)
return bfd_reloc_continue;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = (symbol->value
@@ -480,7 +476,6 @@ sparc_elf_lox10_reloc (abfd,
{
bfd_vma relocation;
bfd_vma insn;
- bfd_size_type sz;
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0)
@@ -492,8 +487,7 @@ sparc_elf_lox10_reloc (abfd,
if (output_bfd != NULL)
return bfd_reloc_continue;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = (symbol->value
Index: bfd/elf32-v850.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-v850.c,v
retrieving revision 1.44
diff -u -p -r1.44 elf32-v850.c
--- bfd/elf32-v850.c 24 Jun 2004 04:46:21 -0000 1.44
+++ bfd/elf32-v850.c 29 Jun 2004 12:51:14 -0000
@@ -1334,7 +1334,6 @@ v850_elf_reloc (abfd, reloc, symbol, dat
bfd *obfd;
char **err ATTRIBUTE_UNUSED;
{
- bfd_size_type sz;
long relocation;
/* If there is an output BFD,
@@ -1360,8 +1359,7 @@ v850_elf_reloc (abfd, reloc, symbol, dat
/* We handle final linking of some relocs ourselves. */
/* Is the address of the relocation really within the section? */
- sz = isection->rawsize ? isection->rawsize : isection->size;
- if (reloc->address > sz)
+ if (reloc->address > bfd_get_section_limit (abfd, isection))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
Index: bfd/elf32-xstormy16.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xstormy16.c,v
retrieving revision 1.27
diff -u -p -r1.27 elf32-xstormy16.c
--- bfd/elf32-xstormy16.c 24 Jun 2004 04:46:21 -0000 1.27
+++ bfd/elf32-xstormy16.c 29 Jun 2004 12:51:14 -0000
@@ -372,7 +372,6 @@ xstormy16_elf_24_reloc (abfd, reloc_entr
char **error_message ATTRIBUTE_UNUSED;
{
bfd_vma relocation, x;
- bfd_size_type sz;
if (output_bfd != NULL)
{
@@ -380,8 +379,7 @@ xstormy16_elf_24_reloc (abfd, reloc_entr
return bfd_reloc_ok;
}
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
if (bfd_is_com_section (symbol->section))
Index: bfd/elf32-xtensa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xtensa.c,v
retrieving revision 1.28
diff -u -p -r1.28 elf32-xtensa.c
--- bfd/elf32-xtensa.c 24 Jun 2004 04:46:21 -0000 1.28
+++ bfd/elf32-xtensa.c 29 Jun 2004 12:51:17 -0000
@@ -1650,7 +1650,6 @@ bfd_elf_xtensa_reloc (abfd, reloc_entry,
bfd_vma relocation;
bfd_reloc_status_type flag;
bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
- bfd_size_type sz;
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
asection *reloc_target_output_section;
@@ -1675,8 +1674,7 @@ bfd_elf_xtensa_reloc (abfd, reloc_entry,
}
/* Is the address of the relocation really within the section? */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz / bfd_octets_per_byte (abfd))
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
Index: bfd/elf64-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-alpha.c,v
retrieving revision 1.120
diff -u -p -r1.120 elf64-alpha.c
--- bfd/elf64-alpha.c 24 Jun 2004 04:46:21 -0000 1.120
+++ bfd/elf64-alpha.c 29 Jun 2004 12:51:20 -0000
@@ -1036,7 +1036,7 @@ elf64_alpha_reloc_gpdisp (abfd, reloc_en
{
bfd_reloc_status_type ret;
bfd_vma gp, relocation;
- bfd_size_type sz;
+ bfd_vma high_address;
bfd_byte *p_ldah, *p_lda;
/* Don't do anything if we're not doing a final link. */
@@ -1046,9 +1046,9 @@ elf64_alpha_reloc_gpdisp (abfd, reloc_en
return bfd_reloc_ok;
}
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz
- || reloc_entry->address + reloc_entry->addend > sz)
+ high_address = bfd_get_section_limit (abfd, input_section);
+ if (reloc_entry->address > high_address
+ || reloc_entry->address + reloc_entry->addend > high_address)
return bfd_reloc_outofrange;
/* The gp used in the portion of the output object to which this
Index: bfd/elf64-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-mips.c,v
retrieving revision 1.60
diff -u -p -r1.60 elf64-mips.c
--- bfd/elf64-mips.c 24 Jun 2004 04:46:21 -0000 1.60
+++ bfd/elf64-mips.c 29 Jun 2004 12:51:21 -0000
@@ -1588,7 +1588,6 @@ mips_elf64_gprel32_reloc (bfd *abfd, are
bfd_vma gp;
bfd_vma relocation;
bfd_vma val;
- bfd_size_type sz;
/* If we're relocating, and this is an external symbol, we don't want
to change anything. */
@@ -1622,8 +1621,7 @@ mips_elf64_gprel32_reloc (bfd *abfd, are
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Set val to the offset into the section or symbol. */
@@ -1714,7 +1712,6 @@ mips16_gprel_reloc (bfd *abfd, arelent *
unsigned short insn = 0;
bfd_signed_vma val;
bfd_vma relocation;
- bfd_size_type sz;
/* If we're relocating, and this is an external symbol with no
addend, we don't want to change anything. */
@@ -1739,8 +1736,7 @@ mips16_gprel_reloc (bfd *abfd, arelent *
if (ret != bfd_reloc_ok)
return ret;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
if (bfd_is_com_section (symbol->section))
Index: bfd/elf64-mmix.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-mmix.c,v
retrieving revision 1.36
diff -u -p -r1.36 elf64-mmix.c
--- bfd/elf64-mmix.c 24 Jun 2004 04:46:22 -0000 1.36
+++ bfd/elf64-mmix.c 29 Jun 2004 12:51:23 -0000
@@ -1261,7 +1258,6 @@ mmix_elf_reloc (abfd, reloc_entry, symbo
bfd_reloc_status_type flag = bfd_reloc_ok;
bfd_vma output_base = 0;
bfd_vma addr;
- bfd_size_type sz;
r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
input_section, output_bfd, error_message);
@@ -1277,8 +1273,7 @@ mmix_elf_reloc (abfd, reloc_entry, symbo
return bfd_reloc_undefined;
/* Is the address of the relocation really within the section? */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
Index: bfd/elf64-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-s390.c,v
retrieving revision 1.62
diff -u -p -r1.62 elf64-s390.c
--- bfd/elf64-s390.c 24 Jun 2004 04:46:22 -0000 1.62
+++ bfd/elf64-s390.c 29 Jun 2004 12:51:25 -0000
@@ -420,7 +420,6 @@ s390_elf_ldisp_reloc (abfd, reloc_entry,
reloc_howto_type *howto = reloc_entry->howto;
bfd_vma relocation;
bfd_vma insn;
- bfd_size_type sz;
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0
@@ -433,8 +432,7 @@ s390_elf_ldisp_reloc (abfd, reloc_entry,
if (output_bfd != NULL)
return bfd_reloc_continue;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = (symbol->value
Index: bfd/elf64-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-sparc.c,v
retrieving revision 1.92
diff -u -p -r1.92 elf64-sparc.c
--- bfd/elf64-sparc.c 24 Jun 2004 04:46:22 -0000 1.92
+++ bfd/elf64-sparc.c 29 Jun 2004 12:51:26 -0000
@@ -794,7 +794,6 @@ init_insn_reloc (abfd,
bfd_vma *pinsn;
{
bfd_vma relocation;
- bfd_size_type sz;
reloc_howto_type *howto = reloc_entry->howto;
if (output_bfd != (bfd *) NULL
@@ -810,8 +809,7 @@ init_insn_reloc (abfd,
if (output_bfd != NULL)
return bfd_reloc_continue;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = (symbol->value
Index: bfd/elfn32-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfn32-mips.c,v
retrieving revision 1.19
diff -u -p -r1.19 elfn32-mips.c
--- bfd/elfn32-mips.c 24 Jun 2004 04:46:23 -0000 1.19
+++ bfd/elfn32-mips.c 29 Jun 2004 12:51:27 -0000
@@ -1415,7 +1415,6 @@ gprel32_with_gp (bfd *abfd, asymbol *sym
void *data, bfd_vma gp)
{
bfd_vma relocation;
- bfd_size_type sz;
unsigned long val;
if (bfd_is_com_section (symbol->section))
@@ -1426,8 +1425,7 @@ gprel32_with_gp (bfd *abfd, asymbol *sym
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
if (reloc_entry->howto->src_mask == 0)
@@ -1508,7 +1506,6 @@ mips16_gprel_reloc (bfd *abfd, arelent *
unsigned short insn = 0;
bfd_signed_vma val;
bfd_vma relocation;
- bfd_size_type sz;
if (output_bfd != NULL)
relocatable = TRUE;
@@ -1523,8 +1520,7 @@ mips16_gprel_reloc (bfd *abfd, arelent *
if (ret != bfd_reloc_ok)
return ret;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
if (bfd_is_com_section (symbol->section))
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.104
diff -u -p -r1.104 elfxx-mips.c
--- bfd/elfxx-mips.c 24 Jun 2004 04:46:23 -0000 1.104
+++ bfd/elfxx-mips.c 29 Jun 2004 12:51:33 -0000
@@ -1068,7 +1068,6 @@ _bfd_mips_elf_gprel16_with_gp (bfd *abfd
{
bfd_vma relocation;
bfd_signed_vma val;
- bfd_size_type sz;
bfd_reloc_status_type status;
if (bfd_is_com_section (symbol->section))
@@ -1079,8 +1078,7 @@ _bfd_mips_elf_gprel16_with_gp (bfd *abfd
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Set val to the offset into the section or symbol. */
@@ -1145,10 +1143,8 @@ _bfd_mips_elf_hi16_reloc (bfd *abfd ATTR
char **error_message ATTRIBUTE_UNUSED)
{
struct mips_hi16 *n;
- bfd_size_type sz;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
n = bfd_malloc (sizeof *n);
@@ -1198,10 +1194,8 @@ _bfd_mips_elf_lo16_reloc (bfd *abfd, are
bfd *output_bfd, char **error_message)
{
bfd_vma vallo;
- bfd_size_type sz;
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
vallo = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
@@ -1250,14 +1244,12 @@ _bfd_mips_elf_generic_reloc (bfd *abfd A
char **error_message ATTRIBUTE_UNUSED)
{
bfd_signed_vma val;
- bfd_size_type sz;
bfd_reloc_status_type status;
bfd_boolean relocatable;
relocatable = (output_bfd != NULL);
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz)
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Build up the field adjustment in VAL. */
Index: bfd/reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.105
diff -u -p -r1.105 reloc.c
--- bfd/reloc.c 25 Jun 2004 16:11:07 -0000 1.105
+++ bfd/reloc.c 29 Jun 2004 12:51:36 -0000
@@ -587,7 +587,6 @@ bfd_perform_relocation (bfd *abfd,
{
bfd_vma relocation;
bfd_reloc_status_type flag = bfd_reloc_ok;
- bfd_size_type sz;
bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
@@ -624,8 +623,7 @@ bfd_perform_relocation (bfd *abfd,
}
/* Is the address of the relocation really within the section? */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz / bfd_octets_per_byte (abfd))
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
@@ -981,7 +979,6 @@ bfd_install_relocation (bfd *abfd,
{
bfd_vma relocation;
bfd_reloc_status_type flag = bfd_reloc_ok;
- bfd_size_type sz;
bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
bfd_vma output_base = 0;
reloc_howto_type *howto = reloc_entry->howto;
@@ -1015,8 +1012,7 @@ bfd_install_relocation (bfd *abfd,
}
/* Is the address of the relocation really within the section? */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (reloc_entry->address > sz / bfd_octets_per_byte (abfd))
+ if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
@@ -1350,11 +1346,9 @@ _bfd_final_link_relocate (reloc_howto_ty
bfd_vma addend)
{
bfd_vma relocation;
- bfd_size_type sz;
/* Sanity check the address. */
- sz = input_section->rawsize ? input_section->rawsize : input_section->size;
- if (address > sz)
+ if (address > bfd_get_section_limit (input_bfd, input_section))
return bfd_reloc_outofrange;
/* This function assumes that we are dealing with a basic relocation
--
Alan Modra
IBM OzLabs - Linux Technology Centre