Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libffi:x86-windows crashes since update to version 3.3 on february 7th #10230

Closed
rglbssw opened this issue Feb 26, 2020 · 32 comments · Fixed by #12498
Closed

libffi:x86-windows crashes since update to version 3.3 on february 7th #10230

rglbssw opened this issue Feb 26, 2020 · 32 comments · Fixed by #12498
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@rglbssw
Copy link
Contributor

rglbssw commented Feb 26, 2020

Describe the bug
I install gtkmm:x86-windows for use in an application. everything worked fine. But with commit 7d4227f libffi was upgraded to version 3.3. Since then my application crashes on every mouse click when returning from libffi assembler code (see debugger screenshot under "Failure Logs" below).
I assume, it has to do with the target x86-windows. The libffi src folder does not contain a "win32.S" file any more, only a "win64.S"!

Environment

  • OS: Windows 10 Enterprise
  • Compiler: Visual Studio Professional 2019 16.4.5

To Reproduce
Steps to reproduce the behavior:

  1. ./vcpkg install gtkmm:x86-windows
  2. build an application using gtkmm
  3. click with mouse

I think it does not depend on gtkmm. I'm sure, a GTK3-application would also crash.

Expected behavior
I would expect no crash. This was the behaviour with libffi 3.1

Failure logs
Debugger screenshot
2020-02-26-Debugging

Additional context
The contents of the file vcpkg\installed\status:

installed-status.txt

@itayzafrir
Copy link

itayzafrir commented Feb 26, 2020

I'm also having a similar issue but with GTK in a 64bit build:

OS: Windows 10 x64
GTK: 3.22.2-2

Everything works fine in a release build, but when running a debug build I get a runtime error as soon as the application starts up.
The error is in function ffi_call_win64 which is called from ffi_call_int.

Screenshot:
Capture

@feliwir
Copy link

feliwir commented Mar 1, 2020

Having the same issue here when using Gtk

@feliwir
Copy link

feliwir commented Mar 10, 2020

Any updates on this? This is a complete blocker for debugging my application

@NancyLi1013
Copy link
Contributor

Hi all,
Sorry for the late reply. I will check this issue later.
Could you please help confirm if this can work well before libffi updaed to 3.3?

@feliwir
Copy link

feliwir commented Mar 11, 2020

@NancyLi1013 how can i install the older library version?

@NancyLi1013
Copy link
Contributor

NancyLi1013 commented Mar 11, 2020

You can use git checkout commit id to checkout a new branch to the commit that the older library version was updated.

Could you please also help provide the project case?

@NancyLi1013 NancyLi1013 added the requires:more-information This Issue requires more information to solve label Mar 11, 2020
@itayzafrir
Copy link

Any updates on this? This is a complete blocker for debugging my application

If you don't need to debug libffi then you can use the release build of it. That's what I did for now, just copied the release version and overwrote it in my app's output directory

@rglbssw
Copy link
Contributor Author

rglbssw commented Mar 11, 2020

This may be helpful in your actual painful situation. But it will not help to fix the general problem.
So please - in addition to this work around - follow Nancy's advice. If your application does not depend on newly added or modified packages it is not too hard. I myself did the following:

  • clone a new copy of vcpkg
  • create a new local branch from a commit before the commit commented "[libffi] Update to v3.3 release ([libffi] Update to v3.3 release #6119)". I decided to use the commit 7aebb48 labeled "2020.01".
  • switch to the newly created branch
  • vcpkg install gtkmm (and libxmlpp because I need it for my application). Maybe you only need to install gtk.
  • rebuild the application (debug version) using the newly created packages.
  • try running it.
    In my case, the difference ist obvious.

@rglbssw
Copy link
Contributor Author

rglbssw commented Mar 12, 2020

Here are two minimal example applications to reproduce the behavior. One is for gtk, the other one is for gtkmm. The msvs vcxproj... and props files provided with the two examples allow you to test debug and release builds for 32 and 64 bit windows. You should unpack the two zip files to the directory where your vcpkg directory resides. this will lead to a directory layout like that:

  • GtkmmSampleForVcpkg
  • GtkSampleForVcpkg
  • vcpkg

The GtkmmSample presupposes, that you vcpkg install gtkmm for the target platforms you want to build and test. To build and test the GtkSample only vcpkg install gtk is needed.

I've tested all variants with both libffi 3.3 (commit 7d4227f) and libffi 3.1 (the commit immediately before 8eaa597).
Both example apps crash in the debug builds with libffi 3.3 on both target platforms.

Hope this helps solving the issue.

GtkmmSampleForVcpkg.zip
GtkSampleForVcpkg.zip

@NancyLi1013
Copy link
Contributor

@rglbssw

Thanks for your update and detail information about this issue.
I will try to reproduce according to the projects you provided above.

@NancyLi1013 NancyLi1013 added category:port-bug The issue is with a library, which is something the port should already support and removed requires:more-information This Issue requires more information to solve labels Mar 13, 2020
@NancyLi1013
Copy link
Contributor

@rglbssw
I have tested and this issue can be reproduced on my local now.
It seems that this issue is only happened in debug type.
We will go further investigation about this.

@feliwir
Copy link

feliwir commented Mar 16, 2020

@NancyLi1013 yes it only happens in debug builds as @itayzafrir mentioned. Great you can reproduce this now!

@764994703
Copy link

@NancyLi1013 it seems that in x86-windows debug mode, in function ffi_call_int, call to _alloca leads to a failure in _RTC_CheckStackVars2, because %rsp is recovered when the ffi_call_int function return, which is after call to _RTC_CheckStackVars2. avoid using _alloca can help.
image

@NancyLi1013
Copy link
Contributor

@764994703
Thanks for your deep investigation about this.
We will try to look into it.

@PhoebeHui PhoebeHui self-assigned this Apr 13, 2020
@JackBoosY
Copy link
Contributor

I think that's a Visual Studio bug.

@pim01
Copy link

pim01 commented May 6, 2020

Following the suggestions of @rglbssw and @NancyLi1013 I checkout to the commit tagged 2020.01 where libffi:x64-windows 3.1-7 is installed. I do confirm that the .exe executes normally in debug mode with this version of the library. In the older version libbffi was installed as a static library only (and so there is no export of the dll into the application's directory), whereas in the newer version 3.3-2 libffi is installed as both static and dynamic. May be a workaround would be to compile libffi 3.3-2 as a static lib only ?

@driver1998
Copy link
Contributor

Following the suggestions of @rglbssw and @NancyLi1013 I checkout to the commit tagged 2020.01 where libffi:x64-windows 3.1-7 is installed. I do confirm that the .exe executes normally in debug mode with this version of the library. In the older version libbffi was installed as a static library only (and so there is no export of the dll into the application's directory), whereas in the newer version 3.3-2 libffi is installed as both static and dynamic. May be a workaround would be to compile libffi 3.3-2 as a static lib only ?

Allowing shared DLL is needed because vcpkg only supports dynamic DLL on Windows ARM. (insane, I know) We should be able to let it build only static lib on x86/x64.

@ChihHao-Su
Copy link

I have the same issue when using gtkmm
libffi_crash

@Ajax-Light
Copy link

Yep, experiencing the same issue. Had to run my College Project in release mode to avoid this. The libffi call is optimized away in release mode (resulting in a lot less assembly code) and also does not corrupt the stack. Maybe a memory allocation / re-allocation issue as @764994703 said.. I gave up trying to figure out the root cause... glad I found this thread !!

@Zergoma
Copy link

Zergoma commented Jun 24, 2020

hello

I've got the same problem
Windows 7 pro
Visual Studio 2019 Community
x64
debug mode

soo sad ... I really hope a fix

image

@Zergoma
Copy link

Zergoma commented Jun 24, 2020

hello

I'm surprized: dependency walker seems to find that the vcruntime is ... 140 Oo' (for both, release [who is working] and debug)
Is that normal ? I expected something like 142 to be honest for vs2019 ... [sorry if I say something stupid]
Is that related for the crash or nothing at all ?

image

@NancyLi1013
Copy link
Contributor

Hi all,
Could you please rebuild this based on the PR #12498 from @Mixaill ?
After disabling runtime stack check for libffi, I cannot reproduce this issue on my local now.

@ice0
Copy link
Contributor

ice0 commented Jul 21, 2020

@NancyLi1013 just checked on my own project - all works fine!

@rglbssw
Copy link
Contributor Author

rglbssw commented Jul 22, 2020

Works fine for x64-windows. I tried to extend the solution for x86-windows (see #12498 (comment)).

@Ajax-Light
Copy link

[Newbie Question]: Shouldn't we find out what caused the Stack Corruption instead of disabling the Runtime Check? I don't mean to offend / belittle the work done by @Mixaill and @rglbssw , but I would like to know what caused the Stack to be corrupted in the first place.

According to Microsoft Docs, one of the reasons /RTC fails is due to a calling convention mismatch. I have tried setting different calling conventions like _stdcall or _cdecl , but the crash persists. The other reasons include overruns / under-runs of memory; Padding issues with Struct Member Alignment ( /Zp ), which I am currently looking into..

@JackBoosY
Copy link
Contributor

@Ajax-Light It's a Visual Studio bug.

@Mixaill
Copy link
Contributor

Mixaill commented Jul 23, 2020

Shouldn't we find out what caused the Stack Corruption instead of disabling the Runtime Check?

It is the intended behavior for libffi, it modfies stack of the caller function which results in RTC trigger. No actual error here.

@Ajax-Light
Copy link

Ah! I understand now. Thanks for your time. 👍

@rglbssw
Copy link
Contributor Author

rglbssw commented Aug 5, 2020

Thanks to all at any place!
Especially I'd like to praise:
@Mixaill who broke the Gordian knot
and @NancyLi1013 who tamed the wild blue bot
in its azure pipeline maze.

(... e grazie a la @strega-nil)

@ghost
Copy link

ghost commented Aug 14, 2020

It is still happening for me, do I need to do something to apply the fix?

gtkbug

@rglbssw
Copy link
Contributor Author

rglbssw commented Aug 14, 2020

Seems as if the patch was not applied already. The code would look a bit different, if it was.
Did you do a "vcpkg upgrade" after pulling?
If you tried the pull request before it was merged, especially if you did that before it contained the x86-windows patch, it is possible, that vcpk doesn't recognize the package as outdated. In this case you should vcpkg remove the package and vcpkg install it again. If vcpkg decides to restore it from a cached version, delete the cached version and try it again.

@faserg1
Copy link
Contributor

faserg1 commented Sep 10, 2020

Have installed with gtkmm as root package. Same issue. x64-windows.
UPD: Installed vcpkg as submodule, so I have to git submodule update --init --recursive --remote. Now should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

Successfully merging a pull request may close this issue.