x86: Clear modrm if not needed
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 5 Oct 2020 12:23:29 +0000 (05:23 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 5 Oct 2020 12:23:39 +0000 (05:23 -0700)
The MODRM byte can be checked to display the instruction name only if the
MODRM byte needed.  Clear modrm if the MODRM byte isn't needed so that
modrm field checks in putop like, modrm.mod == N with N != 0, can be done
without checking need_modrm.

gas/

PR binutils/26705
* testsuite/gas/i386/x86-64-suffix.s: Add "mov %rsp,%rbp" before
sysretq.
* testsuite/gas/i386/x86-64-suffix-intel.d: Updated.
* testsuite/gas/i386/x86-64-suffix.d: Likewise.

opcodes/

PR binutils/26705
* i386-dis.c (print_insn): Clear modrm if not needed.
(putop): Check need_modrm for modrm.mod != 3.  Don't check
need_modrm for modrm.mod == 3.

gas/ChangeLog
gas/testsuite/gas/i386/x86-64-suffix-intel.d
gas/testsuite/gas/i386/x86-64-suffix.d
gas/testsuite/gas/i386/x86-64-suffix.s
opcodes/ChangeLog
opcodes/i386-dis.c

index 56796ff9485abe1d9b25aa430e23bf0821c54862..ae5a614543fe54a5e7b34d27ef9e55d96f0d6f0e 100644 (file)
@@ -1,3 +1,11 @@
+2020-10-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/26705
+       * testsuite/gas/i386/x86-64-suffix.s: Add "mov %rsp,%rbp" before
+       sysretq.
+       * testsuite/gas/i386/x86-64-suffix-intel.d: Updated.
+       * testsuite/gas/i386/x86-64-suffix.d: Likewise.
+
 2020-10-05  Nick Clifton  <nickc@redhat.com>
 
        PR 26253
index 74c8eaa4747324c8c3037887ccbbc3678df1a287..55d4a8dd1b603be49427e9eed60d83efc671ac43 100644 (file)
@@ -18,11 +18,13 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    cf                      iretd  
 [      ]*[a-f0-9]+:    48 cf                   iretq  
 [      ]*[a-f0-9]+:    0f 07                   sysretd 
+[      ]*[a-f0-9]+:    48 89 e5                mov    rbp,rsp
 [      ]*[a-f0-9]+:    48 0f 07                sysretq 
 [      ]*[a-f0-9]+:    66 cf                   iretw  
 [      ]*[a-f0-9]+:    cf                      iretd  
 [      ]*[a-f0-9]+:    cf                      iretd  
 [      ]*[a-f0-9]+:    48 cf                   iretq  
 [      ]*[a-f0-9]+:    0f 07                   sysretd 
+[      ]*[a-f0-9]+:    48 89 e5                mov    rbp,rsp
 [      ]*[a-f0-9]+:    48 0f 07                sysretq 
 #pass
index d81ac4526bf4fff09600af52f782ab3e5536ce2c..5ae11730b63f167b720468e8a37cda231c9cccc7 100644 (file)
@@ -17,11 +17,13 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    cf                      iretl  
 [      ]*[a-f0-9]+:    48 cf                   iretq  
 [      ]*[a-f0-9]+:    0f 07                   sysretl 
+[      ]*[a-f0-9]+:    48 89 e5                movq   %rsp,%rbp
 [      ]*[a-f0-9]+:    48 0f 07                sysretq 
 [      ]*[a-f0-9]+:    66 cf                   iretw  
 [      ]*[a-f0-9]+:    cf                      iretl  
 [      ]*[a-f0-9]+:    cf                      iretl  
 [      ]*[a-f0-9]+:    48 cf                   iretq  
 [      ]*[a-f0-9]+:    0f 07                   sysretl 
+[      ]*[a-f0-9]+:    48 89 e5                movq   %rsp,%rbp
 [      ]*[a-f0-9]+:    48 0f 07                sysretq 
 #pass
index 2261c2c1aeed526c03aad8c56ece3a13e6ae19bb..a226836215c3d8f8919bf41ed09b3560213af0dd 100644 (file)
@@ -14,6 +14,7 @@ foo:
        iretl
        iretq
        sysretl
+       mov     %rsp,%rbp
        sysretq
 
        .intel_syntax noprefix
@@ -22,4 +23,5 @@ foo:
        iret
        iretq
        sysretd
+       mov     rbp,rsp
        sysretq
index c57c0b1e209f0105b4de62e25c644cef821b888a..f1b427318d5de0d3608d1d3eb771b74e490bc7ce 100644 (file)
@@ -1,3 +1,10 @@
+2020-10-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/26705
+       * i386-dis.c (print_insn): Clear modrm if not needed.
+       (putop): Check need_modrm for modrm.mod != 3.  Don't check
+       need_modrm for modrm.mod == 3.
+
 2020-09-28  Przemyslaw Wirkus  <przemyslaw.wirkus@arm.com>
 
        * aarch64-opc.c: Added ETMv4 system registers TRCACATRn, TRCACVRn,
index 67d5b6aaefc6fd24abc2b1ca3a60cbe272ccae57..f4f35bc8f1a862d79198e7d686d5cc8d55312ef2 100644 (file)
@@ -9927,7 +9927,7 @@ print_insn (bfd_vma pc, disassemble_info *info)
       FETCH_DATA (info, codep + 1);
       threebyte = *codep;
       dp = &dis386_twobyte[threebyte];
-      need_modrm = twobyte_has_modrm[*codep];
+      need_modrm = twobyte_has_modrm[threebyte];
       codep++;
     }
   else
@@ -9954,6 +9954,8 @@ print_insn (bfd_vma pc, disassemble_info *info)
       modrm.reg = (*codep >> 3) & 7;
       modrm.rm = *codep & 7;
     }
+  else
+    memset (&modrm, 0, sizeof (modrm));
 
   need_vex = 0;
   memset (&vex, 0, sizeof (vex));
@@ -10644,7 +10646,8 @@ putop (const char *in_template, int sizeflag)
        case 'A':
          if (intel_syntax)
            break;
-         if (modrm.mod != 3 || (sizeflag & SUFFIX_ALWAYS))
+         if ((need_modrm && modrm.mod != 3)
+             || (sizeflag & SUFFIX_ALWAYS))
            *obufp++ = 'b';
          break;
        case 'B':
@@ -10796,7 +10799,7 @@ putop (const char *in_template, int sizeflag)
        case 'P':
          if (l == 0)
            {
-             if (((need_modrm && modrm.mod == 3) || !cond)
+             if ((modrm.mod == 3 || !cond)
                  && !(sizeflag & SUFFIX_ALWAYS))
                break;
          /* Fall through.  */
@@ -10840,7 +10843,8 @@ putop (const char *in_template, int sizeflag)
              if (intel_syntax && !alt)
                break;
              USED_REX (REX_W);
-             if (modrm.mod != 3 || (sizeflag & SUFFIX_ALWAYS))
+             if ((need_modrm && modrm.mod != 3)
+                 || (sizeflag & SUFFIX_ALWAYS))
                {
                  if (rex & REX_W)
                    *obufp++ = 'q';