Hello,
I've been working on a guide to compile DOSBox here:
https://www.vogons.org/viewtopic.php?f=31&t=55706&p=609435#p609435
While working on this guide myself and others have noticed than an executable compiled with Mingwrt v5+ results in an executable that will not run if the processor supports SSE but the Operating system does not. (Windows 95, NT 3.51). Testing was performed with a simple Hello World and also with DOSBox itself. Testing has also been performed on the same version of Windows used inside Vmware (i686) with the SSE flag masked and in Pcem (i586) (Pentium) and Qemu (i686).
The issue can be recreated as follows:
Create an "Hello World" executable with g++ with Mingw 6.3.0 and Mingwrt v5+. This results in an executable that will not work if the processor is i686 and the OS does not support SSE. (The executable WILL work fine on any OS that supports SSE as well as on any i586 processor)
Create an "Hello World" executable with g++ with Mingw 6.3.0 and Mingwrt v3. This results in an executable that will work if the processor is i686 and the OS does not support SSE. (The OS will work on non SSE and SSE processors as well as i486+)
Further testing revealed that replacing the crt2.0 file with one from v3 of mingwrt removes the error or removing Lines 118 to 122 of fesetenv.c and recompiling mingwrt v5+ will remove the error as well.
Obviously these operating systems are ancient so I doubt anyone cares but thought I'd get these posted if anyone does care or wants to know why their executable doesn't work and can't figure out why.
See this post and the next one for further info:
https://www.vogons.org/viewtopic.php?f=31&t=55706&p=609435#p625288
Diff:
Thank you for bringing this to my attention. Before addressing the issue, may I draw your attention to the instructions at the top of the form which you completed, to create this ticket:
In assigning this to me, you exceeded your authority by updating the forbidden
Ownerfield; thus, I would be perfectly justified in deleting this ticket, without further action.That said, I am willing to discuss the issue further; initial comments as follows:
fesetenv.c; the lines to which you point produce identical assembly code, for bothmingwrt-3.xandmingwrt-5.xcrt1.c, in progressing frommingwrt-3.xtomingwrt-5.x, to circumvent a badly engineered, and utterly non-deterministic attempt to selectively override Microsoft's_fpreset()function; it is this change which is responsible for the change in behaviour.fesetenv()which was not present in themingwrt-3.xversion), reverting that change is definitely not a solution, since it would simply sweep an underlying problem under the carpet; in the environment in which you have observed the issue, any explicit call tofesetenv(), (even in existingmingwrt-3.xdependent code), would fall foul of the underlying problem, (and such a call could arise, with the default FPU exception handler installed bycrt2.o-- which is compiled fromcrt1.c-- in the event that FPU exceptions are enabled).I think the correct way to resolve this will be to modify
cpu_features.c, to ensure that the__HAS_SSEfeature test does not rely on a CPU feature probe alone, but will also consider whether the host OS supports the feature; can you suggest a suitable test, which could be used to deduce that the CPU feature probe should be overridden w.r.t. the__HAS_SSEfeature test bit?Hi,
While troubleshooting the Hello world test case that fails will an illegal instruction when executed on a VMWare Win95 Guest running on a SSE supported host processor, we came across this thread in the FLAC forum for detecting SSE support in OS(with some rider about 'no guarantee to work' in future Intel processors). The patch from that thread was added to cpu_features.c(modded file attached) as advised and to my limited knowledge worked out fine under the following test conditions:
Last edit: Keith Marshall 2017-11-28
Nope. If I compile, and run, the current
cpu_features.cinTESTmode, I see:However, your version simply doesn't work:
It did give the same error message when I ran it under wine, but not when I compiled and ran it natively in Linux. Also I tested on another system running Windows 8.1 and the CPU support features were properly reported.
I will try to find out and resolve the issue to the best of my ability and will update if I have something.
Failing of the test program seems to be due to non-alignment of 'fxsr' struct variable to 16 byte boundary, that was being allocated in the stack under wine (This issue was not observed in the case of running the executable under Windows).
__attribute__((aligned(16)))doesn't seem to work for the stack allocated struct variable. I'm not much familiar with realignment of stack allocated variable, though I tried some things without success. Alternatively, I found an advice to declare the struct as 'static' and after doing that, didn't receive any page fault when I compiled and ran it under wine. Updated file is attached for perusal. Tested on:a) MinGW under Wine (1.6.2) in Lubuntu(14.04 LTS), running under QEMU on Core i7 system
b) Win8.1 Pro 64 bit running on Core i7 system
c) Bochs with emulated P3(Katmai) processor running Win95 Guest
d) PCEM with emulated Pentium processor running Win95 Guest
P.S.: I don't have much knowledge about the intrinsics of compiler optimizations/cross platform compatiblity things, so I'm not sure about their effects on the added code & vice versa. Additional testing on Sandybridge Laptop & VMWare guest to be done later tonight.
Last edit: Keith Marshall 2017-11-28
Yes, I'd guessed that might have been the case, after examining the generated assembly code.
That was reported, years ago, as GCC bug #16660, and was claimed to have been fixed by #33721, but the generated assembly code provides no evidence to support that claim; perhaps a regression by the time we get to GCC-6.3, otherwise the claimed resolution may never have been completely effective.
Strictly, you should have provided patches, rather than complete replacement files, but that's being pernickerty: I can generate them here. Thus, your initial proposal (after some cosmetic adjustment) becomes
cpu_features.original.patch(sourceforge.net), and your follow-up (as an incremental patch, after elimination of redundant changes) becomescpu_features.update.patch(sourceforge.net), (both of which are attached). However, given the weight of inline assembly code, and relative dearth of C code in the originalcpu_features.c, it seems ridiculous that this was ever written in C in the first place; rather than adopting your proposals verbatim, I propose the alternative ofcpu-features-init.patch(sourceforge.net) (also attached).I've successfully tested the
cpu_features.sxreplacement implementation, under wine, on my LMDE host, (but not on native Win32); I have no available test platform, on which to verify the behaviour on legacy Windows versions, so would be grateful if you could do so -- you may find myt-cpu.ctest program (also attached) to be helpful.Last edit: Keith Marshall 2017-11-28
First of all, thanks for looking into a test case involving such old OS versions and providing a solution for it.
I never felt qualified enough to propose a proper patch as I lacked the knowhow and also the means to test it under various conditions. As said earlier, the underlying code itself was not mine to begin with, hence it was just a suggestion more than anything, hopefully, to be molded properly in the hands of an experienced developer(as you have done now).
Your test program reported the correct CPU features in my following test cases:
a) MinGW under Wine (1.6.2) in Lubuntu(14.04 LTS), running under QEMU on Core i7 system
b) Win8.1 Pro 64 bit running on Core i7 system
c) Bochs with emulated P3(Katmai) processor running Win95 Guest
d) PCEM with emulated Pentium processor running Win95 Guest
Now I will try to understand your new cpu_features file, fully. Even though you have commented each and everything in detail, there is much to be learned by me. Once I understood it enough, I will try to test in more obscure conditions.
Last but not the least, thanks heaps for the MinGW project.
with regards,
G.Gandhi.
Last edit: satgan 2017-11-29
FWIW, this is how I generated
cpu_features.original.patch(sourceforge.net), in my build directory, from your first proposed replacement forcpu_features.c:Simple as that; note that the use of
a/andb/directories mimics the behaviour ofhg,git, and even venerable oldcvs, when formatting patches; also note that my build directory is an immediate child of the top-level directory in my repository clone, and thus, an immediate sibling of the top-levelmingwrtandw32apiproject source directories.From there, to create
cpu_features.update.patch(sourceforge.net), I did:Finally, to clean up:
The procedure I used to create my own patch was somewhat different; I reverted my working copy of the repository to published state, made my proposed changes "in-place", then used mercurial queues (mine is an
hg cloneof thegitrepository) to generate the patch:This leaves the patch file in
../.hg/patches-cpu-features/cpu-features-init.patchThanks for testing; (I assume you applied my patch, in the parent of your
mingwrtandw32apisource directories, and rebuilt using):Before building the test program, (in the sandbox):
You're most welcome. Do please note that thanks are also due to yourself, and others like you, who are prepared to follow up, and most importantly ... test on these legacy platforms, (which are becoming increasingly difficult for us to support without such feedback). We always strive to preserve the legacy platform support, but alas, too many users will simply file bug reports, which they then never follow up. So, once again, a big thank you to you, for persisting with this one!
I was probably sounding more naive than necessary on my earlier reply. I should have worded it as "I never felt qualified enough to propose it as a proper patch". What I meant by 'lacked the knowhow' was not w.r.t 'generating diff or applying a patch(which,thankfully, I do know)', rather, it was about the possible (ill?)effects of the 'added' code on other systems (that weren't tested by me). That said, your reply about generating your own patch using mercurial wasn't known to me, thanks for sharing your knowledge.
Yes, your patch got applied cleanly to my source directory. However, my ugly build procedure involved
Thanks to the OP, DosFreak who was instrumental in identifying & isolating the issue in his test case of Win95 Guest under VMWare.
P.S. Happy to help in any way if you need any support for testing in old systems, as I enjoy trobleshooting more than coding/patching.
Last edit: satgan 2017-11-29
Ah, okay. I misunderstood that you may not have been comfortable with the procedure for creating, and submitting patches ... sorry about that. W.r.t. possibible adverse effects on systems you haven't tested on, (or cannot test on), it's best to just "get it out there", and let others report any problems which arise.
Pleased to have given you something new. I believe it's possible to do something similar with
gitbranches, but IMO, whatever featuresgitmay offer, they surely lack the elegance of mercurial.So, your CWD was set to the top of the
mingwrtsource tree, whereas I work from a repository clone, with bothmingwrtandw32apisource directories as immediate children of the top source directory, (together with a build directory, which is an immediate sibling of both); with this setup, having cloned it from the public repository, there is also additional build-time code in the top source directory, to facilitate combined configuration and build of both subsidiary packages.I handle this by keeping several installations in parallel, e.g. for
mingw32-gcc-6.3I have$HOME/mingw32-gcc-6.3.0for my production compiler, and$HOME/mingw32-gcc-6.3.0-sandboxfor testing. My$PATHrefers to one or other of these, (but never both at the same time), via a symbolic$HOME/mingw32link, such that$HOME/mingw32/binis in$PATH. Thus, I can switch between production and testing environments, simply by changing one symbolic link, (and I have a little shell script to automate the switch).Yes, indeed.
Would you be interested in joining the project, in the capacity of "tester", with a particular emphasis on legacy systems support?
Last edit: Keith Marshall 2017-11-29
Thanks for giving inputs in maintaining an organized setup. Frankly I have never used git or mercurial before, so, as indicated, I will start with mercurial and mimic your setup.
It took me around 10 days to understand, identify and search a fix for the stack alignment issue under wine. So you can guess my knowledge level. I'm also doing testing for DosFreak's compilation guide in dosbox forum(vogons.org) and learning at the same time.
Am I right in assuming that there won't be any time bound pressure to complete the tasks at hand? If not so && still you would like to consider me as a tester, then I'm flattered to join.
Another thing I would like to bring to your notice is that I don't have any actual legacy hardware/OS (all are emulators only), though I guess it shouldn't matter for practical purposes.
Correct. We place no demands whatsoever, on our project contributors; each is allowed to work at their own pace, as their own time constraints permit, while contributing as much, or as little, as they wish.
Well, for most of us, testing on older platforms, (whether physical or virtual), is becoming increasingly difficult. (Personally, I run WinXP and Win7 under VirtualBox, on an LMDE host; I tried to create a similar set-up for Win98, but it is so poorly supported by VirtualBox that it is effectively unusable, and I gave up). Without willing volunteers, who can test on these older platforms, we may be forced to drop support for them.
Incorporporating you as a project member just makes it easier keep you informed of issues which you may wish to investigate. However, right now, SourceForge have messed up our project communications, and we are exploring alternative infrastructures; let me get back to you, when we have something more concrete in place.
I don't think that should matter; as noted above, I use virtual machines myself, and surely such testing must be better than no testing at all.
Sure.
I'm presently experimenting, to get to install MinGW in PCEM Win95 guest for debugging an application. I know it is far-fetched. Do you have any advice regarding the version I could try, btw. Or is it a fool's errand?
MinGW GUI setup actually doesn't run in Win95 guest, so, I'm trying the CLI route
Last edit: satgan 2017-12-02
I don't know, but it really would be better to ask on the MinGW-Users mailing list, or to open a new ticket, to discuss the new topic. (The mailing list gets better exposure to a broader corpus of users, one of whom may just know the answer).
Does
mingw-getrun as a CLI process? Again, I don't know, (and have no way to check), and once again, the mailing list, or a new ticket, would be more appropriate for continued discussion.I pushed a slightly modified version of my previously proposed patch, (fixing some CFI directive usage issues), as [fa00fd]. There may be some x86-64 compatibility issues, arising out of this, so I'm leaving the ticket open.
Related
Commit: [fa00fd]
Thanks for the commit.
Last edit: satgan 2017-12-05
Closing, since the original issue should have been resolved, and no consequent x86-64 issue has been raised.