This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [BFD][AARCH64]Fix MOVW_SABS_G(0,1,2) relocation overflow check.
- From: Renlin Li <renlin dot li at foss dot arm dot com>
- To: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Cc: Nicholas Clifton <nickc at redhat dot com>, Marcus Shawcroft <Marcus dot Shawcroft at arm dot com>, Ramana Radhakrishnan <Ramana dot Radhakrishnan at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>
- Date: Thu, 25 Feb 2016 10:51:28 +0000
- Subject: Re: [BFD][AARCH64]Fix MOVW_SABS_G(0,1,2) relocation overflow check.
- Authentication-results: sourceware.org; auth=none
- References: <56CEDB35 dot 8070102 at foss dot arm dot com>
Sorry,
the correct patch attached in this email.
Regards,
Renlin
On 25/02/16 10:45, Renlin Li wrote:
Hi all,
This patch fixes the overflow check for
R_AARCH64_MOVW_SABS_G0
R_AARCH64_MOVW_SABS_G1
R_AARCH64_MOVW_SABS_G2
According to the aarch64 elf specification, for those relocations with
overflow check, the following rule applies:
X > 0: Set the instruction to MOVZ and its immediate value to the
selected bits S;
for relocation R_..._Gn, check that X< {G0: 2^16 , G1 : 2^32 , G2 :
2^48 } (no check for R_..._G3).
X < 0: Set the instruction to MOVN and its immediate value to NOT
(selected bits of);
for relocation R_..._Gn , check that -{ G0 : 2^16 , G1 : 2^32 , G2 :
2^48 } ? X (no check for R_..._G3).
This rule indicates:
1, signed overflow check should be used.
2, For the allowed range, 17 bit signed value should be used, instead
of 16 bit.
Here the bitsize field is changed from 16 to 17, this field in aarch64
backend is used for overflow check only.
the BFD already have the functions to re-encode the instruction into
movz/movn according to the sign of the value.
Only the overflow check needs to be fixed!
binutils regression test checked Okay, Okay for trunk?
Regards,
Renlin Li
bfd/ChangeLog:
2016-02-25 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/ChangeLog:
2016-02-25 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.
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 292470df73ed97768880b172cf7e995cbb31dc4f..b5c3019b879bf2a402935fd96ae3f824a8160572 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -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 */
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 939539ec809a51b9371d9c8bf66e2bbe6ddc4093..f5a4192d62be4378a40a556720f5b19d720607c9 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -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
index 0000000000000000000000000000000000000000..991dc1f33a768a30a5fff321c52fe3fb17bfec60
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-270-overflow.d
@@ -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
index 0000000000000000000000000000000000000000..acc9b2d3bfb3af45f3bce709cb7f47748559cac2
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-270-overflow.s
@@ -0,0 +1,6 @@
+.comm gempy,4,4
+.text
+
+ movz x4, :abs_g0_s:tempy
+ movz x5, :abs_g0_s:tempy1
+
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-270.d b/ld/testsuite/ld-aarch64/emit-relocs-270.d
index 442150e7b06391fab24adcc6e3256dd0138d2427..34f7a2a933f70784cebdef2214ebcf9bb7b37fac 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-270.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-270.d
@@ -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
index 0000000000000000000000000000000000000000..b526ca469c2c698b579adab94362c56fe25cc154
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-271-overflow.d
@@ -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
index 0000000000000000000000000000000000000000..47d06863beb2f84c95e9ecd569787492a6ece3e8
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-271-overflow.s
@@ -0,0 +1,5 @@
+.comm gempy,4,4
+.text
+
+ movz x4, :abs_g1_s:tempy
+ movz x5, :abs_g1_s:tempy1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-271.d b/ld/testsuite/ld-aarch64/emit-relocs-271.d
index 1f348201e3fac00f2b71e5f988bfb59666216a4a..f71cd026855b60afd2c131e89dd219dc6511699c 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-271.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-271.d
@@ -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
index 0000000000000000000000000000000000000000..a035554cc1a2c102d7178a73594196888269b480
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-272-overflow.d
@@ -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
index 0000000000000000000000000000000000000000..ac79465c5c0dd9432a9532f3c7175ed548da60a9
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-272-overflow.s
@@ -0,0 +1,5 @@
+.comm gempy,4,4
+.text
+
+ movz x4, :abs_g2_s:tempy
+ movz x5, :abs_g2_s:tempy1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-272.d b/ld/testsuite/ld-aarch64/emit-relocs-272.d
index 011ead54c99f7dae34862237116404dd4c507f31..94c037f5c611ecbf57188503830daba46fdfe833 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-272.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-272.d
@@ -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