This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[mn10300] fix overflow and jump checks
- From: DJ Delorie <dj at redhat dot com>
- To: binutils at sourceware dot org
- Date: Wed, 9 Jul 2008 17:26:38 -0400
- Subject: [mn10300] fix overflow and jump checks
Alex, Eric,
Ok? I've attached a test case too.
* elf-m10300.c (mn10300_elf_final_link_relocate): Correct overflow
checks for PCREL8 and PCREL16 relocs.
(mn10300_elf_relax_section): Correct jump offset check when target
is in a different section.
Index: elf-m10300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-m10300.c,v
retrieving revision 1.94
diff -p -U3 -r1.94 elf-m10300.c
--- elf-m10300.c 31 Dec 2007 11:29:31 -0000 1.94
+++ elf-m10300.c 9 Jul 2008 21:21:18 -0000
@@ -1212,7 +1212,7 @@ mn10300_elf_final_link_relocate (reloc_h
value -= offset;
value += addend;
- if ((long) value > 0xff || (long) value < -0x100)
+ if ((long) value > 0x7f || (long) value < -0x80)
return bfd_reloc_overflow;
bfd_put_8 (input_bfd, value, hit_data);
@@ -1224,7 +1224,7 @@ mn10300_elf_final_link_relocate (reloc_h
value -= offset;
value += addend;
- if ((long) value > 0xffff || (long) value < -0x10000)
+ if ((long) value > 0x7fff || (long) value < -0x8000)
return bfd_reloc_overflow;
bfd_put_16 (input_bfd, value, hit_data);
@@ -2751,6 +2751,8 @@ mn10300_elf_relax_section (bfd *abfd,
for (irel = internal_relocs; irel < irelend; irel++)
{
bfd_vma symval;
+ bfd_signed_vma jump_offset;
+ asection *sym_sec = NULL;
struct elf32_mn10300_link_hash_entry *h = NULL;
/* If this isn't something that can be relaxed, then ignore
@@ -2790,7 +2792,6 @@ mn10300_elf_relax_section (bfd *abfd,
if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
{
Elf_Internal_Sym *isym;
- asection *sym_sec = NULL;
const char *sym_name;
char *new_name;
@@ -2857,6 +2858,8 @@ mn10300_elf_relax_section (bfd *abfd,
if (h->root.root.u.def.section->output_section == NULL)
continue;
+ sym_sec = h->root.root.u.def.section->output_section;
+
symval = (h->root.root.u.def.value
+ h->root.root.u.def.section->output_section->vma
+ h->root.root.u.def.section->output_offset);
@@ -2959,10 +2962,15 @@ mn10300_elf_relax_section (bfd *abfd,
/* See if the value will fit in 16 bits, note the high value is
0x7fff + 2 as the target will be two bytes closer if we are
- able to relax. */
+ able to relax, if it's in the same section. */
+ if (sec->output_section == sym_sec->output_section)
+ jump_offset = 0x8001;
+ else
+ jump_offset = 0x7fff;
+
/* Account for jumps across alignment boundaries using
align_gap_adjustment. */
- if ((bfd_signed_vma) value < 0x8001 - (bfd_signed_vma) align_gap_adjustment
+ if ((bfd_signed_vma) value < jump_offset - (bfd_signed_vma) align_gap_adjustment
&& ((bfd_signed_vma) value > -0x8000 + (bfd_signed_vma) align_gap_adjustment))
{
unsigned char code;
begin 644 i141456-test.tar.gz
M'XL(`!8L=4@"`^W5ST^#,!0'\%YY?T6/:K+9!V5;4'=1#R9&#_-H8MB`A07&
MLM9DQOB_VX*=[.`\R=2\SX'RX_4=*%^:HT09#GK83]A/$<9`RGI$OQF%&^VI
M'S)$$82^+P=#GPD481`R+E@'GI6.UYRS9+&_;AZ7J6+_#NARE>3KTWS['6PB
M;F5YD?*L6I>QYFF1!7ZO7)HU$@(`KG(5*Y66T^*%5QE7Z4SGU9(_]G6ZT1&`
M6UA^_F3?KAY'8#J*R$MFW-P="7OT%N7*&]55M^:[&-L2&7GF&ACIRN>ZJX/E
M'WUL\H]#&8@F_Q(I_UWPZLR"UY\7U30NO":PT`P1V)#6OP,;43!E+NL?ZMD(
M]JDI7E8KRNY?S;\^6/YEB-O]/Y!-_D-!^>_"Y/KRX>;^;@*OX"+-+[C8B#-H
M1YQ'[G);YYP<U17'[OX;[':R6_QN,_R^&W[=#MOMIDKM;V8*6JW<M"36\?YY
CMJ(U\8W^:X000@@AA!!"""&$$$(((820W^X=Y&ARZ0`H````
`
end