Skip to content
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

NativeAOT build #22

Merged
merged 19 commits into from
Jul 30, 2020
Merged

NativeAOT build #22

merged 19 commits into from
Jul 30, 2020

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Jul 22, 2020

No description provided.

@jkotas
Copy link
Member Author

jkotas commented Jul 22, 2020

@MichalStrehovsky I have created the WIP PR here so that we can work on it together. Feel free add more commits to this.

@joperezr
Copy link
Member

@jkotas do you want to add CI coverage for this branch? If so, you need to update this with latest dotnet/runtime so that you get the new runtimelab.yml and then just add this branch to the list of branches that triggers builds. If you want me to do that for you let me know.

@jkotas
Copy link
Member Author

jkotas commented Jul 23, 2020

@joperezr I have merged latest dotnet/runtime to NativeAOT. Could you please take care of adding the branch name to the right places?

@joperezr
Copy link
Member

Sure, I sent out #25 that adds that, feel free to close that one and add that small change right here instead if you prefer that.

@joperezr
Copy link
Member

/azp run runtimelab

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@joperezr
Copy link
Member

@jkotas do note that since this experiment is compiling native assets, should you need to build additional platforms you can do so by adding the desired platforms to the lists on runtimelab.yml like:

platforms:
- Linux_x64
- Windows_NT_x64

The list of platforms we support and you can add are on this file:

https://github.com/dotnet/runtimelab/blob/NativeAOT/eng/pipelines/common/platform-matrix.yml

@jkotas
Copy link
Member Author

jkotas commented Jul 24, 2020

@joperezr Thank you for your help with this!

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Jul 24, 2020

I had to bring back gcinfodecoder for now because including the one from vm requires preprocessor-fu that I haven't reached yet. Directly including from vm brings major confusion around which common.h the include in the decoder refers to. Preprocessor picks the one in vm and bad things happen. I think we'll need to pull that file out of vm.

I got rid of the GC_DIR nicety because it doesn't play with convert_to_absolute_path.

I reordered when nativeaot is included because we probably don't want all of CoreCLR's FEATUREs.

TODO:

  • Check we define all necessary defines
  • Check we set all necessary compiler switches
  • Uncomment AsmOffsets CSPP processing once Runtime.Base is copied over
  • Uncomment add_definitions(-DSTRESS_HEAP)
  • Get rid of gcinfodecoder copy

I'm working on the first two right now.

Don't know what the hell that is (building for linux, but using MSVC and MIDL?!?), but it's failing hard.
@MichalStrehovsky
Copy link
Member

Differences in compiler configuration in Release builds:

I guess we're fine with it. We'll see what CFG does.

-     <AdditionalOptions>%(AdditionalOptions) /source-charset:utf-8</AdditionalOptions>
+     <AdditionalOptions>%(AdditionalOptions) /Zc:strictStrings /Zm200 /w34092 /w34121 /w34125 /w34130 /w34132 /w34212 /w34530 /w35038 /w44177 /ZH:SHA_256 /source-charset:utf-8</AdditionalOptions>
      <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
      <BufferSecurityCheck>true</BufferSecurityCheck>
      <CompileAs>CompileAsCpp</CompileAs>
+     <ControlFlowGuard>Guard</ControlFlowGuard>
      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+     <DisableSpecificWarnings>4960;4961;4603;4627;4838;4456;4457;4458;4459;4091;4291</DisableSpecificWarnings>      
-     <ExceptionHandling>Sync</ExceptionHandling>
+     <ExceptionHandling>Async</ExceptionHandling>
+     <ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
-     <FloatingPointModel>Precise</FloatingPointModel>
+     <FunctionLevelLinking>true</FunctionLevelLinking>
      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+     <IntrinsicFunctions>true</IntrinsicFunctions>
+     <MinimalRebuild>false</MinimalRebuild>
+     <MultiProcessorCompilation>true</MultiProcessorCompilation>
+     <OmitDefaultLibName>true</OmitDefaultLibName>
+     <OmitFramePointers>false</OmitFramePointers>
-     <Optimization>MaxSpeed</Optimization>
+     <Optimization>MinSpace</Optimization>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-     <RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
-     <RuntimeTypeInfo>true</RuntimeTypeInfo>
+     <RuntimeTypeInfo>false</RuntimeTypeInfo>
+     <StringPooling>true</StringPooling>
+     <StructMemberAlignment>8Bytes</StructMemberAlignment>
+     <SuppressStartupBanner>true</SuppressStartupBanner>
+     <TreatSpecificWarningsAsErrors>4640;4007;4013;4102;4551;4700;4806</TreatSpecificWarningsAsErrors>     
      <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
+     <TreatWarningAsError>true</TreatWarningAsError>
+     <UndefinePreprocessorDefinitions>_MT</UndefinePreprocessorDefinitions>
      <UseFullPaths>false</UseFullPaths>
-     <WarningLevel>Level1</WarningLevel>
+     <WarningLevel>Level3</WarningLevel>
+     <WholeProgramOptimization>true</WholeProgramOptimization>

@jkotas
Copy link
Member Author

jkotas commented Jul 24, 2020

We'll see what CFG does.

Unless we make the code generated by our compiler CFG compliant as well and enable it in the linker, I expect it will just add overhead. From https://docs.microsoft.com/en-us/cpp/build/reference/guard-enable-guard-checks?view=vs-2019: "Code compiled but not linked by using /GUARD:CF incurs the cost of runtime checks, but does not enable CFG protection."

<ExceptionHandling>Async</ExceptionHandling>

We do not want this for CoreRT bits. The async exception handling generates signficantly larger code.

<Optimization>MinSpace</Optimization>

The GC perf may be signficicanly influenced by this one. CoreCLR GC depends on PGO data to turn on MaxSpeed for everything that matters (that is large chunk of GC code). I suspect that optimizing for speed is a better tradeoff for CoreRT without the PGO data since there is not that much else in the native part of runtime. We can keep it as MinSpace and file a tracking perf issue on it.

<RuntimeTypeInfo>false</RuntimeTypeInfo>

Nice! I have not realized that we have RTTI enabled.

<WholeProgramOptimization>true</WholeProgramOptimization>

This will make us sensitive to a match between the compiler version used by the build lab, and linker version used by end user. We can leave it and see whether it causes problems in practice.

I am cleaning up some of this in dotnet/runtime#39901

@jkotas jkotas added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Jul 25, 2020
@jkotas jkotas changed the title WIP: NativeAOT build NativeAOT build Jul 29, 2020
@jkotas jkotas merged commit a89d3cb into NativeAOT Jul 30, 2020
@jkotas jkotas deleted the NativeAOT-build branch July 30, 2020 16:10
runtimelab-bot pushed a commit that referenced this pull request May 18, 2021
…2769)

Transition to GC Unsafe mode on every MONO_RT_EXTERNAL_ONLY function in
reflection.c

In particular, fix mono_reflection_type_from_name which is used in
https://github.com/xamarin/xamarin-android/blob/681887ebdbd192ce7ce1cd02221d4939599ba762/src/monodroid/jni/embedded-assemblies.cc#L350

Fixes stack traces like

```
05-14 08:06:12.848 31274 31274 F DEBUG   :       #00 pc 00000b99  [vdso] (__kernel_vsyscall+9)
05-14 08:06:12.848 31274 31274 F DEBUG   :       #1 pc 0005ad68  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40) (BuildId: 6e3a0180fa6637b68c0d181c343e6806)
05-14 08:06:12.848 31274 31274 F DEBUG   :       #2 pc 00076511  /apex/com.android.runtime/lib/bionic/libc.so (abort+209) (BuildId: 6e3a0180fa6637b68c0d181c343e6806)
05-14 08:06:12.848 31274 31274 F DEBUG   :       #3 pc 0002afcd  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonodroid.so (xamarin::android::internal::MonodroidRuntime::mono_log_handler(char const*, char const*, char const*, int, void*)+141) (BuildId: 9726f32ad5f8fa5e7c5762baf2f6e3294da41cc1)
05-14 08:06:12.848 31274 31274 F DEBUG   :       #4 pc 00112c5d  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (eglib_log_adapter+141) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #5 pc 00020fdf  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (monoeg_g_logv+175) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #6 pc 0002113a  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (monoeg_g_log+42) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #7 pc 00128892  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_threads_transition_do_blocking+258) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #8 pc 0012a406  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_threads_enter_gc_safe_region_unbalanced_with_info+134) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #9 pc 0012a27e  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_threads_enter_gc_safe_region_internal+46) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #10 pc 000799a7  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_loader_lock+71) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #11 pc 000447a1  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_class_create_from_typedef+129) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #12 pc 0003c073  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_class_get_checked+99) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #13 pc 0003cc0f  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_class_from_name_checked_aux+735) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #14 pc 00037989  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_class_from_name_checked+73) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #15 pc 000cc5f4  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_reflection_get_type_internal+132) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #16 pc 000c9bce  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_reflection_get_type_with_rootimage+126) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #17 pc 000ca204  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (_mono_reflection_get_type_from_info+292) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #18 pc 000ca06e  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_reflection_type_from_name_checked+334) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #19 pc 000c9f01  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonosgen-2.0.so (mono_reflection_type_from_name+49) (BuildId: b67e93dd750dafdd6f65f408b021b6a3a74868ac)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #20 pc 0001b40b  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonodroid.so (xamarin::android::internal::EmbeddedAssemblies::typemap_java_to_managed(char const*)+427) (BuildId: 9726f32ad5f8fa5e7c5762baf2f6e3294da41cc1)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #21 pc 0001b551  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonodroid.so (xamarin::android::internal::EmbeddedAssemblies::typemap_java_to_managed(_MonoString*)+113) (BuildId: 9726f32ad5f8fa5e7c5762baf2f6e3294da41cc1)
05-14 08:06:12.849 31274 31274 F DEBUG   :       #22 pc 000211a7  /data/app/~~rMrkpKmVPaBpM5jKb8fPAg==/com.microsoft.maui-JfRo8RWSDJaNtJuBa0y7_Q==/lib/x86/libmonodroid.so (xamarin::android::internal::MonodroidRuntime::typemap_java_to_managed(_MonoString*)+39) (BuildId: 9726f32ad5f8fa5e7c5762baf2f6e3294da41cc1)
```
MichalStrehovsky added a commit to MichalStrehovsky/runtimelab that referenced this pull request Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants