-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Windows x64 compiling #109
Comments
Please don't hate me ... I have now built your program with the official Microsoft build tools & get an error message when compiling. Error: cpuid_asm.c
src/x86/cpuid_asm.c(4): error C4235: nonstandard extension used: '__asm' keyword not supported on this architecture
src/x86/cpuid_asm.c(4): warning C4431: missing type specifier - int assumed. Note: C no longer supports default-int
src/x86/cpuid_asm.c(4): error C2059: syntax error: 'string' I also attach the whole output of the compiler as a file for you. Compile command: cl /Wall /std:c17 /TC /Od /DARCH_X86 /MT src/common/main.c src/common/cpu.c src/common/getopt.c src/common/udev.c src/common/printer.c src/common/args.c src/common/global.c src/x86/cpuid.c src/x86/apic.c src/x86/cpuid_asm.c src/x86/uarch.c /DEBUG /MACHINE:X64 /OUT:cpufetch_msvc.exe > msvc_output_cl.txt |
If the program builds but you get no output (as you showed in your screenshot), then cpufetch must have encountered an error and exited. It is pretty strange but may happen. You can run the program again with About the second message, if it compiles with mingw and does not compile with mscv, I am not really interested in fixing it. I saw the log you attached and msvc reports lots and lots of warnings about things that (from my perspective) are totally ok and that no other compiler would ever complain. I'm not going to invest hours and hours to check what msvc likes or does not like. Can you try again with |
I can run the program again later with the The warnings from MSVC are normal, a lot is just Windows specific, like padding. I will create a fork of your project and take care of MSVC, maybe I can find a way to keep everything 🤷 Update: C:\Users\Benny Nystroem\Documents\AAA_Zielstruktur\AAA_Environment\cpufetcher.master.env\cpufetch>cpufetch.exe --verbose
C:\Users\Benny Nystroem\Documents\AAA_Zielstruktur\AAA_Environment\cpufetcher.master.env\cpufetch> |
Okay, wow. I managed to make the program compatible with the MSVC compiler. And the program works too! A 64bit compiled program, without inline assembler instructions. I show here the changes to the files Content of cpuid_asm.h #ifndef __CPUID_ASM__
#define __CPUID_ASM__
/// We're going for a cross-platform solution and yes,
/// Windows has it's own rules to deal with cpuid ... Thanks Microsoft!
#ifdef _WIN32
#include <limits.h>
#include <intrin.h>
typedef unsigned __int32 uint32_t;
#else
#include <stdint.h>
#endif
void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
#endif Content of cpuid_asm.c #include "cpuid_asm.h"
void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
#ifdef _WIN32
// Array as register (EAX, EBX, ECX, EDX)
uint32_t regs[4];
/// Call Windows-specific cpuid function, we're using the extended one
__cpuidex((int *)regs, (int)*eax, (int)*ecx);
/// Now let's debug our results
printf("- CPUID dump: 0x%.8X\n", regs[0]); // regs[0] = eax
/// Bind result to the arguments, I hope this works
(*eax) = regs[0];
(*ebx) = regs[1];
(*ecx) = regs[2];
(*edx) = regs[3];
#else
__asm volatile("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx),
: "0" (*eax), "2" (*ecx));
#endif
} Update:
Theoretically, the modified program code should compile without problems under Unix 🤔 |
Thanks for your effort and your results, Xemorph. Before anything, I would like to investigate the first problem; why cpufetch compiled with mingw64 does not produce any output (and yes... this was the same problem I had some time ago). I just tried compiling and running it and I now I remember why I love windows so much. Regarding your fixed code, I was thinking about compiling the program with mingw64 and trying your code to check if it works. I mean, if mingw64 works without your fix, maybe it is only useful for msvc? I will consider adding your fix to the master branch if I see it is useful. |
UPDATESorry, I made a mistake. I have split the Windows architecture again separately and destroyed the program. I have now fixed the errors and the changes work properly. I will upload the whole changed source code in my fork, link follows! UPDATE 2But I am not happy with the changes at all, because the whole program code becomes completely invisible. |
The changes that you made are not responsible for the segfault when you compiled with mingw64. I also had the segfault and the program itself works perfectly, so it is not our problem. Looks like it is something related to mingw64? The summary right now is:
If you find anything new, please let me know! And also let's see how your patches go |
@Dr-Noob , could you maybe test something for me? What happens if we take your source code v0.99 and take out the parameter |
…segfault with mingw64, found in issue #109
That was a great idea! Yeah, this was the problem in mingw64, removing I have updated the Makefile to fix this problem. Now you should be able to compile with mingw64 and run it without problems. Now we have:
|
Nice 👍 Your hint that it could be the stack gave me the idea to throw out the stack protector. Can we keep this issue open? Because I am still tinkering here to be able to provide people with an executable file for Windows again. |
Sure, I will keep this open, I'm still unsure if I will include the code needed to be able to compile with msvc. By the way, you look like know a lot about Windows stuff. Are you interested in giving a helping hand in #95? Maybe you know a better approach than winget? One last thing, do you have issues compiling with mingw with the default Makefile? At least in my case, it complains that |
Ah, that problem. I have the problem too, but again this is apparently a bug in MinGW. Because the expression I just changed the expression to
I would put the issue on the back burner for now, because the Windows version is not really stable & the effort would be too big. That's why I'm currently writing a separate version of |
Hey, I've done a bit of work on the You can find all the changes in my fork under the branch: https://github.com/Xemorph/cpufetch/tree/playground/v2 If you have any questions, please don't hesitate to contact me. |
Hey,
the current version of the tool "cpufetch" currently only supports 32 bit compilation under Windows. The 32 bit compiled program runs under Windows 32 bit as well as 64 bit.
For me personally I think it makes sense to remove the dependency to 32 bit. The following sourcecode files prevent a 64 bit compilation under Windows:
src/x86/cpuid_asm.h
src/x86/cpuid_asm.c
The error is exactly in the inline assembler instruction:
Microsoft says the following about inline assembly instructions (source is attached as a link)
Source: Microsoft Inline Assembler
At least for Windows the provided methods
__cpuid
and__cpuidex
should be used. According to Microsoft these functions generate the appropriate assembly set for the respective selected architecture. Documentation for the mentioned functions: __cpuid, __cpuidexI hope I haven't overwhelmed you with all the information 😳 What is your opinion?
Best regards, Derik
The text was updated successfully, but these errors were encountered: