Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 786549 - dev-util/mingw64-runtime fails to build due to __rdtsc() redefinition with gcc11
Summary: dev-util/mingw64-runtime fails to build due to __rdtsc() redefinition with gcc11
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks: gcc-11
  Show dependency tree
 
Reported: 2021-04-28 20:16 UTC by Mihai Donțu
Modified: 2021-05-02 10:17 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
crossdev log file (cross-x86_64-w64-mingw32-info.log,19.79 KB, text/x-log)
2021-04-28 20:19 UTC, Mihai Donțu
Details
crossdev log file (runtime) (cross-x86_64-w64-mingw32-mingw64-runtime.log.xz,44.56 KB, application/x-xz)
2021-04-28 20:20 UTC, Mihai Donțu
Details
crossdev log file (runtime config) (mingw64-runtime-config.logs.tar.xz,7.62 KB, application/x-xz)
2021-04-28 20:20 UTC, Mihai Donțu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mihai Donțu 2021-04-28 20:16:59 UTC
I have been trying to emerge x86_64-w64-mingw32 via crossdev for a while now, as suggested by the app-emulation/wine-vanilla[mingw] ebuild. The build failed with gcc 10.2, but surprisingly it did not affect the emerge of wine-vanilla. Today I gave it another shot with gcc 11.1 and after removing -fstack-clash-protection from make.conf (causes ICE) I got stuck here and decided to file a bug:

In file included from /usr/lib/gcc/x86_64-w64-mingw32/11.1.0/include/x86gprintrin.h:27,
                 from /usr/lib/gcc/x86_64-w64-mingw32/11.1.0/include/x86intrin.h:27,
                 from /var/tmp/portage/cross-x86_64-w64-mingw32/mingw64-runtime-8.0.0/temp/tmproot/include/intrin.h:73,
                 from intrincs/rdtsc.c:7:
/usr/lib/gcc/x86_64-w64-mingw32/11.1.0/include/ia32intrin.h:110: note: macro "__rdtsc" defined here
  110 | #define __rdtsc()               __builtin_ia32_rdtsc ()
      | 
intrincs/rdtsc.c:16:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   16 | {
      | ^


Reproducible: Always

Steps to Reproduce:
Run: crossdev --target x86_64-w64-mingw32
Comment 1 Mihai Donțu 2021-04-28 20:19:49 UTC
Created attachment 703473 [details]
crossdev log file
Comment 2 Mihai Donțu 2021-04-28 20:20:15 UTC
Created attachment 703476 [details]
crossdev log file (runtime)
Comment 3 Mihai Donțu 2021-04-28 20:20:30 UTC
Created attachment 703479 [details]
crossdev log file (runtime config)
Comment 4 Ionen Wolkens gentoo-dev 2021-04-28 21:06:40 UTC
__rdtsc is a new gcc11 mingw64-runtime issue

https://sourceforge.net/p/mingw-w64/mailman/message/37259429/

Unsure if above patch is complete/proper for gcc11, haven't took the time to look into this.
Comment 5 Mihai Donțu 2021-04-28 21:38:44 UTC
The patch worked. Thank you!
Comment 6 Sergei Trofimovich (RETIRED) gentoo-dev 2021-04-28 21:42:26 UTC
'#if !__has_builtin(__rdtsc)' is a nasty check. I think the original intent is to check if compiler (MSVC) provides __rdtsc builtin.

Instead it gets fooled by a (incompatible) compat define: 

/usr/lib/gcc/x86_64-w64-mingw32/11.1.0/include/ia32intrin.h:110: note: macro "__rdtsc" defined here
  110 | #define __rdtsc()               __builtin_ia32_rdtsc ()

That effectively checks for __builtin_ia32_rdtsc.

Given it's a namespace clash simplest would be to not rely on gcc's __rdtsc.
Comment 7 Larry the Git Cow gentoo-dev 2021-04-28 21:58:56 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=40d0fd393ac48096a4e826f3eb941a21142a1f41

commit 40d0fd393ac48096a4e826f3eb941a21142a1f41
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-04-28 21:58:19 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-04-28 21:58:54 +0000

    dev-util/mingw64-runtime: fix build against gcc-11 (__rdtsc clash)
    
    gcc-11 defines __rdtsc as a macro:
        // include/ia32intrin.h:110
        #define __rdtsc() __builtin_ia32_rdtsc ()
    and causes build failure:
        intrincs/rdtsc.c:15:30:
          error: macro "__rdtsc" passed 1 arguments, but takes just 0
           15 | unsigned __int64 __rdtsc(void)
              |                              ^
    
    Let's avoid __rdtsc definition on systems with #define __rdtsc present.
    
    There is still a chance that it might be a '#define __rdtsc __rdtsc'.
    We'll revisit it then.
    
    Reported-by: Mihai Donțu
    Closes: https://bugs.gentoo.org/786549
    Package-Manager: Portage-3.0.18, Repoman-3.0.3
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 .../files/mingw64-runtime-8.0.0-__rdtsc.patch      |  25 +++++
 .../mingw64-runtime-8.0.0-r1.ebuild                | 119 +++++++++++++++++++++
 2 files changed, 144 insertions(+)