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

GCC 10.2.0-6 with LTO segfaults #8074

Open
andrew-aladev opened this issue Mar 6, 2021 · 7 comments
Open

GCC 10.2.0-6 with LTO segfaults #8074

andrew-aladev opened this issue Mar 6, 2021 · 7 comments

Comments

@andrew-aladev
Copy link

andrew-aladev commented Mar 6, 2021

Please refer the following issue on cmake gitlab.

If you tries to enable IPO (GCC LTO) in cmake using mingw-w64-x86_64-gcc version 10.2.0-6, than you executable segfaults.

Please checkout IPO folder with easy project that reproduces the issue.

@lazka
Copy link
Member

lazka commented Mar 8, 2021

I can confirm, but no idea. We build CPython with LTO+PGO, so LTO can work with our toolchain.. if that helps.

@mati865
Copy link
Collaborator

mati865 commented Mar 8, 2021

You are not exporting symbols in DLL correctly, mingw-w64 can often workaround it by using runtime pseudo relocations but it's fragile.

You should build your DLL with __declspec(dllexport) annotations or pass --export-all-symbols to the linker.

@andrew-aladev
Copy link
Author

Thank you, I am going to add decls together with WINDOWS_EXPORT_ALL_SYMBOLS. But segfault is not an user friendly solution, maybe mingw gcc can add linker warning that symbols were not properly exported for windows.

PS previous version of mingw-w64-x86_64-gcc installed by default in appveyor (version <= 10.2.0-5) works perfect, we can view the following log.

@andrew-aladev
Copy link
Author

andrew-aladev commented Mar 27, 2021

Unfortunately today gcc has critical issue that makes dllexport usage impossible. --export-all-symbols is not possible with cmake, because mingw platform has no CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS in platform file Windows-GNU.cmake. Forcing of set (CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS 1) reveals that it is broken. So for now there is no way to fix lto in mingw. If you want to export inline C99 than mingw LTO won't work.

Suddenly new MSVC with C17 turned out to be not so bad: dllexport works perfect with any data and functions, LTO works fine, hmm...

@jtanx
Copy link
Contributor

jtanx commented Mar 28, 2021

This is what we do to export all symbols, it works just fine.

https://github.com/fontforge/fontforge/blob/d867fe0ab9c1edb2a5d268f713b72bef7146d59b/fontforge/CMakeLists.txt#L224

@andrew-aladev
Copy link
Author

andrew-aladev commented Apr 2, 2021

Unfortunately, -Wl,--export-all-symbols -Wl,--enable-auto-import is not working for current mingw gcc version + LTO. The only one possible option is dllexport/dllimport.

# make
C:/msys64/mingw64/bin/cc.exe -flto -fno-fat-lto-objects -o CMakeFiles/fit.dir/a1.c.obj -c C:/fit1/a1.c
C:/msys64/mingw64/bin/cc.exe -flto -fno-fat-lto-objects -o CMakeFiles/fit.dir/a2.c.obj -c C:/fit1/a2.c
C:/msys64/mingw64/bin/cc.exe -flto -fno-fat-lto-objects -Wl,--export-all-symbols -Wl,--enable-auto-import -shared -o libfit.dll -Wl,--out-implib,libfit.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles/fit.dir/objects.a -Wl,--no-whole-archive @CMakeFiles/fit.dir/linklibs.rsp
C:/msys64/mingw64/bin/cc.exe -flto -fno-fat-lto-objects -o CMakeFiles/main.dir/main.c.obj -c C:/fit1/main.c
C:/msys64/mingw64/bin/cc.exe -flto -fno-fat-lto-objects -Wl,--whole-archive CMakeFiles/main.dir/objects.a -Wl,--no-whole-archive -o main.exe -Wl,--out-implib,libmain.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/main.dir/linklibs.rsp
./main.exe
Segmentation fault

@andrew-aladev
Copy link
Author

andrew-aladev commented Apr 2, 2021

-Wl,--export-all-symbols works perfect and you are receiving libfit.dll with exported function. But it is not possible to import it automatically without dllimport. So there are 2 options: -Wl,--export-all-symbols + dllimport or dllexport + dllimport for now.

This bug appeared today, but nobody can guarentee that it won't happen tomorrow. I thought that there are 2 possible export modes: dllexport + dllimport or export all / import all. But there are actually 4 possible export modes: dllexport + dllimport, export all + dllimport, dllexport + import all, export all + import all.

standards

Do you remember this meme? It was wrong: if you have 14 standards and someone tries to add +1 standard than you will receive all combinations between 14 standards and 1 additional standard (turned off and turned on) = 28 standards. If someone tries to add 2 standards (gnu and bsd) than we will receive 56 standards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants