Bug 25167 - The .code16 directive is broken
Summary: The .code16 directive is broken
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: 2.34
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-06 15:35 UTC by H.J. Lu
Modified: 2019-11-08 17:36 UTC (History)
0 users

See Also:
Host:
Target: i386
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 2019-11-06 15:35:43 UTC
commit d241b91073165f99fe404d9b38c65f03835ecaf4
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Oct 7 08:38:01 2019 +0200

    x86/Intel: correct MOVSD and CMPSD handling

caused:

[hjl@gnu-skx-1 build-x86_64-linux]$ cat x.s
.code16
rep; movsd
[hjl@gnu-skx-1 build-x86_64-linux]$ ./gas/as-new --32 -o x.o x.s
[hjl@gnu-skx-1 build-x86_64-linux]$ objdump -dw -Mi8086 x.o

x.o:     file format elf32-i386


Disassembly of section .text:

00000000 <.text>:
   0:	f3 a5                	rep movsw %ds:(%si),%es:(%di)
                                    This should be movsl.
[hjl@gnu-skx-1 build-x86_64-linux]$
Comment 1 H.J. Lu 2019-11-06 15:38:20 UTC
cmpsd is also wrong.
Comment 2 H.J. Lu 2019-11-06 15:57:56 UTC
[hjl@gnu-skx-1 build-x86_64-linux]$ cat x.s 
.code16
rep; movsd
rep; cmpsd
.intel_syntax noprefix
cmpsd dword ptr [si], dword ptr es:[di]
[hjl@gnu-skx-1 build-x86_64-linux]$ ./gas/as-new --32 -o x.o x.s
[hjl@gnu-skx-1 build-x86_64-linux]$ objdump -dw -Mi8086 x.o

x.o:     file format elf32-i386


Disassembly of section .text:

00000000 <.text>:
   0:	f3 a5                	rep movsw %ds:(%si),%es:(%di)
   2:	f3 a7                	repz cmpsw %es:(%di),%ds:(%si)
   4:	a7                   	cmpsw  %es:(%di),%ds:(%si)
[hjl@gnu-skx-1 build-x86_64-linux]$
Comment 3 H.J. Lu 2019-11-06 17:20:11 UTC
String version of cmpsd and movsd are used to handle SSE versions of
cmpsd and movsd.  They should be treated as special cases.
Comment 4 Sourceware Commits 2019-11-08 17:35:14 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=dc2be329b9508395b7270b7c3bebc19a6f1e2e07

commit dc2be329b9508395b7270b7c3bebc19a6f1e2e07
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Nov 8 09:31:06 2019 -0800

    i386: Only check suffix in instruction mnemonic
    
    We should check suffix in instruction mnemonic when matching instruction.
    In Intel syntax, normally we check for memory operand size.  But the same
    mnemonic with 2 different encodings can have the same memory operand
    size and i.suffix is set to LONG_DOUBLE_MNEM_SUFFIX from memory operand
    size in Intel syntax to distinguish them.  When there is no suffix in
    mnemonic, we check LONG_DOUBLE_MNEM_SUFFIX in i.suffix for mnemonic
    suffix.
    
    gas/
    
    	PR gas/25167
    	* config/tc-i386.c (match_template): Don't check instruction
    	suffix set from operand.
    	* testsuite/gas/i386/code16.d: New file.
    	* testsuite/gas/i386/code16.s: Likewise.
    	* testsuite/gas/i386/i386.exp: Run code16.
    	* testsuite/gas/i386/x86-64-branch-4.l: Updated.
    
    opcodes/
    
    	PR gas/25167
    	* i386-opc.tbl: Remove IgnoreSize from cmpsd and movsd.
    	* i386-tbl.h: Regenerated.
Comment 5 H.J. Lu 2019-11-08 17:36:00 UTC
Fixed.