msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.3k stars 1.22k forks source link

binutils-2.31.1 gold linker broken with plugins enabled. #4104

Closed revelator closed 2 years ago

revelator commented 6 years ago

Seems gold has plugin support as well, but none that work with windows. Unfortuantly golds plugin support also gets enabled when we specify plugin support so the build fails.

revelator commented 6 years ago

The problem is dlfcn-win32, SYSTEMTIME and FILETIME comes from minwinbase.h which is included by winbase.h and finally by windows.h, dlfcn.h includes neither and the gold plugin seems to assume that it does so these end up undefined if dlfcn-win32 is installed with the current patchset. moving the dlfcn.h header out of the place fixes things but it would probably be better with a more permanent fix.

Alexpux commented 6 years ago

@revelator I dont install dlfch-win32 at all in system because in this case most packages will build with it.

revelator commented 6 years ago

So should we remove it from packages ?

Alexpux commented 6 years ago

@revelator I will leave it in packages but I dont recommend to install it if you really dont need it. I will not build packages that depends on this library

revelator commented 6 years ago

Seems resonable, it was mostly intended as a tool for porting some stubborn packages anyway.

revelator commented 6 years ago

Hmm small whoops, previous binutils linked with dlfcn-win32 worked fine with liblto_plugin.dll copied to /mingw/lib/bfd-plugins, using the builtin version in the new 2.31.1 build yields unable to load dll :s so it seems to be broken or ?.

Alexpux commented 6 years ago

@revelator As I know plugins not working without dlfcn-win32

revelator commented 6 years ago

Ah damn, i wonder what changed from previous versions since this no longer works. Maybe i should ready a patch fixing up binutils dlfcn replacement functions based on dlfcn-win32, would this be considered apropriate ?. LTO builds work much better when this plugin works so id really like to have it back.

Alexpux commented 6 years ago

@revelator create pull request and i will look

revelator commented 6 years ago

Will do, will probably take some testing and comparing it with earlier builds to see why it broke in this release in the first place, but as soon as i have something solid ill make a pull request.

revelator commented 6 years ago

Ok got it working, one small snag though, it requires linking in the psapi library and binutils dont link this in by default, so where would be the best place to add this in the autotools chain ?.

Alexpux commented 6 years ago

@revelator possibly need to add additional library in configure script

revelator commented 6 years ago

Oki, ill see what i can come up with. Easier way though is just exporting LIBS+="-lpsapi" but thats a bit messy.

revelator commented 6 years ago

Not having much luck finding a good place to getting this library in yet. I have a hunch that i might need to do some additions to configure.ac and then rebuild the autotool toolchain, the only places i found where i could plug it in are to specific to some code, and atm i need this library linked in with bfd ld ranlib and gold. Besides that it works extremely well now if i just link psapi in globally.

revelator commented 6 years ago

Uh oh... anyone remember the bug in binutils-2.26 with to many files open ? guess what its back. To make sure it had nothing to do with my fixing the dlfcn replacements for plugin support i tried downloading an unmodified version from here and it also has this.

Try building clang, the error comes allmost at the end of the build. Had to downgrade to 2.25 to be able to build clang.

revelator commented 5 years ago

0030-fix-plugin-support.zip

finally got it done, it became a bit messy but now binutils support loading plugin dll's like the lto_plugin.dll if it is placed in /mingw*/lib/bfd-plugins.

The dlfcn code was taken from dlfcn-win32 because the inbuilt minimal version does not support loading plugins from external folders.

This patch also works with binutils-2.30

mati865 commented 5 years ago

Gold linker doesn't use BFD and supports only ELF format, porting it would need a lot of effort. I doubt it'd be worth the time.

revelator commented 5 years ago

true i could probably remove the plugin support from the gold linker to simplify the patch a bit. Strangely even though bfd has plugin support it seems ld also needs the same code which is kinda overkill. Ill see if i can come up with a way to simplify things a bit, but in the meantime feel free to use my patch if you like.

MehdiChinoune commented 2 years ago

gold linker is no longer supported/shipped on Windows.