![]() * Enable AddressSanitizer in CoreCLR, Libs, and Host and update runtime-sanitized to run tests with ASAN on Linux and Mac * Unify on HAS_ADDRESS_SANITIZER define name Centralize setting up sanitizer flags. Remove last usage of CLR_CMAKE_ENABLE_ASAN outside of eng/native Remove unnecessary diffs Use the cpuid intrinsic and enable ASAN on InitJitHelpers1. Add comments for the places where we have ASAN disabled Undo changes to src/coreclr/jit/CMakeLists.txt Add docs and fix the docs in the build script. Add docs for the SkipVCEnvInit hook * Remove CRT runtime changes. We won't need this when we finally onboard to Windows with some changes they have coming down the pipeline, so remove them for now to reduce the diff of this PR. * Remove suppression now that we've fixed the underlying issue. * Remove some Windows-only sanitizer CMake that we won't need when ASAN is ready for us to consume on Windows. * Set schedule for runtime-sanitized pipeline * Remove workaround in JIT memory set/copy helpers now that the JIT bug has been fixed. * Add missing helix queues setup template. * Fix missing command to build nativeaot runtime tests as nativeaot. * Add a scenario name to trigger the extended timeout in the libraries test helix configuration. * Remove extraneous whitespace. * Fix using the cross-targetting ILC when sanitizers are enabled. Also pass through our TargetOS and TargetArchitecture variables to the publish command for our native sanitizers targets to correctly do their extra logic. * Disable LSAN on the CustomMain test. * Disable some tests on sanitized runtimes. * Copy the sanitizer runtime for OSX NativeAOT runtime tests. * A little cleanup to try to get the build right now that we are always doing cross-builds on Linux. * Fix crossgen-corelib.proj syntax. * Fix cross-os dac builds to not include the host architecture in the output path. * Split the debugger components into a separate component and make the "unsanitized cross components" build into an "unsanitized debugger components" build as it can't be part of the regular cross-components build * Always write out the host-arch path on Windows and update the cross-dac build script to expect that. * Change to use the dynamic runtime on Windows, as ASAN in VS is moving to a dynamic-only model. * Update docker images to include the sanitizer runtimes in the crossrootfs images. * Fix explicit image tags * The unsanitized build should be of the target architecture, not the host architecture. As a result, we still need a cross-arch build for the cross-arch use cases when sanitized, as well as an unsanitized target arch build for the debugger tools. * Turn off using the sigaltstack for NativeAOT tests that don't use the asansupport.cpp default options * Make sure the shared ASAN runtime is present for the nativeaot/SmokeTests/SharedLibrary test. * Disable crossgen2 tests with sanitizers as they don't get us interesting coverage. * Fix custom default options and disable some more crossgen2-based tests. * Simplify lookup of asan runtime on mac and fix copying the shared runtime for the SharedLibrary NativeAOT test. * Disable test that's failing for weird reasons. * Fix one more alloc-dealloc mismatch that only started to show up after test merging increased allocations in the runtime * Disable the System.Text.Json test suite on sanitized builds as it causes SO failures on Mac * Fix test exclusion * PR feedback. * Fix mac build * Do review changes * Add libbootstrapper object files to the platform manifest now that NativeAOT has * Disable tests that check size on sanitized builds * Use the built-in `include_guard` option * Disable use-after-return checking in ASAN. CoreCLR doesn't do well with parallel stacks. * Only pass the no UAR flag on C and CXX with Clang (not AppleClang). |
||
---|---|---|
.. | ||
android.md | ||
cross-building.md | ||
freebsd-instructions.md | ||
linux-instructions.md | ||
macos-instructions.md | ||
nativeaot.md | ||
README.md | ||
windows-instructions.md |
Building CoreCLR
Introduction
Here is a brief overview on how to build the common form of CoreCLR in general. For further specific instructions on each platform, we have links to instructions later on in Platform-Specific Instructions.
To build just CoreCLR, use the subset
flag to the build.sh
or build.cmd
script at the repo root. Note that specifying -subset
explicitly is not necessary if it is the first argument (i.e. ./build.sh --subset clr
and ./build.sh clr
are equivalent). However, if you specify any other argument beforehand, then you must specify the -subset
flag.
For Linux and macOS:
./build.sh --subset clr
For Windows:
.\build.cmd -subset clr
Common Building Options
By default, the script generates a Debug build type, which is not optimized code and includes asserts. As its name suggests, this makes it easier and friendlier to debug the code. If you want to make performance measurements, you ought to build the Release version instead, which doesn't have any asserts and has all code optimizations enabled. Likewise, if you plan on running tests, the Release configuration is more suitable since it's considerably faster than the Debug one. For this, you add the flag -configuration release
(or -c release
). For example:
./build.sh --subset clr --configuration release
As mentioned before in the general building document, CoreCLR also supports a Checked build type which has asserts enabled like Debug, but is built with the native compiler optimizer enabled, so it runs much faster. This is the usual mode used for running tests in the CI system.
Now, it is also possible to select a different configuration for each subset when building them together. The --configuration
flag applies universally to all subsets, but it can be overridden with any one or more of the following ones:
--runtimeConfiguration (-rc)
: Flag for the CLR build configuration.--librariesConfiguration (-lc)
: Flag for the libraries build configuration.--hostConfiguration (-hc)
: Flag for the host build configuration.
For example, a very common scenario used by developers and the repo's test scripts with default options, is to build the clr in Debug mode, and the libraries in Release mode. To achieve this, the command-line would look like the following:
./build.sh --subset clr+libs --configuration Release --runtimeConfiguration Debug
Or alternatively:
./build.sh --subset clr+libs --librariesConfiguration Release --runtimeConfiguration Debug
For more information about all the different options available, supply the argument -help|-h
when invoking the build script. On Unix-like systems, non-abbreviated arguments can be passed in with a single -
or double hyphen --
.
Build Drivers
If you want to use Ninja to drive the native build instead of Make on non-Windows platforms, you can pass the -ninja
flag to the build script as follows:
./build.sh --subset clr --ninja
If you want to use Visual Studio's MSBuild to drive the native build on Windows, you can pass the -msbuild
flag to the build script similarly to the -ninja
flag.
We recommend using Ninja for building the project on Windows since it more efficiently uses the build machine's resources for the native runtime build in comparison to Visual Studio's MSBuild.
Extra Flags
To pass extra compiler/linker flags to the coreclr build, set the environment variables EXTRA_CFLAGS
, EXTRA_CXXFLAGS
and EXTRA_LDFLAGS
as needed. Don't set CFLAGS
/CXXFLAGS
/LDFLAGS
directly as that might lead to configure-time tests failing.
Build Results Layout
Once the build has concluded, it will have produced its output artifacts in the following structure:
- Product binaries will be dropped in
artifacts\bin\coreclr\<OS>.<arch>.<configuration>
folder. - A NuGet package, Microsoft.Dotnet.CoreCLR, will be created under
artifacts\bin\coreclr\<OS>.<arch>.<configuration>\.nuget
folder. - Test binaries (if built) will be dropped under
artifacts\tests\coreclr\<OS>.<arch>.<configuration>
folder. However, remember the root build script will not build the tests. The instructions for working with tests (building and running) are in the testing doc. - The build places logs in
artifacts\log
and these are useful when the build fails. - The build places all of its intermediate output in the
artifacts\obj\coreclr
directory.
If you want to force a full rebuild of the subsets you specified when calling the build script, pass the -rebuild
flag to it, in addition to any other arguments you might require.
Platform-Specific Instructions
Now that you've got the general idea on how the CoreCLR builds work, here are some further documentation links on platform-specific caveats and features.
We also have specific instructions for building NativeAOT here.
Testing CoreCLR
For testing your build, the testing docs have detailed instructions on how to do it.