fixing MinGW compilation

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
dpJudas
 
 
Posts: 3040
Joined: Sat May 28, 2016 1:01 pm

Re: fixing MinGW compilation

Post by dpJudas »

Chris wrote:Passing "complex" resources, such as std::string, between DLL/module boundaries has always been problematic. You can't safely pass such resources between them as anything but raw externally-owned memory if you're not sure you're using the same library since they can expect different sizes and layouts. But I don't see what that has to do with the given discussion of a library's own separate dependencies being a problem for the main app.
It has to do with the fact that the list of dependencies passed into the linker is often only a subset of the total set. Your main argument against the #pragma, the way I understood it, was that the #pragma hided information that would be otherwise visible. That limitation is there for dynamic libraries as well.

I agree with you that an ideal written dynamic library uses a plain C interface with no reliance on other libraries in its public interface. But it is also an unreasonable proposition for a lot of types of projects. We don't even have to bring C++ into this. Let's imagine that I'm writing a dynamic library adding a QMainWindow equivalent for Gtk+. My library extends another library, so I don't really have a choice - my public interface has to expose Gtk+ types unless you expect me to spend the majority of the time writing wrapper binding code. Thus in the real world there's lots and lots of dynamic libraries where their internal dependencies very much matter to the main executable.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: fixing MinGW compilation

Post by Graf Zahl »

As so often the Linux side argues by seeing things in an idealistic way, where everybody should and would adhere to overambitious guidelines. Each time this will cause problems down the line. It's precisely the same with that godforsaken "link everything dynamically" attitude that has ground my employer's servers to a halt multiple times already because despite all the supposed safeguards some bogus library still got in and screwed things up.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: fixing MinGW compilation

Post by drfrag »

I find the crash on exit more of a concern than that PIE flag.
The tdm-gcc executable runs on win98 (this is just a curiosity) without sound. Probably recompiling the dlls someone could get sound there. Compiling your own cross-compiler with MinGW-w64 is possible to target even win95 but i don't know how to do it, not that i think that could be useful in general.

Then can the non SSE version of the software renderer actually be expected to run on anything lower than a P4 on x86 now?
Crashes on both a P3 and an Athlon XP, looks like SSE2 is being used somewhere. I already restored DoBlending_MMX.
@dpJudas: Do you think debugging on such a machine would be a good idea? (i know you think it's not but you know what i mean, if it actually could lead somewhere or it's hopeless). Thanks.
I don't know how to disable SSE2 on a virtual machine, if that's even possible.
dpJudas
 
 
Posts: 3040
Joined: Sat May 28, 2016 1:01 pm

Re: fixing MinGW compilation

Post by dpJudas »

The software renderer, as it is on gzdooom master, can run without SSE2 -- it runs that way on the Raspberry Pi. The performance is significantly worse, though. I don't think it is worth the effort to get it to run on something lower than a P4 as it will most likely be too slow.
User avatar
Chris
Posts: 2941
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: fixing MinGW compilation

Post by Chris »

dpJudas wrote:Let's imagine that I'm writing a dynamic library adding a QMainWindow equivalent for Gtk+. My library extends another library, so I don't really have a choice - my public interface has to expose Gtk+ types unless you expect me to spend the majority of the time writing wrapper binding code. Thus in the real world there's lots and lots of dynamic libraries where their internal dependencies very much matter to the main executable.
In that case your external interface depends on Gtk+, so by definition it's not an internal dependency but an external one. Anyone using your lib will also be using Gtk+. And with GCC and Clang, an app using your lib will have to link with Gtk+ explicitly; the implicit dependency on Gtk+ via your lib will not satisfy the app's use of Gtk+ functions/symbols (this actually used to be a problem, that an app's use of functions/symbols could be satisfied by a dependency's dependency; it would end up causing errors when said dependency was updated and changed its own dependencies making the needed libs no longer available).

In contrast, my library uses libpulse.so internally. Or I can swap it out with a different one that uses libsdl2.so internally. Or yet another one that uses libasound.so internally. Or another that static-links what it uses internally. It's an internal dependency, an app that uses my lib doesn't know (or care) what it's using because it's internal, the external interface and behavior is the same regardless.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: fixing MinGW compilation

Post by drfrag »

-pie
Produce a position independent executable on targets that support it. For predictable
results, you must also specify the same set of options used for compilation (-fpie,
-fPIE, or model suboptions) when you specify this linker option.
I've investigated and that's just bad language, -fPIE is not a linker option and that just means you also need to add those compilation options.

On the NO_SSE build no need to debug anything, i revised the build log and some files were still compiled with SS2. Now it's fixed. Also it only runs without sound, the included OpenAL ddl is compiled with SSE2. I don't know if OpenAL now requires SSE2 if so i'd need to use an older version. It's actually pretty fast. On an Athlon XP 2400+ i get 117 fps @640 with gcc 7, VS would be probably faster. On a 2.4 GHz it's slower (90 fps) but the SSE2 version could be much faster (this is 8 bit). On a P3 1 GHZ i get 50 with gcc 5 but the game is somewhat choppy (even @320) and with cl_capfps on i get 18 fps instead of 35, i guess a side effect of the new timing code. That was on win 98 BTW.
And that old code for 1.4 PS cards was definitely broken in truecolor (weapon, status bar and menus), good riddance i guess. For truecolor PS 2.0 was effectively required so now with GL 2.0 the requirement would be the same. Restoring support for old processors for gcc won't harm and the solution is pretty simple and clean as you can see. Would make sense even after the refactoring (there were up to 3100+ XP processors and any crappy GL 2.0 card could be enough).
Last edited by drfrag on Tue May 01, 2018 3:12 pm, edited 2 times in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: fixing MinGW compilation

Post by Graf Zahl »

drfrag wrote: On the NO_SSE build no need to debug anything, i revised the build log and some files were still compiled with SS2. Now it's fixed. Also it only runs without sound, the included OpenAL ddl is compiled with SSE2.

You will find out that this is increasingly the case with modern code, because most software developers really do not care anymore about those old systems. You may also have to recompile some of the other DLLs - I have no idea which use SSE 2 and which don't.
But the signs are there: Those legacy computers will soon be left behind for good with software being compiled with current toolchains simply containing machine language features these old systems cannot handle.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: fixing MinGW compilation

Post by _mental_ »

drfrag wrote:I've investigated and that's just bad language, -gPIE is not a linker option and that just means you also need to add those compilation options.
So, adding -fPIE to linker options didn’t help to make proper ASLR aware 64-bit executable, right?
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: fixing MinGW compilation

Post by drfrag »

Sorry i haven't even compiled a 64 bit version yet, my "dev computer" runs win 8.1 32 bit since it has only 2 GB of ram. In theory i could cross-compile but i'd have to cheat and use the 32 bit c executables. The right package is x86_64-7.3.0-release-posix-seh-rt_v5-rev0.7z.
But you're probably more familiarized with gcc than me and that's not a linker option, you've tested on linux and it worked so your commit was fine.
From MinGW-user forum (old post):
>I know Linux and Windows work differently and that Windows does not
>really need this kind of things (since it uses relocation table)...

Effectively that relocation table makes the code position independent.

>... but my question is: is there however an option to generate such code
>on Windows with mingw ?

No, there is no compiler, assembler, linker or runtime support for
"Linux-style" PIC code in the MinGW tools.
Another guy wrote somewhere else:
MinGW's compiler is based on GCC and as such supports PIE to some extent. Unfortunately I found that the '-pie' compiler option was causing the entry point to the executable to point away from the main() function. It was hitting MinGW's dummy main() instead and the executable was returning immediately.
So probably it's a bug i dunno.

I've recompiled OpenAL without SSE2 and now the game runs but i get sound init failed on win 98, i guess that's normal. The other machine is in the garage.
I've also recompiled FluidSynth (still crashed) but i haven't tested it yet.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: fixing MinGW compilation

Post by drfrag »

I've installed the environment on my 64 bit laptop, it really only took a few minutes.
This is what i did: unzipped x86_64-7.3.0-release-posix-seh-rt_v5-rev0.7z in C:\DEV, unzipped cmake-3.9.6-win32-x86.zip and extracted the source too. Then added 'C:\DEV\mingw64\bin;' to the system Path. And ran CMake and selected MinGW makefiles: D3D_INCLUDE_DIR 'C:/DEV/mingw64/x86_64-w64-mingw32/include', DX libs 'C:/DEV/mingw64/x86_64-w64-mingw32/lib/'. I compiled from the command line with 'mingw32-make -j2'. It's advisable to increase the cmd buffer size .

Now, did it work? Of course not. The makefile actually invokes gcc with -fPIE twice, but it doesn't matter since that's not a linker flag.
I've successfully built the 64 bit executable, same crash on exit BTW.

I've recompiled fluidsynth as well and tested on XP, on the K7 machine the game runs fine now. But fluidsynth depends on a lot of dlls, i don't know how to merge all those dlls in fluidsynth.dll.

On the crash on exit i've been debugging it without luck, more on its thread.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: fixing MinGW compilation

Post by _mental_ »

You need to build all FluidSynth dependencies as static libraries. Mostly it's about GLib.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: fixing MinGW compilation

Post by drfrag »

Easier said than done, i guess il'll try. For now i'm using a version of fluidsynth 1.1.6 without the GLib dependency from here: https://www.vogons.org/viewtopic.php?f= ... 40#p630425.

Some news:
I've reported the crash on exit as a MinGW-w64 C runtime bug at https://sourceforge.net/p/mingw-w64/bugs/734/ but i guess i'll have to add a workaround.
I can't think of a better solution that the exiting global variable to kick it out of there and return NULL (leaking memory on exit it's not important). Is this really that bad? :)

I suspect i've been too agressive porting stuff to the old codebase. I wonder what transfer heights are, should i be worried? :) Apparently it's okay but there are a few commits i'm not sure about them.
https://github.com/drfrag666/gzdoom/commits/g3.3mgw

This one about gitinfo.h included in version.h is driving me nuts, i've tried regenerating and rebuilding the project but no avail. It introduces a delay on every commit and that's annoying to me, i might even revert it completely. Only commenting out the include works.
https://github.com/drfrag666/gzdoom/com ... c7fa81bad2

The PR when the refactoring is complete is pending stuff.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: fixing MinGW compilation

Post by drfrag »

I've found another problem, the -iwad command line parameter now only works with VS in windows so you can't launch iwads with ZDL. I'll investigate it.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: fixing MinGW compilation

Post by drfrag »

It's fixed, i've debugged it and was a wrong #define.
https://github.com/drfrag666/gzdoom/com ... 11f5f15709

On the gitinfo.h thing i actually tried with both #if defined(_WIN32) && defined(_MSC_VER) and #if defined(_WIN32) && !defined(__MINGW32__) conditions without luck. Both worked in a simple c program but not inside the project. Crazy.
Post Reply

Return to “General”