This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] R_ARM_ABS16 and R_ARM_ABS8 overflow checking


The attached patch fixes the boundaries of the R_ARM_ABS16 and R_ARM_ABS8 relocs overflow checking according to the ARM documentation.

I tested this patch by running the gas, binutils, and ld testsuites, the latter including a test case I added for this fix.

Please let me know if OK to commit.

Daniel.

ChangeLog:

2009-12-25 Daniel Gutson <dgutson@codesourcery.com>

        bfd/
        * elf32-arm.c (elf32_arm_final_link_relocate): limits
        fixed.

        ld/testsuite/
        * ld-arm/arm-elf.exp (armelftests): New test case added.
        * ld-arm/reloc-boundaries.s: New file.
        * ld-arm/reloc-boundaries.d: New file.


-- Daniel Gutson CodeSourcery www.codesourcery.com
? reloc_boundaries.patch
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.217
diff -u -p -r1.217 elf32-arm.c
--- bfd/elf32-arm.c	11 Dec 2009 13:42:02 -0000	1.217
+++ bfd/elf32-arm.c	25 Dec 2009 20:38:44 -0000
@@ -7212,7 +7212,11 @@ elf32_arm_final_link_relocate (reloc_how
 
     case R_ARM_ABS8:
       value += addend;
-      if ((long) value > 0x7f || (long) value < -0x80)
+
+      /* There is no way to tell whether the user intended to use a signed or
+	 unsigned addend.  When checking for overflow we accept either,
+	 as specified by the AAELF.  */
+      if ((long) value > 0xff || (long) value < -0x80)
 	return bfd_reloc_overflow;
 
       bfd_put_8 (input_bfd, value, hit_data);
@@ -7221,7 +7225,8 @@ elf32_arm_final_link_relocate (reloc_how
     case R_ARM_ABS16:
       value += addend;
 
-      if ((long) value > 0x7fff || (long) value < -0x8000)
+      /* See comment for R_ARM_ABS8.  */
+      if ((long) value > 0xffff || (long) value < -0x8000)
 	return bfd_reloc_overflow;
 
       bfd_put_16 (input_bfd, value, hit_data);
Index: ld/testsuite/ld-arm/arm-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-arm/arm-elf.exp,v
retrieving revision 1.65
diff -u -p -r1.65 arm-elf.exp
--- ld/testsuite/ld-arm/arm-elf.exp	9 Dec 2009 21:42:00 -0000	1.65
+++ ld/testsuite/ld-arm/arm-elf.exp	25 Dec 2009 20:38:45 -0000
@@ -58,7 +58,7 @@ if { ![is_elf_format] || ![istarget "arm
     return
 }
 
-# List contains test-items with 3 items followed by 2 lists:
+# List contains test-items with 3 items followed by 2 lists and one more item:
 # 0:name 1:ld options 2:assembler options
 # 3:filenames of assembler files 4: action and options. 5: name of output file
 
@@ -233,6 +233,9 @@ set armelftests {
     {"callweak" "-static -T arm.ld" "" {callweak.s}
      {{objdump -dr callweak.d}}
      "callweak"}
+    {"Relocation boundaries" "-defsym x=0 -defsym y=0 -defsym _start=0" "" {reloc-boundaries.s}
+     {{objdump -s reloc-boundaries.d}}
+     "reloc-boundaries"}
 }
 
 run_ld_link_tests $armelftests
Index: ld/testsuite/ld-arm/reloc-boundaries.d
===================================================================
RCS file: ld/testsuite/ld-arm/reloc-boundaries.d
diff -N ld/testsuite/ld-arm/reloc-boundaries.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/reloc-boundaries.d	25 Dec 2009 20:38:45 -0000
@@ -0,0 +1,6 @@
+
+[^:]*:     file format elf32-(little|big)arm
+
+Contents of section .text:
+ 8000 80ff0080 ffff                        ......          
+#...
Index: ld/testsuite/ld-arm/reloc-boundaries.s
===================================================================
RCS file: ld/testsuite/ld-arm/reloc-boundaries.s
diff -N ld/testsuite/ld-arm/reloc-boundaries.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/reloc-boundaries.s	25 Dec 2009 20:38:45 -0000
@@ -0,0 +1,5 @@
+.syntax unified
+	.byte	x -128
+	.byte	x +255
+	.short	y -32768
+	.short	y +65535

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]