Bug 26705 - MODRM isn't properly handled
Summary: MODRM isn't properly handled
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: 2.36
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-04 22:34 UTC by H.J. Lu
Modified: 2020-10-05 12:29 UTC (History)
0 users

See Also:
Host:
Target: x86-64
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2020-10-04 22:34:14 UTC
[hjl@gnu-cfl-2 tmp]$ cat x.s
sysretq
mov    %rsp,%rbp
sysretq
[hjl@gnu-cfl-2 tmp]$ gcc -c x.s
[hjl@gnu-cfl-2 tmp]$ objdump -dw x.o

x.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <.text>:
   0:	48 0f 07             	sysretq 
   3:	48 89 e5             	mov    %rsp,%rbp
   6:	48 0f 07             	rex.W sysret 
[hjl@gnu-cfl-2 tmp]$
Comment 1 Sourceware Commits 2020-10-05 12:25:47 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 0e9f3bf12616b108682bb6f6e2a5ef04df9586a8
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Oct 5 05:23:29 2020 -0700

    x86: Clear modrm if not needed
    
    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.
Comment 2 H.J. Lu 2020-10-05 12:29:27 UTC
Fixed for 2.36.