[BFD][AARCH64]Fix MOVW_SABS_G(0,1,2) relocation overflow check.
authorRenlin Li <renlin.li@arm.com>
Fri, 26 Feb 2016 17:52:34 +0000 (17:52 +0000)
committerRenlin Li <renlin.li@arm.com>
Fri, 26 Feb 2016 18:00:15 +0000 (18:00 +0000)
For these three relocations, 17 bit signed value should be used, instead of
16 bit. The bitsize field is changed from 16 to 17, this field in aarch64
backend is used for overflow check only.

bfd/

2016-02-26  Renlin Li  <renlin.li@arm.com>

    * elfnn-aarch64.c (elfNN_aarch64_howto_table): Fix signed overflow
    check for MOVW_SABS_G0, MOVW_SABS_G1, MOVW_SABS_G2.

ld/

2016-02-26  Renlin Li  <renlin.li@arm.com>

    * testsuite/ld-aarch64/aarch64-elf.exp: Run new testcases.
    * testsuite/ld-aarch64/emit-relocs-270.d: Update to use new boundary.
    * testsuite/ld-aarch64/emit-relocs-271.d: Likewise.
    * testsuite/ld-aarch64/emit-relocs-272.d: Likewise.
    * testsuite/ld-aarch64/emit-relocs-270-overflow.d: New.
    * testsuite/ld-aarch64/emit-relocs-270-overflow.s: New.
    * testsuite/ld-aarch64/emit-relocs-271-overflow.d: New.
    * testsuite/ld-aarch64/emit-relocs-271-overflow.s: New.
    * testsuite/ld-aarch64/emit-relocs-272-overflow.d: New.
    * testsuite/ld-aarch64/emit-relocs-272-overflow.s: New.

13 files changed:
bfd/ChangeLog
bfd/elfnn-aarch64.c
ld/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/emit-relocs-270-overflow.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-270-overflow.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-270.d
ld/testsuite/ld-aarch64/emit-relocs-271-overflow.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-271-overflow.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-271.d
ld/testsuite/ld-aarch64/emit-relocs-272-overflow.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-272-overflow.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-272.d

index 0b52c17463ef1bed89348b1b69c0475b89fd1441..8339eae9b32d346385716a1213b1847601a2b4bd 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-26  Renlin Li  <renlin.li@arm.com>
+
+       * elfnn-aarch64.c (elfNN_aarch64_howto_table): Fix signed overflow
+       check for MOVW_SABS_G0, MOVW_SABS_G1, MOVW_SABS_G2.
+
 2016-02-26  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/19609
index 16a6eea92182a90a2a927aafb1c1077290031911..599b5f8516acbd51cc5123af4550f9d689b5d13d 100644 (file)
@@ -575,7 +575,7 @@ static reloc_howto_type elfNN_aarch64_howto_table[] =
   HOWTO (AARCH64_R (MOVW_SABS_G0),     /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        16,                    /* bitsize */
+        17,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed,      /* complain_on_overflow */
@@ -590,7 +590,7 @@ static reloc_howto_type elfNN_aarch64_howto_table[] =
   HOWTO64 (AARCH64_R (MOVW_SABS_G1),   /* type */
         16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        16,                    /* bitsize */
+        17,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed,      /* complain_on_overflow */
@@ -605,7 +605,7 @@ static reloc_howto_type elfNN_aarch64_howto_table[] =
   HOWTO64 (AARCH64_R (MOVW_SABS_G2),   /* type */
         32,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        16,                    /* bitsize */
+        17,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed,      /* complain_on_overflow */
index ef2e60feadc83bb278ed0d87bfaad71af718b240..24a913fd275f7ddacffbea348304ea1b395857d7 100644 (file)
@@ -1,3 +1,16 @@
+2016-02-26  Renlin Li  <renlin.li@arm.com>
+
+       * testsuite/ld-aarch64/aarch64-elf.exp: Run new testcases.
+       * testsuite/ld-aarch64/emit-relocs-270.d: Update to use new boundary.
+       * testsuite/ld-aarch64/emit-relocs-271.d: Likewise.
+       * testsuite/ld-aarch64/emit-relocs-272.d: Likewise.
+       * testsuite/ld-aarch64/emit-relocs-270-overflow.d: New.
+       * testsuite/ld-aarch64/emit-relocs-270-overflow.s: New.
+       * testsuite/ld-aarch64/emit-relocs-271-overflow.d: New.
+       * testsuite/ld-aarch64/emit-relocs-271-overflow.s: New.
+       * testsuite/ld-aarch64/emit-relocs-272-overflow.d: New.
+       * testsuite/ld-aarch64/emit-relocs-272-overflow.s: New.
+
 2016-02-26  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/19609
index d0b33cf5a466690ccb2f6e6d0e4a23dffcaae3b2..37ce48c3c745af6836661b2efa470fa46d899526 100644 (file)
@@ -96,8 +96,11 @@ run_dump_test "emit-relocs-269"
 run_dump_test "emit-relocs-269-bad"
 run_dump_test "emit-relocs-270"
 run_dump_test "emit-relocs-270-bad"
+run_dump_test "emit-relocs-270-overflow"
 run_dump_test "emit-relocs-271"
+run_dump_test "emit-relocs-271-overflow"
 run_dump_test "emit-relocs-272"
+run_dump_test "emit-relocs-272-overflow"
 run_dump_test "emit-relocs-273"
 run_dump_test "emit-relocs-274"
 run_dump_test "emit-relocs-275"
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-270-overflow.d b/ld/testsuite/ld-aarch64/emit-relocs-270-overflow.d
new file mode 100644 (file)
index 0000000..991dc1f
--- /dev/null
@@ -0,0 +1,5 @@
+#source: emit-relocs-270-overflow.s
+#ld: -T relocs.ld --defsym tempy=0x10000 --defsym tempy1=-0x10001 -e0 --emit-relocs
+#objdump: -dr
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_MOVW_SABS_G0 against symbol `tempy' .*
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_MOVW_SABS_G0 against symbol `tempy1' .*
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-270-overflow.s b/ld/testsuite/ld-aarch64/emit-relocs-270-overflow.s
new file mode 100644 (file)
index 0000000..acc9b2d
--- /dev/null
@@ -0,0 +1,6 @@
+.comm   gempy,4,4
+.text
+
+       movz    x4, :abs_g0_s:tempy
+       movz    x5, :abs_g0_s:tempy1
+
index 442150e7b06391fab24adcc6e3256dd0138d2427..34f7a2a933f70784cebdef2214ebcf9bb7b37fac 100644 (file)
@@ -1,14 +1,13 @@
 #source: emit-relocs-270.s
-#ld: -T relocs.ld --defsym tempy=0x1012 --defsym tempy2=0x4500 --defsym tempy3=-292  -e0 --emit-relocs
-#objdump: -dr -Mno-aliases
+#ld: -T relocs.ld --defsym tempy=0xffff --defsym tempy2=0x4500 --defsym tempy3=-0x10000  -e0 --emit-relocs
+#objdump: -dr
 
 #...
  +10000:       8a000000        and     x0, x0, x0
  +10004:       92400000        and     x0, x0, #0x1
- +10008:       d2820244        movz    x4, #0x1012
-       +10008: R_AARCH64_MOVW_SABS_G0  tempy
- +1000c:       d288a007        movz    x7, #0x4500
-       +1000c: R_AARCH64_MOVW_SABS_G0  tempy2
- +10010:       92802471        movn    x17, #0x123
-       +10010: R_AARCH64_MOVW_SABS_G0  tempy3
-
+ +10008:       d29fffe4        mov     x4, #0xffff                     // #65535
+                       10008: R_AARCH64_MOVW_SABS_G0   tempy
+ +1000c:       d288a007        mov     x7, #0x4500                     // #17664
+                       1000c: R_AARCH64_MOVW_SABS_G0   tempy2
+ +10010:       929ffff1        mov     x17, #0xffffffffffff0000        // #-65536
+                       10010: R_AARCH64_MOVW_SABS_G0   tempy3
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-271-overflow.d b/ld/testsuite/ld-aarch64/emit-relocs-271-overflow.d
new file mode 100644 (file)
index 0000000..b526ca4
--- /dev/null
@@ -0,0 +1,5 @@
+#source: emit-relocs-271-overflow.s
+#ld: -T relocs.ld --defsym tempy=0x100000000 --defsym tempy1=-0x100000001 -e0 --emit-relocs
+#objdump: -dr
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_MOVW_SABS_G1 against symbol `tempy' .*
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_MOVW_SABS_G1 against symbol `tempy1' .*
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-271-overflow.s b/ld/testsuite/ld-aarch64/emit-relocs-271-overflow.s
new file mode 100644 (file)
index 0000000..47d0686
--- /dev/null
@@ -0,0 +1,5 @@
+.comm   gempy,4,4
+.text
+
+       movz    x4, :abs_g1_s:tempy
+       movz    x5, :abs_g1_s:tempy1
index 1f348201e3fac00f2b71e5f988bfb59666216a4a..f71cd026855b60afd2c131e89dd219dc6511699c 100644 (file)
@@ -1,14 +1,13 @@
 #source: emit-relocs-271.s
-#ld: -T relocs.ld --defsym tempy=0x1012 --defsym tempy2=0x674500 --defsym tempy3=-292  -e0 --emit-relocs
-#objdump: -dr -Mno-aliases
+#ld: -T relocs.ld --defsym tempy=0xffffffff --defsym tempy2=0x674500 --defsym tempy3=-0x100000000  -e0 --emit-relocs
+#objdump: -dr
 
 #...
  +10000:       8a000000        and     x0, x0, x0
  +10004:       92400000        and     x0, x0, #0x1
- +10008:       d2a00004        movz    x4, #0x0, lsl #16
-       +10008: R_AARCH64_MOVW_SABS_G1  tempy
- +1000c:       d2a00ce7        movz    x7, #0x67, lsl #16
-       +1000c: R_AARCH64_MOVW_SABS_G1  tempy2
- +10010:       92a00011        movn    x17, #0x0, lsl #16
-       +10010: R_AARCH64_MOVW_SABS_G1  tempy3
-
+ +10008:       d2bfffe4        mov     x4, #0xffff0000                 // #4294901760
+                       10008: R_AARCH64_MOVW_SABS_G1   tempy
+ +1000c:       d2a00ce7        mov     x7, #0x670000                   // #6750208
+                       1000c: R_AARCH64_MOVW_SABS_G1   tempy2
+ +10010:       92bffff1        mov     x17, #0xffffffff0000ffff        // #-4294901761
+                       10010: R_AARCH64_MOVW_SABS_G1   tempy3
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-272-overflow.d b/ld/testsuite/ld-aarch64/emit-relocs-272-overflow.d
new file mode 100644 (file)
index 0000000..a035554
--- /dev/null
@@ -0,0 +1,5 @@
+#source: emit-relocs-272-overflow.s
+#ld: -T relocs.ld --defsym tempy=0x1000000000000 --defsym tempy1=-0x1000000000001 -e0 --emit-relocs
+#objdump: -dr
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_MOVW_SABS_G2 against symbol `tempy' .*
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_MOVW_SABS_G2 against symbol `tempy1' .*
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-272-overflow.s b/ld/testsuite/ld-aarch64/emit-relocs-272-overflow.s
new file mode 100644 (file)
index 0000000..ac79465
--- /dev/null
@@ -0,0 +1,5 @@
+.comm   gempy,4,4
+.text
+
+       movz    x4, :abs_g2_s:tempy
+       movz    x5, :abs_g2_s:tempy1
index 011ead54c99f7dae34862237116404dd4c507f31..94c037f5c611ecbf57188503830daba46fdfe833 100644 (file)
@@ -1,14 +1,14 @@
 #source: emit-relocs-272.s
-#ld: -T relocs.ld --defsym tempy=0x1012 --defsym tempy2=-12345678912345 --defsym tempy3=-292  -e0 --emit-relocs
-#objdump: -dr -Mno-aliases
+#ld: -T relocs.ld --defsym tempy=0xffffffffffff --defsym tempy2=-12345678912345 --defsym tempy3=-0x1000000000000  -e0 --emit-relocs
+#objdump: -dr
 
 #...
  +10000:       8a000000        and     x0, x0, x0
  +10004:       92400000        and     x0, x0, #0x1
- +10008:       d2c00004        movz    x4, #0x0, lsl #32
-       +10008: R_AARCH64_MOVW_SABS_G2  tempy
- +1000c:       92c16747        movn    x7, #0xb3a, lsl #32
-       +1000c: R_AARCH64_MOVW_SABS_G2  tempy2
- +10010:       92c00011        movn    x17, #0x0, lsl #32
-       +10010: R_AARCH64_MOVW_SABS_G2  tempy3
+ +10008:       d2dfffe4        mov     x4, #0xffff00000000             // #281470681743360
+                       10008: R_AARCH64_MOVW_SABS_G2   tempy
+ +1000c:       92c16747        mov     x7, #0xfffff4c5ffffffff         // #-12343736008705
+                       1000c: R_AARCH64_MOVW_SABS_G2   tempy2
+ +10010:       92dffff1        mov     x17, #0xffff0000ffffffff        // #-281470681743361
+                       10010: R_AARCH64_MOVW_SABS_G2   tempy3