aboutsummaryrefslogtreecommitdiff
path: root/gas/testsuite
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2021-04-28 10:53:00 +0200
committerJan Beulich <jbeulich@suse.com>2021-04-28 10:53:00 +0200
commiteb19308f2d09675dd936960c15603ae749e0f837 (patch)
tree5fba813ce356228e4f3dac2fdcb0963008e002b9 /gas/testsuite
parent6c356992b46da85a3eae0e901538c9d9855508ed (diff)
downloadgdb-eb19308f2d09675dd936960c15603ae749e0f837.zip
gdb-eb19308f2d09675dd936960c15603ae749e0f837.tar.gz
gdb-eb19308f2d09675dd936960c15603ae749e0f837.tar.bz2
x86: honor signedness of PC-relative relocations
PR gas/27763 While the comment in output_jump() was basically correct prior to the introduction of 64-bit mode, both that and the not-JMP-like behavior of XBEGIN require adjustments: Branches with 32-bit displacement do not wrap at 4G in 64-bit mode, and XBEGIN with 16-bit operand size doesn't wrap at 64k. Similarly %rip-relative addressing doesn't wrap at 4G. The new testcase points out that for PE/COFF object_64bit didn't get set so far, preventing in particular the check at the end of md_convert_frag() to take effect. For Mach-O the new testcase fails (bogusly), in that only the first two of the expected errors get raised. Since for Mach-O many testcases already fail, and since an x86_64-darwin target can't even be configured for, I didn't think I need to bother. Note that there are further issues in this area, in particular for branches with operand size overrides. Such branches, which truncate %rip / %eip, can't be correctly expressed with ordinary PC-relative relocations. It's not really clear what to do with them - perhaps the best we can do is to carry through all associated relocations, leaving it to the linker (or even loader) to decide (once the final address layout is known). Same perhaps goes for relocations associated with 32-bit addressing in 64-bit mode.
Diffstat (limited to 'gas/testsuite')
-rw-r--r--gas/testsuite/gas/i386/i386.exp4
-rw-r--r--gas/testsuite/gas/i386/pcrel64.l54
-rw-r--r--gas/testsuite/gas/i386/pcrel64.s27
-rw-r--r--gas/testsuite/gas/i386/x86-64-rip-2.d21
-rw-r--r--gas/testsuite/gas/i386/x86-64-rip-2.s10
-rw-r--r--gas/testsuite/gas/i386/x86-64-rip-inval-1.l11
-rw-r--r--gas/testsuite/gas/i386/x86-64-rip-inval-1.s4
-rw-r--r--gas/testsuite/gas/i386/x86-64-rip-inval-2.l11
-rw-r--r--gas/testsuite/gas/i386/x86-64-rip-inval-2.s4
9 files changed, 146 insertions, 0 deletions
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index 0086645..1846c98 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -760,8 +760,12 @@ if [gas_64_check] then {
} else {
run_dump_test "x86-64-w64-pcrel"
}
+ run_list_test "pcrel64" "-al"
run_dump_test "x86-64-rip"
run_dump_test "x86-64-rip-intel"
+ run_dump_test "x86-64-rip-2"
+ run_list_test "x86-64-rip-inval-1" "-al"
+ run_list_test "x86-64-rip-inval-2" "-al"
run_dump_test "x86-64-stack"
run_dump_test "x86-64-stack-intel"
run_dump_test "x86-64-stack-suffix"
diff --git a/gas/testsuite/gas/i386/pcrel64.l b/gas/testsuite/gas/i386/pcrel64.l
new file mode 100644
index 0000000..7c2fc64
--- /dev/null
+++ b/gas/testsuite/gas/i386/pcrel64.l
@@ -0,0 +1,54 @@
+.*: Assembler messages:
+.*:16: Error: .*
+.*:17: Error: .*
+.*:13: Error: .*
+.*:15: Error: .*
+.*:18: Error: .*
+.*:19: Error: .*
+.*:20: Error: .*
+GAS LISTING .*
+
+
+[ ]*[0-9]+[ ]+\.text
+[ ]*[0-9]+[ ]+\.code64
+[ ]*[0-9]+[ ]+pcrel:
+[ ]*[0-9]+ \?\?\?\? E8..8000[ ]+call target
+[ ]*[0-9]+[ ]+00
+[ ]*[0-9]+ \?\?\?\? E9..8000[ ]+jmp target
+[ ]*[0-9]+[ ]+00
+[ ]*[0-9]+ \?\?\?\? 0F84..80[ ]+jz target
+[ ]*[0-9]+[ ]+0000
+[ ]*[0-9]+ \?\?\?\? C7F8..80[ ]+xbegin target
+[ ]*[0-9]+[ ]+0000
+[ ]*[0-9]+ \?\?\?\? 8B05..80[ ]+mov target\(%rip\), %eax
+[ ]*[0-9]+[ ]+0000
+[ ]*[0-9]+ \?\?\?\? 678B05..[ ]+mov target\(%eip\), %eax
+[ ]*[0-9]+[ ]+800000
+[ ]*[0-9]+ \?\?\?\? 48C7C0..[ ]+mov \$target-., %rax
+[ ]*[0-9]+[ ]+800000
+[ ]*[0-9]+ \?\?\?\? B8..8000[ ]+mov \$target-., %eax
+[ ]*[0-9]+[ ]+00
+[ ]*[0-9]+[ ]*
+[ ]*[0-9]+ \?\?\?\? 66C7F8..[ ]+data16 xbegin target
+[ ]*[0-9]+[ ]+80
+[ ]*[0-9]+[ ]*
+[ ]*[0-9]+ \?\?\?\? E8...000[ ]+call target\+0x7ffff000
+[ ]*[0-9]+[ ]+80
+[ ]*[0-9]+ \?\?\?\? E9000000[ ]+jmp target\+0x7ffff000
+[ ]*[0-9]+[ ]+00
+[ ]*[0-9]+ \?\?\?\? 0F840000[ ]+jz target\+0x7ffff000
+[ ]*[0-9]+[ ]+0000
+[ ]*[0-9]+ \?\?\?\? C7F8...0[ ]+xbegin target\+0x7ffff000
+[ ]*[0-9]+[ ]+0080
+[ ]*[0-9]+ \?\?\?\? 8B05...0[ ]+mov target\+0x7ffff000\(%rip\), %eax
+[ ]*[0-9]+[ ]+0080
+[ ]*[0-9]+ \?\?\?\? 48C7C0..[ ]+mov \$target\+0x7ffff000-., %rax
+[ ]*[0-9]+[ ]+.00080
+[ ]*[0-9]+[ ]*
+[ ]*[0-9]+ \?\?\?\? 678B05..[ ]+mov target\+0x7ffff000\(%eip\), %eax
+[ ]*[0-9]+[ ]+.00080
+[ ]*[0-9]+ \?\?\?\? B8...000[ ]+mov \$target\+0x7ffff000-., %eax
+[ ]*[0-9]+[ ]+80
+[ ]*[0-9]+[ ]*
+[ ]*[0-9]+ \?\?\?\? CCCCCCCC[ ]+\.fill 0x8000, 1, 0xcc
+#pass
diff --git a/gas/testsuite/gas/i386/pcrel64.s b/gas/testsuite/gas/i386/pcrel64.s
new file mode 100644
index 0000000..831ee40
--- /dev/null
+++ b/gas/testsuite/gas/i386/pcrel64.s
@@ -0,0 +1,27 @@
+ .text
+ .code64
+pcrel:
+ call target
+ jmp target
+ jz target
+ xbegin target
+ mov target(%rip), %eax
+ mov target(%eip), %eax
+ mov $target-., %rax
+ mov $target-., %eax
+
+ data16 xbegin target
+
+ call target+0x7ffff000
+ jmp target+0x7ffff000
+ jz target+0x7ffff000
+ xbegin target+0x7ffff000
+ mov target+0x7ffff000(%rip), %eax
+ mov $target+0x7ffff000-., %rax
+
+ mov target+0x7ffff000(%eip), %eax
+ mov $target+0x7ffff000-., %eax
+
+ .fill 0x8000, 1, 0xcc
+target:
+ ret
diff --git a/gas/testsuite/gas/i386/x86-64-rip-2.d b/gas/testsuite/gas/i386/x86-64-rip-2.d
new file mode 100644
index 0000000..bf9ca39
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-rip-2.d
@@ -0,0 +1,21 @@
+#as: -J
+#objdump: -drw --syms
+#name: x86-64 rip addressing 2
+
+.*: +file format .*
+
+SYMBOL TABLE:
+0000000000000000 l .text 0000000000000000 _start
+0000000080000006 l .text 0000000000000000 test1
+ffffffff8000000e l .text 0000000000000000 test2
+00000000f000000e l .text 0000000000000000 test3
+ffffffff1000000e l .text 0000000000000000 test4
+
+
+
+Disassembly of section .text:
+
+0000000000000000 <_start>:
+ +0: 48 8b 05 ff ff ff 7f mov 0x7fffffff\(%rip\),%rax # 80000006 <test1>
+ +7: 48 8b 05 00 00 00 80 mov -0x80000000\(%rip\),%rax # ffffffff8000000e <test2>
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-rip-2.s b/gas/testsuite/gas/i386/x86-64-rip-2.s
new file mode 100644
index 0000000..5ce80e8
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-rip-2.s
@@ -0,0 +1,10 @@
+ .text
+_start:
+ movq test1(%rip), %rax
+ .set test1, . + 0x7fffffff
+
+ movq test2(%rip), %rax
+ .set test2, . - 0x80000000
+
+ .set test3, . + 0xf0000000
+ .set test4, . - 0xf0000000
diff --git a/gas/testsuite/gas/i386/x86-64-rip-inval-1.l b/gas/testsuite/gas/i386/x86-64-rip-inval-1.l
new file mode 100644
index 0000000..d40099e
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-rip-inval-1.l
@@ -0,0 +1,11 @@
+.*: Assembler messages:
+.*:3: Error:.* (0x)?ffffffff7fffffff .*
+GAS LISTING .*
+
+
+[ ]*1[ ]+\.text
+[ ]*2[ ]+_start:
+[ ]*3[ ]+\?\?\?\? 488B05FF movq test1\(%rip\), %rax
+[ ]*3[ ]+FFFF7F
+[ ]*4[ ]+\.set test1, \. - 0x80000001
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-rip-inval-1.s b/gas/testsuite/gas/i386/x86-64-rip-inval-1.s
new file mode 100644
index 0000000..a0e783e
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-rip-inval-1.s
@@ -0,0 +1,4 @@
+ .text
+_start:
+ movq test1(%rip), %rax
+ .set test1, . - 0x80000001
diff --git a/gas/testsuite/gas/i386/x86-64-rip-inval-2.l b/gas/testsuite/gas/i386/x86-64-rip-inval-2.l
new file mode 100644
index 0000000..e724393
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-rip-inval-2.l
@@ -0,0 +1,11 @@
+.*: Assembler messages:
+.*:3: Error:.* (0x)?0*80000000 .*
+GAS LISTING .*
+
+
+[ ]*1[ ]+\.text
+[ ]*2[ ]+_start:
+[ ]*3[ ]+\?\?\?\? 488B0500 movq test1\(%rip\), %rax
+[ ]*3[ ]+000080
+[ ]*4[ ]+\.set test1, \. \+ 0x80000000
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-rip-inval-2.s b/gas/testsuite/gas/i386/x86-64-rip-inval-2.s
new file mode 100644
index 0000000..9bdc703
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-rip-inval-2.s
@@ -0,0 +1,4 @@
+ .text
+_start:
+ movq test1(%rip), %rax
+ .set test1, . + 0x80000000