Skip to content

Commit

Permalink
[build/ci] Enable native code analysis nightly (#6420)
Browse files Browse the repository at this point in the history
Context: aaa37c3

Updates the build to conditionally generate extra native libraries with
the ASAN and UBSAN runtime sanitizers when
`'$(EnableNativeAnalyzers)' == 'true'`.

We will only enable this behavior in our nightly builds, and the
`*-checked+asan` and `*-checked+ubsa` native libraries have been removed
from our regular installers.
  • Loading branch information
pjcollins authored Oct 26, 2021
1 parent 6509d17 commit f9d86ae
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 31 deletions.
4 changes: 2 additions & 2 deletions build-tools/automation/azure-pipelines-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ stages:

- template: yaml-templates/commercial-build.yaml
parameters:
makeMSBuildArgs: /p:EnableRoslynAnalyzers=true
makeMSBuildArgs: /p:EnableRoslynAnalyzers=true /p:EnableNativeAnalyzers=true

- template: yaml-templates/upload-results.yaml
parameters:
Expand Down Expand Up @@ -131,7 +131,7 @@ stages:
project: tests/Mono.Android-Tests/Mono.Android-Tests.csproj
testResultsFiles: TestResult-Mono.Android_Tests-$(XA.Build.Configuration).xml
extraBuildArgs: /p:TestAvdApiLevel=$(avdApiLevel) /p:TestAvdAbi=$(avdAbi)
artifactName: Mono.Android_Tests-Signed.apk
artifactSource: bin/Test$(XA.Build.Configuration)/Mono.Android_Tests-Signed.apk
artifactFolder: Default

- task: MSBuild@1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ steps:
/p:MicroBuildOverridePluginDirectory=$(Build.StagingDirectory)/MicroBuild/Plugins
/bl:${{ parameters.xaSourcePath }}/bin/Build$(XA.Build.Configuration)/restore-sign-pkg-content.binlog
- script: make create-installers CONFIGURATION=$(XA.Build.Configuration)
- script: make create-installers CONFIGURATION=$(XA.Build.Configuration) MSBUILD_ARGS='${{ parameters.makeMSBuildArgs }}'
workingDirectory: ${{ parameters.xaSourcePath }}
displayName: make create-installers

Expand Down
16 changes: 8 additions & 8 deletions build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@
<_MSBuildFiles Include="$(MSBuildSrcDir)\jnimarshalmethod-gen.pdb" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\LayoutBinding.cs" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android.debug.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.debug.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.debug.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.debug.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.debug.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android.release.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.release.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.release.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.release.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.release.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+asan.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+asan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-btls-shared.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-btls-shared.d.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-profiler-aot.so')" ExcludeFromAndroidNETSdk="true" />
Expand All @@ -179,8 +179,8 @@
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmonosgen-2.0.d.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libsqlite3_xamarin.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+asan.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+asan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\interpreter-%(Identity)\libmono-btls-shared.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\interpreter-%(Identity)\libmono-profiler-aot.so')" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\interpreter-%(Identity)\libmono-profiler-log.so')" ExcludeFromAndroidNETSdk="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,12 @@ void WriteMSBuildConfigureRuntimeCommands (StreamWriter sw, string indent, strin
flags.Append (String.Join (" ", command.ExtraOptions));
}

sw.WriteLine ($"{indent}<MakeDir Directories=\"{workingDirectory}\" />");
sw.WriteLine ($"{indent}<ItemGroup>");
var conditionString = (workingDirectory.IndexOf ("-asan", StringComparison.OrdinalIgnoreCase) >= 0
|| workingDirectory.IndexOf ("-ubsan", StringComparison.OrdinalIgnoreCase) >= 0)
? " Condition=\"'$(EnableNativeAnalyzers)' == 'true'\" " : string.Empty;

sw.WriteLine ($"{indent}<MakeDir Directories=\"{workingDirectory}\"{conditionString}/>");
sw.WriteLine ($"{indent}<ItemGroup{conditionString}>");
sw.WriteLine ($"{indent} <_ConfigureRuntimeCommands Include=\"{itemName}\">");
sw.WriteLine ($"{indent} <Command>$(CmakePath)</Command>");
WriteProperty (sw, $"{indent} ", "Arguments", flags, replacements);
Expand Down
9 changes: 8 additions & 1 deletion src/monodroid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ endif()

option(ENABLE_CLANG_ASAN "Enable the clang AddressSanitizer support" OFF)
option(ENABLE_CLANG_UBSAN "Enable the clang UndefinedBehaviorSanitizer support" OFF)

if(ENABLE_CLANG_ASAN OR ENABLE_CLANG_UBSAN)
set(STRIP_DEBUG_DEFAULT OFF)
else()
set(STRIP_DEBUG_DEFAULT ON)
endif()

option(ENABLE_NET6 "Enable compilation for .NET6" OFF)
option(ENABLE_TIMING "Build with timing support" OFF)
option(STRIP_DEBUG "Strip debugging information when linking" ON)
option(STRIP_DEBUG "Strip debugging information when linking" ${STRIP_DEBUG_DEFAULT})
option(DISABLE_DEBUG "Disable the built-in debugging code" OFF)
option(USE_CCACHE "Use ccache, if found, to speed up recompilation" ${CCACHE_OPTION_DEFAULT})

Expand Down
45 changes: 28 additions & 17 deletions src/monodroid/monodroid.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<Target Name="_BuildRuntimes" BeforeTargets="Build"
DependsOnTargets="_GenerateIncludeFiles;_ConfigureRuntimes;_BuildAndroidRuntimes;_BuildHostRuntimes">
DependsOnTargets="_GenerateIncludeFiles;_ConfigureRuntimes;_BuildAndroidRuntimes;_BuildAndroidAnalyzerRuntimes;_BuildHostRuntimes">
</Target>
<Target Name="_TestPinvokeTables" Condition=" '$(HostOS)' == 'Linux' And '$(RunningOnCI)' == 'true' ">
<Exec
Expand Down Expand Up @@ -89,21 +89,23 @@
<_BuildAndroidRuntimesInputs Include="..\..\build-tools\scripts\Ndk.targets" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android.debug.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android.debug.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.debug.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.debug.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.debug.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.debug.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android.release.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android.release.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.release.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.release.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.release.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.release.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\Debug\libxamarin-app.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\Debug\libxamarin-app.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\Release\libxamarin-app.so')" />
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\Release\libxamarin-app.so')" />
</ItemGroup>
<ItemGroup Condition=" '$(EnableNativeAnalyzers)' == 'true' ">
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.debug.so')" />
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.debug.so')" />
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.debug.so')" />
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.debug.so')" />
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.release.so')" />
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.release.so')" />
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.release.so')" />
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.release.so')" />
</ItemGroup>
</Target>

<Target Name="_BuildAndroidRuntimes"
Expand All @@ -122,32 +124,40 @@

<Exec
Command="$(NinjaPath) -v"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-asan-Debug"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-Release"
/>

<Exec
Command="$(NinjaPath) -v"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-asan-Debug"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-Release"
/>

<Touch Files="@(_BuildAndroidRuntimesOutputs)" />
</Target>

<Target Name="_BuildAndroidAnalyzerRuntimes"
Condition=" '$(EnableNativeAnalyzers)' == 'true' "
DependsOnTargets="_BuildAndroidRuntimesInputs"
Inputs="@(_BuildAndroidRuntimesInputs)"
Outputs="@(_BuildAndroidAnalyzerRuntimesOutputs)">
<Exec
Command="$(NinjaPath) -v"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-ubsan-Debug"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-asan-Debug"
/>

<Exec
Command="$(NinjaPath) -v"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-ubsan-Debug"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-asan-Debug"
/>

<Exec
Command="$(NinjaPath) -v"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-Release"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-ubsan-Debug"
/>

<Exec
Command="$(NinjaPath) -v"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-Release"
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-ubsan-Debug"
/>

<Exec
Expand All @@ -170,7 +180,7 @@
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-ubsan-Release"
/>

<Touch Files="@(_BuildAndroidRuntimesOutputs)" />
<Touch Files="@(_BuildAndroidAnalyzerRuntimesOutputs)" />
</Target>

<Target Name="_BuildHostRuntimesInputs"
Expand Down Expand Up @@ -270,7 +280,8 @@
</Target>

<Target Name="ClangTidyCheck"
DependsOnTargets="_GetCompileCommandsDirs">
Condition=" '$(EnableNativeAnalyzers)' == 'true' "
DependsOnTargets="_GetCompileCommandsDirs">
<PropertyGroup>
<ClangTidy>$(AndroidNdkDirectory)\toolchains\llvm\prebuilt\$(NdkLlvmTag)\bin\clang-tidy</ClangTidy>
</PropertyGroup>
Expand Down

0 comments on commit f9d86ae

Please sign in to comment.