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
Task Type Bug Report
Category Packages
Status Closed
Assigned To No-one
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

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
Comment by Toolybird (Toolybird) - Thursday, 04 August 2022, 23:52 GMT
What plugin? Please provide exact steps to reproduce.
Comment by semper victus (rageltman) - Friday, 05 August 2022, 12:40 GMT
Steps to reproduce:
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

```
Comment by semper victus (rageltman) - Friday, 12 August 2022, 11:20 GMT
@Toolybird: any luck reproducing?
Comment by Toolybird (Toolybird) - Monday, 15 August 2022, 03:02 GMT
I think you might be confused which makes this a support issue. The way you are trying to do things makes no sense at all. You need to get your head around "host", "build", "target", etc [1].

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
Comment by semper victus (rageltman) - Monday, 15 August 2022, 03:37 GMT
The GCC plugin is part of the toolchain which is built for the host, i'm not trying to build it against the target environment, but since the target of the plugin is a cross compiler on the host, it seems to pull in the wrong headers.
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.
Comment by Toolybird (Toolybird) - Monday, 15 August 2022, 04:59 GMT
> Could you please provide instructions

Sorry, you're still not getting it. Please seek help in the support channels (forum/IRC/etc).

Loading...