Bug 17898 - rdrand/rdseed should not disassmble with f2/f3 prefixes present.
Summary: rdrand/rdseed should not disassmble with f2/f3 prefixes present.
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: 2.26
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2015-01-29 02:04 UTC by markcharney
Modified: 2015-04-15 17:04 UTC (History)
1 user (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description markcharney 2015-01-29 02:04:42 UTC
binutils/objdump should do the software equivalent of a #UD (emit "(bad)" or whatever is the binutils convention for unrecognized instructions) if f2/f3 prefixes are present before rdrand/rdseed. Intel SDM says so.  Binutils disassembles them as if F2/F3 were legal legacy prefixes for these instructions. 

I demonstrated this with binutils 2.24. I did not check later versions.

% objdump -v
GNU objdump (GNU Binutils) 2.24
Copyright 2013 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

% cat foo.c
int main()
    asm volatile(".byte 0xF3, 0x0F, 0xC7, 0xF8");
    asm volatile(".byte 0xF3, 0x0F, 0xC7, 0xF0");
    return 0;

% gcc foo.c

% objdump -D a.out | grep -A10 'main>:'
0000000000400496 <main>:
  400496:	55                   	push   rbp
  400497:	48 89 e5             	mov    rbp,rsp
  40049a:	f3 0f c7 f8          	repz rdseed eax
  40049e:	f3 0f c7 f0          	repz rdrand eax
  4004a2:	b8 00 00 00 00       	mov    eax,0x0
  4004a7:	5d                   	pop    rbp
  4004a8:	c3                   	ret    
  4004a9:	0f 1f 80 00 00 00 00 	nop    DWORD PTR [rax+0x0]

00000000004004b0 <__libc_csu_init>:
Comment 1 cvs-commit@gcc.gnu.org 2015-04-15 17:02:08 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:


commit f24bcbaa5a6e30556e2da20bfd78e7823741475a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Apr 15 09:53:13 2015 -0700

    Handle invalid prefixes for rdrand and rdseed
    This patch puts rdrand and rdseed in prefix_table so that invalid
    prefixes for rdrand and rdseed are handled properly.
    	PR binutils/17898
    	* gas/i386/prefix.s: Add rdrand/rdseed prefix tests.
    	* gas/i386/prefix.d: Updated.
    	PR binutils/17898
    	* i386-dis.c (PREFIX_0FC7_REG_6): Renamed to ...
    	(PREFIX_MOD_0_0FC7_REG_6): This.
    	(PREFIX_MOD_3_0FC7_REG_6): New.
    	(PREFIX_MOD_3_0FC7_REG_7): Likewise.
    	(prefix_table): Replace PREFIX_0FC7_REG_6 with
    	PREFIX_MOD_0_0FC7_REG_6.  Add PREFIX_MOD_3_0FC7_REG_6 and
    	(mod_table): Replace PREFIX_0FC7_REG_6 with
    	PREFIX_MOD_0_0FC7_REG_6.  Use PREFIX_MOD_3_0FC7_REG_6 and
Comment 2 H.J. Lu 2015-04-15 17:04:53 UTC
Fixed for 2.26.