[binutils-gdb] x86-64: improve handling of branches to absolute addresses

Jan Beulich jbeulich@sourceware.org
Mon Jul 4 06:33:00 GMT 2022


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9386188e95f4dee6319c51b30e2ea64b27ae0084

commit 9386188e95f4dee6319c51b30e2ea64b27ae0084
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Jul 4 08:31:21 2022 +0200

    x86-64: improve handling of branches to absolute addresses
    
    There are two related problems here: The use of "addr32" on a direct
    branch would, besides causing a warning, result in operands to be
    permitted which mistakenly are refused without "addr32". Plus at some
    point not too long ago I'm afraid it may have been me who regressed the
    relocation addends emitted for such branches. Correct both problems,
    adding a testcase to guard against regressing this again.

Diff:
---
 gas/config/tc-i386.c                     |  8 ++++++--
 gas/testsuite/gas/i386/i386.exp          |  1 +
 gas/testsuite/gas/i386/x86-64-branch-6.d | 21 +++++++++++++++++++++
 gas/testsuite/gas/i386/x86-64-branch-6.e |  7 +++++++
 gas/testsuite/gas/i386/x86-64-branch-6.s | 18 ++++++++++++++++++
 5 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 5d486570bf8..8b245cc4d34 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -4975,7 +4975,9 @@ md_assemble (char *line)
   if (i.imm_operands)
     optimize_imm ();
 
-  if (i.disp_operands && !want_disp32 (current_templates->start))
+  if (i.disp_operands && !want_disp32 (current_templates->start)
+      && (!current_templates->start->opcode_modifier.jump
+	  || i.jumpabsolute || i.types[0].bitfield.baseindex))
     {
       for (j = 0; j < i.operands; ++j)
 	{
@@ -5985,7 +5987,9 @@ optimize_disp (void)
 	    /* Optimize 64-bit displacement to 32-bit for 64-bit BFD.  */
 	    if ((i.types[op].bitfield.disp32
 		 || (flag_code == CODE_64BIT
-		     && want_disp32 (current_templates->start)))
+		     && want_disp32 (current_templates->start)
+		     && (!current_templates->start->opcode_modifier.jump
+			 || i.jumpabsolute || i.types[op].bitfield.baseindex)))
 		&& fits_in_unsigned_long (op_disp))
 	      {
 		/* If this operand is at most 32 bits, convert
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index a4fc5b4096b..ebb1b492462 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -1314,6 +1314,7 @@ if [gas_64_check] then {
 	run_dump_test "x86-64-branch-3"
 	run_list_test "x86-64-branch-4" "-al -mintel64"
 	run_list_test "x86-64-branch-5" "-al"
+	run_dump_test "x86-64-branch-6"
 
 	run_dump_test "x86-64-rip-2"
 
diff --git a/gas/testsuite/gas/i386/x86-64-branch-6.d b/gas/testsuite/gas/i386/x86-64-branch-6.d
new file mode 100644
index 00000000000..a2d388f1277
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-branch-6.d
@@ -0,0 +1,21 @@
+#objdump: -r
+#name: x86-64 branch 6
+#warning_output: x86-64-branch-6.e
+
+.*: +file format .*
+
+RELOCATION RECORDS FOR \[\.text\]:
+OFFSET +TYPE +VALUE *
+0+01 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d
+0+11 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c
+0+21 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d
+0+31 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c
+0+07 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d
+0+0c R_X86_64_PC32 +\*ABS\*\+0x000000008765431d
+0+17 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c
+0+1c R_X86_64_PC32 +\*ABS\*\+0x000000087654320c
+0+27 R_X86_64_PC32 +\*ABS\*\+0x000000008765431d
+0+2c R_X86_64_PC32 +\*ABS\*\+0x000000008765431d
+0+37 R_X86_64_PC32 +\*ABS\*\+0x000000087654320c
+0+3c R_X86_64_PC32 +\*ABS\*\+0x000000087654320c
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-branch-6.e b/gas/testsuite/gas/i386/x86-64-branch-6.e
new file mode 100644
index 00000000000..1dc58ea11cb
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-branch-6.e
@@ -0,0 +1,7 @@
+.*: Assembler messages:
+.*:12: Warning: skipping prefixes on `call'
+.*:13: Warning: skipping prefixes on `je'
+.*:14: Warning: skipping prefixes on `jmp'
+.*:16: Warning: skipping prefixes on `call'
+.*:17: Warning: skipping prefixes on `je'
+.*:18: Warning: skipping prefixes on `jmp'
diff --git a/gas/testsuite/gas/i386/x86-64-branch-6.s b/gas/testsuite/gas/i386/x86-64-branch-6.s
new file mode 100644
index 00000000000..a5b108e5abf
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-branch-6.s
@@ -0,0 +1,18 @@
+	.text
+
+branch_6:
+	call	0x87654321
+	je	0x87654321
+	jmp	0x87654321
+
+	call	0x876543210
+	je	0x876543210
+	jmp	0x876543210
+
+	addr32 call	0x87654321
+	addr32 je	0x87654321
+	addr32 jmp	0x87654321
+
+	addr32 call	0x876543210
+	addr32 je	0x876543210
+	addr32 jmp	0x876543210


More information about the Binutils-cvs mailing list