Bug 31178 - [2.42 regression] Crash when building Valgrind tests (Internal error in build_vex_prefix in tc-i386.c:376)
Summary: [2.42 regression] Crash when building Valgrind tests (Internal error in build...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.42
: P2 normal
Target Milestone: 2.42
Assignee: Jan Beulich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-18 10:04 UTC by Sam James
Modified: 2024-01-09 13:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
vcpu_fbench-vcpu_fbench.i (24.47 KB, text/plain)
2023-12-18 10:04 UTC, Sam James
Details
vcpu_fbench-vcpu_fbench.s (51.64 KB, text/plain)
2023-12-18 10:04 UTC, Sam James
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2023-12-18 10:04:21 UTC
Created attachment 15263 [details]
vcpu_fbench-vcpu_fbench.i

```
$ gcc-13 -c vcpu_fbench-vcpu_fbench.i -O3 -march=znver2 -Wa,-O2
/tmp/ccmQb140.s: Assembler messages:
/tmp/ccmQb140.s:523: Internal error in build_vex_prefix at /var/tmp/portage/sys-devel/binutils-9999/work/binutils/gas/config/tc-i386.c:3764.
Please report this bug.
```

```
$ ld --version
GNU ld (Gentoo 9999 p1) 2.41.50.20231218
Copyright (C) 2023 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) a later version.
This program has absolutely no warranty.
```
Comment 1 Sam James 2023-12-18 10:04:53 UTC
Created attachment 15264 [details]
vcpu_fbench-vcpu_fbench.s

```
$ as ./vcpu_fbench-vcpu_fbench.s -O2
./vcpu_fbench-vcpu_fbench.s: Assembler messages:
./vcpu_fbench-vcpu_fbench.s:1217: Internal error in build_vex_prefix at /var/tmp/portage/sys-devel/binutils-9999/work/binutils/gas/config/tc-i386.c:3764.
Please report this bug.
```
Comment 2 Sam James 2023-12-18 10:05:58 UTC
Breakpoint 1, build_vex_prefix (t=t@entry=0x5555555f11cc <i386_optab+112684>) at /usr/src/debug/sys-devel/binutils-9999/binutils/gas/config/tc-i386.c:3764
3764          gas_assert (i.tm.opcode_space == SPACE_0F);
(gdb) bt
#0  build_vex_prefix (t=t@entry=0x5555555f11cc <i386_optab+112684>) at /usr/src/debug/sys-devel/binutils-9999/binutils/gas/config/tc-i386.c:3764
#1  0x00005555555acc8e in md_assemble (line=<optimized out>) at /usr/src/debug/sys-devel/binutils-9999/binutils/gas/config/tc-i386.c:5595
#2  0x000055555558164e in assemble_one (line=0x55555562d21d "vfnmadd231sd %xmm9,%xmm2,%xmm0") at /usr/src/debug/sys-devel/binutils-9999/binutils/gas/read.c:750
#3  read_a_source_file (name=<optimized out>) at /usr/src/debug/sys-devel/binutils-9999/binutils/gas/read.c:1220
#4  0x000055555555a21f in perform_an_assembly_pass (argv=0x55555561c498, argc=<optimized out>) at /usr/src/debug/sys-devel/binutils-9999/binutils/gas/as.c:1236
#5  main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/sys-devel/binutils-9999/binutils/gas/as.c:1415
(gdb)
Comment 3 Sam James 2023-12-22 15:28:10 UTC
da0784f961d8a14890b2a3fa3b5db5820e17deb6 is the first bad commit
commit da0784f961d8a14890b2a3fa3b5db5820e17deb6
Author: Jan Beulich <jbeulich@suse.com>
Date:   Wed Sep 27 14:16:09 2023 +0200

    x86: fold FMA VEX and EVEX templates

    Following the folding of some generic AVX/AVX2 templates with their
    AVX512F counterpart ones, do this for FMA ones as well, requiring one
    further adjustment to cpu_flags_match().

 gas/config/tc-i386.c |    4 +
 opcodes/i386-opc.tbl |   41 +-
 opcodes/i386-tbl.h   | 1662 +++++++++++++++-----------------------------------
 3 files changed, 520 insertions(+), 1187 deletions(-)
bisect found first bad commit
Comment 4 Jan Beulich 2024-01-05 08:41:04 UTC
I can see what I overlooked (the C attribute aliases StaticRounding); working on a fix.
Comment 6 Sourceware Commits 2024-01-09 12:50:46 UTC
The master branch has been updated by Jan Beulich <jbeulich@sourceware.org>:

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

commit 7440781b67631ebdf1b0587724f5d77c3748b034
Author: Jan Beulich <jbeulich@suse.com>
Date:   Tue Jan 9 13:49:48 2024 +0100

    x86: FMA insns aren't eligible to VEX2 encoding
    
    PR gas/31178
    
    In da0784f961d8 ("x86: fold FMA VEX and EVEX templates") I overlooked
    that C aliases StaticRounding, and hence build_vex_prefix() now needs to
    be aware of that aliasing. Disambiguation is easy, as StaticRounding is
    only ever used together with SAE (hence why the overlaying works in the
    first place).
Comment 7 Jan Beulich 2024-01-09 13:01:07 UTC
And thus fixed.