Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 660506 - sys-devel/crossdev-20180508 / i686 / mingw: any exe crashs at start (CFLAGS=-mindirect-branch=thunk)
Summary: sys-devel/crossdev-20180508 / i686 / mingw: any exe crashs at start (CFLAGS=-...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-06 11:23 UTC by fkater
Modified: 2021-06-29 21:02 UTC (History)
4 users (show)

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


Attachments
the generated/crashing binary (a.exe,34.01 KB, application/octet-stream)
2018-07-06 14:08 UTC, fkater
Details
output of emerge --info (emerge-info.txt,5.44 KB, text/plain)
2018-07-06 14:08 UTC, fkater
Details
output of i686-w64-mingw32-gcc -v (i686-w64-mingw32-gcc-v.txt,1.47 KB, text/plain)
2018-07-06 14:09 UTC, fkater
Details
eventviewer entry after crash (a.exe-crash-eventvwr.txt,403 bytes, text/plain)
2018-07-06 14:10 UTC, fkater
Details
output of the crash dialog itself (a.exe-crash-message.txt,819 bytes, text/plain)
2018-07-06 14:11 UTC, fkater
Details

Note You need to log in before you can comment on or make changes to this bug.
Description fkater 2018-07-06 11:23:05 UTC
Any exe we build with crossdev-20180508 (mingw) crashes immediately when run.

This report https://bugs.gentoo.org/show_bug.cgi?id=644930 is very similar but
the resolution does not help (crossdev was ugraded meanwhile).

Details:

- fresh Gentoo installation (also tried on other Gentoo boxes)

- crossdev version: 20180508

- toolchain we tried:

  crossdev --gcc 7.3.0-r1 --binutils 2.29.1-r1 
  --ov-output /usr/local/portage-overlays/ 
  --genv 'USE="-fortran -vtv -sanitize -pie -hardened"'
  i686-w64-mingw32

- other toolchains we tried: i686-pc-mingw32, setting/not setting -pie and
  -hardened, with/without --gcc and --binutils etc

- used C program test.c: int main(int c, char** av){ return 0; }

- compilation command: i686-w64-mingw32-gcc test.c

- a.exe started under Windows 7 (several boxes): crash immediately

- same program compiled for linux, with/without printf(): works ok

- compiling with -static or -static-libgcc: no change




Reproducible: Always
Comment 1 Sergei Trofimovich (RETIRED) gentoo-dev 2018-07-06 12:56:24 UTC
Can you provide a few more details?
1. 'emerge --info' for a host system
2. 'i686-w64-mingw32-gcc -v' output
3. attach binary resulting from 'i686-w64-mingw32-gcc test.c' compilation
4. crash details from windows box. maybe eventlog contains something like a backtrace with addresses.
Comment 2 fkater 2018-07-06 14:08:07 UTC
Created attachment 538568 [details]
the generated/crashing binary
Comment 3 fkater 2018-07-06 14:08:57 UTC
Created attachment 538570 [details]
output of emerge --info
Comment 4 fkater 2018-07-06 14:09:44 UTC
Created attachment 538572 [details]
output of i686-w64-mingw32-gcc -v
Comment 5 fkater 2018-07-06 14:10:36 UTC
Created attachment 538574 [details]
eventviewer entry after crash
Comment 6 fkater 2018-07-06 14:11:10 UTC
Created attachment 538576 [details]
output of the crash dialog itself
Comment 7 fkater 2018-07-06 14:11:45 UTC
Thanks for asking. Attachements created.
Comment 8 Sergei Trofimovich (RETIRED) gentoo-dev 2018-07-06 19:10:10 UTC
In your binary I see unusual code in CRT startup code like:

  00401000 <___mingw_invalidParameterHandler>:
    401000:	ff 25 3a 15 40 00    	jmp    *0x40153a

while mine (working) has:

  00401000 <___mingw_invalidParameterHandler>:
    401000:	c3                   	ret    

I think it's caused by retpoline flags. Your CFLAGS are:

    CFLAGS="-march=core2 -g0 -O3 -pipe -fomit-frame-pointer -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register -fno-diagnostics-show-caret"

Can you try to rebuild
    cross-i686-w64-mingw32/mingw64-runtime
with safer CFLAGS (ideally drop flags one by one to find the culprit) and check it it workarounds failure for you?
Comment 9 fkater 2018-07-09 09:46:05 UTC
(In reply to Sergei Trofimovich from comment #8)

> In your binary I see unusual code in CRT startup code like:
> 
>   00401000 <___mingw_invalidParameterHandler>:
>     401000:	ff 25 3a 15 40 00    	jmp    *0x40153a
> 
> while mine (working) has:
> 
>   00401000 <___mingw_invalidParameterHandler>:
>     401000:	c3                   	ret    
> 
> I think it's caused by retpoline flags. Your CFLAGS are:
> 
>     CFLAGS="-march=core2 -g0 -O3 -pipe -fomit-frame-pointer
> -mindirect-branch=thunk -mfunction-return=thunk -mindirect-branch-register
> -fno-diagnostics-show-caret"
> 
> Can you try to rebuild
>     cross-i686-w64-mingw32/mingw64-runtime
> with safer CFLAGS (ideally drop flags one by one to find the culprit) and
> check it it workarounds failure for you?

Thanks for the terrific support.

Leaving out all three -minderiect-* CFLAGS fixed the issue.

I'll now try to recompile mingw64-runtime with some combinations of the above
flags to narrow down the causes a bit further.
Comment 10 fkater 2018-07-09 13:04:23 UTC
Can the CFLAGS be specified for crossdev only, so elsewhere than in
/etc/portage/make.conf, to keep that separate from the hosts CFLAGS?


And here the results of more tests, for completeness:

#
# works
#
CFLAGS="-march=core2 -g0 -O3 -pipe -fomit-frame-pointer -fno-diagnostics-show-caret"

#
# variant1 -- crash
#
#CFLAGS="-march=core2 -g0 -O3 -pipe -fomit-frame-pointer -mindirect-branch=thunk -mfunction-return=thunk -fno-diagnostics-show-caret"

#
# variant2 -- crash
#
#CFLAGS="-march=core2 -g0 -O3 -pipe -fomit-frame-pointer -mindirect-branch=thunk -mindirect-branch-register -fno-diagnostics-show-caret"

#
# variant3 -- crash
#
#CFLAGS="-march=core2 -g0 -O3 -pipe -fomit-frame-pointer -mfunction-return=thunk -mindirect-branch-register -fno-diagnostics-show-caret"
Comment 11 Sergei Trofimovich (RETIRED) gentoo-dev 2018-07-09 19:14:19 UTC
(In reply to fkater from comment #10)
> Can the CFLAGS be specified for crossdev only, so elsewhere than in
> /etc/portage/make.conf, to keep that separate from the hosts CFLAGS?

I suggest using https://wiki.gentoo.org/wiki/etc/portage/package.env
It should look like

    /etc/portage/env/safer-cflags.conf:
        CFLAGS="-march=core2 -g0 -O3 -pipe -fomit-frame-pointer -fno-diagnostics-show-caret"

    /etc/portage/package.env:
        cross-i686-w64-mingw32/mingw64-runtime safer-cflags.conf
Comment 12 Sergei Trofimovich (RETIRED) gentoo-dev 2019-12-23 00:15:20 UTC
Invalid generated code it more likely a dev-util/mingw64-runtime bug or sys-devel/gcc bug (if trampolines can be statically resolved). Reassigning to toolchain@.