FS#75508 - [mingw-w64-gcc] Cannot Build GCC Plugins
Attached to Project:
Community Packages
Opened by semper victus (rageltman) - Thursday, 04 August 2022, 08:52 GMT
Last edited by Toolybird (Toolybird) - Monday, 15 August 2022, 04:59 GMT
Opened by semper victus (rageltman) - Thursday, 04 August 2022, 08:52 GMT
Last edited by Toolybird (Toolybird) - Monday, 15 August 2022, 04:59 GMT
|
Details
Description:
MinGW builds in Arch are unable to build any GCC plugins. Steps to reproduce: 1. Get sources for a plugin 2. Build with GCC-native to verify current GCC builds it correctly 3. Attempt to build with same architecture MinGW used in step 2 for consistency. 3a. Watch it crash over various conflicting types and missing files (usually starting with `fatal error: sys/wait.h: No such file or directory`) |
This task depends upon
Closed by Toolybird (Toolybird)
Monday, 15 August 2022, 04:59 GMT
Reason for closing: Not a bug
Additional comments about closing: See comments
Monday, 15 August 2022, 04:59 GMT
Reason for closing: Not a bug
Additional comments about closing: See comments
1. `git clone https://github.com/marcolatella/SecRetAddress ; cd SecRetAddress` to acquire sources - any and every GCC plugin will fail to build in the same manner though (looking for POSIX headers).
2. `make && make clean` to verify that it builds with host-native g++
3. `sed -i 's|g++|x86_64-w64-mingw32-g++|g; s|gcc|x86_64-w64-mingw32-gcc|g' Makefile` to convert the Makefile to use mingw
4 `make` to see the breakage happen:
```
$ make
x86_64-w64-mingw32-g++ -std=gnu++11 -I`x86_64-w64-mingw32-gcc -print-file-name=plugin`/include -fPIC -shared -fno-rtti -O2 plugin.cpp -o plugin.so
In file included from /usr/lib/gcc/x86_64-w64-mingw32/12.1.0/plugin/include/gcc-plugin.h:28,
from plugin.cpp:12:
/usr/lib/gcc/x86_64-w64-mingw32/12.1.0/plugin/include/system.h:408:10: fatal error: sys/wait.h: No such file or directory
408 | #include <sys/wait.h>
| ^~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:5: plugin.so] Error 1
```
MinGW reports as being able to compile plugins, so this should be working:
```
$ x86_64-w64-mingw32-gcc -print-file-name=plugin
/usr/lib/gcc/x86_64-w64-mingw32/12.1.0/plugin
```
mingw-w64-gcc is a *cross* compiler targeting Windows. The "host" is Arch Linux. GCC plugins run on the host as part of the compiler. You're trying to build it for the *target* which simply cannot work and explains why you're getting errors about POSIX headers etc. Please see here [2] for a related example which might steer you in the right direction.
[1] https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
[2] https://stackoverflow.com/questions/62170606/gcc-plugin-compilation-issue
Could you please provide instructions on how to compile the plugin for use with with the toolchain if i'm somehow doing it incorrectly? Compiling a plugin using the host-native GCC does not permit mingw to use it when compiling Windows code on Linux.
Sorry, you're still not getting it. Please seek help in the support channels (forum/IRC/etc).