corert icon indicating copy to clipboard operation
corert copied to clipboard

X86 runtime build fails

Open morganbr opened this issue 8 years ago • 24 comments
trafficstars

There are a number of failures building for x86. This should be doable since the same sources get built for x86 as part of .NET Native.

8>e:\corert\corert\src\native\jitinterface\JITCodeManager.h(96): error C2143: syntax error: missing ';' before '*' [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 8>e:\corert\corert\src\native\jitinterface\JITCodeManager.h(96): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 8>e:\corert\corert\src\native\jitinterface\JITCodeManager.h(173): error C3646: 'm_pRuntimeFunctionTable': unknown override specifier [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 8>e:\corert\corert\src\native\jitinterface\JITCodeManager.h(173): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 8>e:\corert\corert\src\native\jitinterface\JITCodeManager.h(229): error C3646: 'AllocRuntimeFunction': unknown override specifier [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 8>e:\corert\corert\src\native\jitinterface\JITCodeManager.h(229): error C2059: syntax error: '(' [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 8>e:\corert\corert\src\native\jitinterface\JITCodeManager.h(229): error C2238: unexpected token(s) preceding ';' [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 8>e:\corert\corert\src\native\runtime\coreclr\gcinfotypes.h(326): fatal error C1083: Cannot open include file: 'bitvector.h': No such file or directory [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\jitinterface\jitinterface.vcxproj] 4>E:\corert\corert\src\Native\Runtime\thread.cpp(600): error C2664: 'UInt32 PalHijack(HANDLE,PalHijackCallback,void *)': cannot convert argument 2 from 'UInt32_BOOL (__cdecl *)(HANDLE,PAL_LIMITED_CONTEXT *,void *)' to 'PalHijackCallback' [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] 4>E:\corert\corert\src\Native\Runtime\windows\PalRedhawkCommon.cpp(225): error C2373: 'PalGetProcessCpuCount': redefinition; different type modifiers [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] E:\corert\corert\src\Native\Runtime\PalRedhawk.h(694): note: see declaration of 'PalGetProcessCpuCount' 4>E:\corert\corert\src\Native\Runtime\windows\PalRedhawkCommon.cpp(249): error C2373: 'PalReadFileContents': redefinition; different type modifiers [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] E:\corert\corert\src\Native\Runtime\PalRedhawk.h(696): note: see declaration of 'PalReadFileContents' 4>E:\corert\corert\src\Native\Runtime\windows\PalRedhawkCommon.cpp(285): error C2373: 'PalGetMaximumStackBounds': redefinition; different type modifiers [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] E:\corert\corert\src\Native\Runtime\PalRedhawk.h(701): note: see declaration of 'PalGetMaximumStackBounds' PalRedhawkMinWin.cpp 4>E:\corert\corert\src\Native\Runtime\windows\PalRedhawkMinWin.cpp(115): error C2373: 'PalAttachThread': redefinition; different type modifiers [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] e:\corert\corert\src\native\runtime\PalRedhawk.h(822): note: see declaration of 'PalAttachThread' 4>E:\corert\corert\src\Native\Runtime\windows\PalRedhawkMinWin.cpp(137): error C2373: 'PalDetachThread': redefinition; different type modifiers [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] e:\corert\corert\src\native\runtime\PalRedhawk.h(823): note: see declaration of 'PalDetachThread' 4>E:\corert\corert\src\Native\Runtime\windows\PalRedhawkMinWin.cpp(192): error C2373: 'PalGetModuleFileName': redefinition; different type modifiers [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] e:\corert\corert\src\native\runtime\PalRedhawk.h(704): note: see declaration of 'PalGetModuleFileName' 4>E:\corert\corert\src\Native\Runtime\windows\PalRedhawkMinWin.cpp(1811): error C2664: 'HANDLE CreateThread(LPSECURITY_ATTRIBUTES,SIZE_T,LPTHREAD_START_ROUTINE,LPVOID,DWORD,LPDWORD)': cannot convert argument 3 from 'DWORD (__cdecl *)(void *)' to 'LPTHREAD_START_ROUTINE' [E:\corert\corert\bin\obj\Native\Windows_NT.x86.Debug\Runtime\Portable\PortableRuntime.vcxproj] E:\corert\corert\src\Native\Runtime\windows\PalRedhawkMinWin.cpp(1811): note: None of the functions with this name in scope match the target type

morganbr avatar Sep 21 '17 20:09 morganbr

Hey @morganbr, I gave it a shot out of curiosity and got to a point where it requires to implement/port more unwinding features for x86 in and around JITCodeManager. One suggestion (which may cleanup some code): port CoreCLR's REGALIAS implementation to deal with E-family i386 registers. I used some ifdefs to deal with them and altered the macro code such as this.

am11 avatar Sep 22 '17 14:09 am11

JITCodeManager can be excluded from the i386 completely (ie it can be included for x64 only). It is experimental component that is not required for CoreRT to work today.

jkotas avatar Sep 22 '17 16:09 jkotas

https://github.com/dotnet/corert/blob/master/src/Native/jitinterface/CMakeLists.txt#L10 is a good place to do it.

jkotas avatar Sep 22 '17 16:09 jkotas

The native parts now build on x86, for managed parts, I think aside from dotnet-cli for x86 Linux/Windows, we need to object-writer from LLILC for Linux-x86 (along with linux-x64, alpine.3.6-x64) RIDs. Something similar to this: https://github.com/dotnet/llilc/commit/8dc6363f625055be5c471f2c11d472b9b167ec32.

@jkotas, @janvorli, (unless ObjectWriter build has dependency on CoreCLR and LLVM) are there plans to bring ObjectWriter to CoreRT repo as there has been no activity in llilc repo in a while. I suppose, this package in CoreRT repo will be comparatively well-maintained and continuously update to new RID conventions (e.g. runtime.{RID}.{Arch}.{PackageName} instead of old toolchain.{RID}.{Arch}.{PackageName} naming).

am11 avatar Oct 04 '17 22:10 am11

We have been re-building ObjectWriter package from llilc repo manually as needed because of it is not changing frequently. Having the source for it in CoreRT repo makes sense. The plan can be something like:

  • Copy over https://github.com/dotnet/llilc/tree/ObjectWriter/lib/ObjWriter to corert\src\Native\objwriter
  • Add script and documentation on how to do one-off build

jkotas avatar Oct 04 '17 23:10 jkotas

@jkotas, the one-off build appears to be quite involved if we follow the documented build steps. I ended up compiling entire LLILC repo (ObjectWriter branch) as an LLVM plugin. Tested only the Windows x64 build, as there are missing x86 implementations which I guess would require a separate effort. With current infrastructure, we have to first compile CoreCLR, then LLILC as LLVM's tool. This can probably be re-wired in ObjectWriter's cmake script to reduce the amount of steps and repos to clone.

Is it a possibility that dependency on ObjectWriter for ILC is removed in future or ObjectWriter's dependency on LLVM is substituted with custom implementation?

am11 avatar Oct 07 '17 08:10 am11

With current infrastructure, we have to first compile CoreCLR

Compiling CoreCLR should not be required to compile ObjectWriter.

dependency on ObjectWriter for ILC is removed in future

We have used ObjectWriter to bootstrap the project faster. We went back and forth on whether/when we should replace it with custom implementation. There is no immediate plan to remove it, but there is a chance that it will be removed in future.

jkotas avatar Oct 07 '17 15:10 jkotas

2 years.... x86 support keep planned?

marcussacana avatar Oct 08 '19 06:10 marcussacana

2 years.... x86 support keep planned?

Would you like to help us make progress with it? I recently fixed on of the issues in #7773, but nobody is actively looking at this.

MichalStrehovsky avatar Oct 08 '19 08:10 MichalStrehovsky

ObjectWriter (which was one of the obstacle) has been since moved to CoreRT repo, so it might also help speed up the x86 bringup.

am11 avatar Oct 08 '19 09:10 am11

Glad to know there is still hope for x86, Well, I would love to help, but frankly I don't think I understand enough how this all works to be able to contribute.

marcussacana avatar Oct 08 '19 13:10 marcussacana

Well, I would love to help, but frankly I don't think I understand enough how this all works to be able to contribute.

It's possible to learn these things as you go.

The first step would be to clone the repo and try to build it. Make sure you have the prerequisites and run build.cmd objwriter skiptests (or build.sh objwriter skiptests on Unixes) from the root of the repo. This should build both CoreRT and the ObjWriter library @am11 alluded to. This will build x64 by default.

Once you verify you can build x64, it's time to try x86. Just add the x86 parameter to the build command line. We can go over the issues as they show up.

MichalStrehovsky avatar Oct 08 '19 13:10 MichalStrehovsky

Well, it doesn't hurt to try, although I don't think I'll make it. Tomorrow I will have time to spend with this.

marcussacana avatar Oct 08 '19 14:10 marcussacana

On Linux i386, build fails when compiling UnixContext.cpp and UnwindHelpers.cpp, due to explicit #errors for missing x86 registers.

#!/usr/bin/env sh

docker build -t corert-x86 - << EOF
FROM i386/ubuntu

RUN apt update
RUN apt install -y clang cmake git

RUN git clone https://github.com/dotnet/corert --single-branch

WORKDIR /corert

RUN ./build.sh objwriter skiptests x86
EOF

fails with:

[ 60%] Building CXX object Runtime/Portable/CMakeFiles/PortableRuntime.dir/__/__/gc/unix/cgroup.cpp.o
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:37:2: error: "Unwinding is not implemented for this architecture yet."
#error "Unwinding is not implemented for this architecture yet."
 ^
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:593:6: error: "Unwinding is not implemented for this architecture yet."
    #error "Unwinding is not implemented for this architecture yet."
     ^
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:597:19: error: use of undeclared identifier 'uc'
    bool retVal = uc.getInfoFromDwarfSection(pc, uwInfoSections, 0 /* fdeSectionOffsetHint */);
                  ^
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:604:5: error: use of undeclared identifier 'uc'
    uc.getInfo(&procInfo);
    ^
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:613:42: error: use of undeclared identifier 'Registers_REGDISPLAY'
    DwarfInstructions<LocalAddressSpace, Registers_REGDISPLAY> dwarfInst;
                                         ^
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:614:86: error: use of undeclared identifier 'Registers_REGDISPLAY'
    int stepRet = dwarfInst.stepWithDwarf(_addressSpace, pc, procInfo.unwind_info, *(Registers_REGDISPLAY*)regs);
                                                                                     ^
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:614:107: error: expected expression
    int stepRet = dwarfInst.stepWithDwarf(_addressSpace, pc, procInfo.unwind_info, *(Registers_REGDISPLAY*)regs);
                                                                                                          ^
/corert/src/Native/Runtime/unix/UnwindHelpers.cpp:614:19: error: use of undeclared identifier 'dwarfInst'
    int stepRet = dwarfInst.stepWithDwarf(_addressSpace, pc, procInfo.unwind_info, *(Registers_REGDISPLAY*)regs);
                  ^
8 errors generated.

am11 avatar Oct 08 '19 17:10 am11

#error "Unwinding is not implemented for this architecture yet."

That will probably require fixes similar to what was done in #7504 for ARM64.

MichalStrehovsky avatar Oct 08 '19 18:10 MichalStrehovsky

Has there been any progress on this since the last pull request? Would be nice if there was something I could do to help this effort.

3dsboy08 avatar Dec 28 '19 17:12 3dsboy08

I hope at least we get x86 support before the CoreRT exit of 'experimental stage'

marcussacana avatar Dec 29 '19 07:12 marcussacana

#7931 has a small fix for cross-compile. Full product is built (native + managed) using cross compile for x86 on x64 system:

#!/usr/bin/env sh

git clone https://github.com/dotnet/corert
cd corert

# create rootfs once, "sudo" is not required when running as root
sudo cross/build-rootfs.sh x86

# cross compile
./build.sh cross x86

Tests

ILCompiler and reflection metadata tests are passing but then there is a whole bunch of test failures uniquely due to the following two reasons:

/datadrive/projects/corert/bin/Linux.x86.Debug/build/Microsoft.NETCore.Native.targets(226,5): error MSB3073: The command ""/datadrive/projects/corert/tests/../bin/Linux.x86.Debug/tools/ilc" @"/datadrive/projects/corert/tests/src/Simple/Delegates/obj/Debug/x86/native/Delegates.ilc.rsp"" exited with code 134. [/datadrive/projects/corert/tests/src/Simple/Delegates/Delegates.csproj]
/datadrive/projects/corert/tests/../Tools/msbuild.sh /ds /m /p:IlcPath=/datadrive/projects/corert/tests/../bin/Linux.x86.Debug /p:Configuration=Debug /p:Platform=x86 /p:OSGroup=Linux /p:RepoLocalBuild=true /p:FrameworkLibPath=/datadrive/projects/corert/tests/../bin/Linux.x86.Debug/lib /p:FrameworkObjPath=/datadrive/projects/corert/tests/../bin/obj/Linux.x86.Debug/Framework /p:NativeCodeGen=cpp /p:AdditionalCppCompilerFlags=" " /p:AdditionalLinkerFlags=" " /datadrive/projects/corert/tests/src/Simple/Delegates/Delegates.csproj
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  /usr/bin/clang
  Generating native code

  Unhandled Exception: System.NotImplementedException: The method or operation is not implemented.
     at ILCompiler.DependencyAnalysis.X86.TargetRegisterMap..ctor(TargetOS os) in /datadrive/projects/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_X86/TargetRegisterMap.cs:line 33
     at ILCompiler.DependencyAnalysis.X86.X86Emitter..ctor(NodeFactory factory, Boolean relocsOnly) in /datadrive/projects/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_X86/X86Emitter.cs:line 15
     at ILCompiler.DependencyAnalysis.AssemblyStubNode.GetData(NodeFactory factory, Boolean relocsOnly) in /datadrive/projects/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/AssemblyStubNode.cs:line 53
     at ILCompiler.DependencyAnalysis.ObjectNode.GetStaticDependencies(NodeFactory factory) in /datadrive/projects/corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectNode.cs:line 61
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1 node) in /datadrive/projects/corert/src/ILCompiler.DependencyAnalysisFramework/src/DependencyAnalyzer.cs:line 145
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1 node) in /datadrive/projects/corert/src/ILCompiler.DependencyAnalysisFramework/src/DependencyAnalyzer.cs:line 183
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in /datadrive/projects/corert/src/ILCompiler.DependencyAnalysisFramework/src/DependencyAnalyzer.cs:line 212
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /datadrive/projects/corert/src/ILCompiler.DependencyAnalysisFramework/src/DependencyAnalyzer.cs:line 259
     at ILCompiler.CppCodegenCompilation.CompileInternal(String outputFile, ObjectDumper dumper) in /datadrive/projects/corert/src/ILCompiler.CppCodeGen/src/Compiler/CppCodegenCompilation.cs:line 47
     at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String outputFile, ObjectDumper dumper) in /datadrive/projects/corert/src/ILCompiler.Compiler/src/Compiler/Compilation.cs:line 405
     at ILCompiler.Program.Run(String[] args) in /datadrive/projects/corert/src/ILCompiler/src/Program.cs:line 612
     at ILCompiler.Program.Main(String[] args) in /datadrive/projects/corert/src/ILCompiler/src/Program.cs:line 766
  Aborted (core dumped)

and:

/datadrive/projects/corert/tests/../Tools/msbuild.sh /ds /m /p:IlcPath=/datadrive/projects/corert/tests/../bin/Linux.x86.Debug /p:Configuration=Debug /p:Platform=x86 /p:OSGroup=Linux /p:RepoLocalBuild=true /p:FrameworkLibPath=/datadrive/projects/corert/tests/../bin/Linux.x86.Debug/lib /p:FrameworkObjPath=/datadrive/projects/corert/tests/../bin/obj/Linux.x86.Debug/Framework /datadrive/projects/corert/tests/src/Simple/Exceptions/Exceptions.csproj
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  /usr/bin/clang
  Generating native code


  Unhandled Exception: Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'jitinterface' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libjitinterface: cannot open shared object file: No such file or directory
     at Internal.JitInterface.CorInfoImpl.GetJitHost(IntPtr configProvider)
     at Internal.JitInterface.CorInfoImpl..ctor(JitConfigProvider jitConfig) in /datadrive/projects/corert/src/JitInterface/src/CorInfoImpl.cs:line 119
     at Internal.JitInterface.CorInfoImpl..ctor(RyuJitCompilation compilation, JitConfigProvider jitConfig) in /datadrive/projects/corert/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs:line 45
     at ILCompiler.RyuJitCompilation.<CompileMultiThreaded>b__8_1(Thread thread) in /datadrive/projects/corert/src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilation.cs:line 100
     at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValueLocked(TKey key, CreateValueCallback createValueCallback)
     at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
     at ILCompiler.RyuJitCompilation.<CompileMultiThreaded>b__8_0(Object m) in /datadrive/projects/corert/src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilation.cs:line 100
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()System.DllNotFoundException: Unable to load shared library 'jitinterface' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libjitinterface: cannot open shared object file: No such file or directory
     at Internal.JitInterface.CorInfoImpl.GetJitHost(IntPtr configProvider)
     at Internal.JitInterface.CorInfoImpl..ctor(JitConfigProvider jitConfig) in /datadrive/projects/corert/src/JitInterface/src/CorInfoImpl.cs:line 119
     at Internal.JitInterface.CorInfoImpl..ctor(RyuJitCompilation compilation, JitConfigProvider jitConfig) in /datadrive/projects/corert/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs:line 45
     at ILCompiler.RyuJitCompilation.<CompileMultiThreaded>b__8_1(Thread thread) in /datadrive/projects/corert/src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilation.cs:line 100
     at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValueLocked(TKey key, CreateValueCallback createValueCallback)
     at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
     at ILCompiler.RyuJitCompilation.<CompileMultiThreaded>b__8_0(Object m) in /datadrive/projects/corert/src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilation.cs:line 100
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()

  Aborted (core dumped)

am11 avatar Dec 29 '19 13:12 am11

Some more progress (for Windows x86 this time) in #7944.

MichalStrehovsky avatar Jan 08 '20 17:01 MichalStrehovsky

god is real

marcussacana avatar Jan 08 '20 19:01 marcussacana

Hello Michal, I tried the /p:DisableUnsupportedError=true flag for dotnet publish, but it was not enough to make HelloWorld example compile as win-x86. There is the The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative error which as far as I could understand means that some DLLs are missing in the compiler folder for x86 compilation. I tried to look into suggestions in #5289 but they did not help.
In #7944 you mentioned that you have managed to compile snake game and I wish there were instructions to reproduce that.

Stat1cV01D avatar Jul 03 '20 07:07 Stat1cV01D

/p:DisableUnsupportedError will only work if you build x86 CoreRT yourself from source in this repo. After installing the prerequisites, you need to run build.cmd x86 objwriter skiptests from the root of the repo. Once you have a build, you can follow these instructions to use the freshtly built CoreRT with dotnet.

Note that x86 support on Windows is incomplete and you won't be able to run much more than the no-runtime zerosharp sample.

MichalStrehovsky avatar Jul 03 '20 11:07 MichalStrehovsky

I see. So when you wrote about compiling the snake game you also had to add all the "supplementary" code (and probably more) that is in "no-runtime zerosharp sample", right?

Stat1cV01D avatar Jul 03 '20 11:07 Stat1cV01D

Yes, it was the 2 kB selfcontained version of the game: https://twitter.com/MStrehovsky/status/1214955686397980673

MichalStrehovsky avatar Jul 03 '20 12:07 MichalStrehovsky