Skip to content

Commit f9d86ae

Browse files
authored
[build/ci] Enable native code analysis nightly (#6420)
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.
1 parent 6509d17 commit f9d86ae

File tree

6 files changed

+53
-31
lines changed

6 files changed

+53
-31
lines changed

build-tools/automation/azure-pipelines-nightly.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ stages:
6060

6161
- template: yaml-templates/commercial-build.yaml
6262
parameters:
63-
makeMSBuildArgs: /p:EnableRoslynAnalyzers=true
63+
makeMSBuildArgs: /p:EnableRoslynAnalyzers=true /p:EnableNativeAnalyzers=true
6464

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

137137
- task: MSBuild@1

build-tools/automation/yaml-templates/commercial-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ steps:
8181
/p:MicroBuildOverridePluginDirectory=$(Build.StagingDirectory)/MicroBuild/Plugins
8282
/bl:${{ parameters.xaSourcePath }}/bin/Build$(XA.Build.Configuration)/restore-sign-pkg-content.binlog
8383
84-
- script: make create-installers CONFIGURATION=$(XA.Build.Configuration)
84+
- script: make create-installers CONFIGURATION=$(XA.Build.Configuration) MSBUILD_ARGS='${{ parameters.makeMSBuildArgs }}'
8585
workingDirectory: ${{ parameters.xaSourcePath }}
8686
displayName: make create-installers
8787

build-tools/installers/create-installers.targets

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@
159159
<_MSBuildFiles Include="$(MSBuildSrcDir)\jnimarshalmethod-gen.pdb" ExcludeFromAndroidNETSdk="true" />
160160
<_MSBuildFiles Include="$(MSBuildSrcDir)\LayoutBinding.cs" />
161161
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android.debug.so')" ExcludeFromAndroidNETSdk="true" />
162-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.debug.so')" ExcludeFromAndroidNETSdk="true" />
163-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.debug.so')" ExcludeFromAndroidNETSdk="true" />
162+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.debug.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
163+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.debug.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
164164
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android.release.so')" ExcludeFromAndroidNETSdk="true" />
165-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.release.so')" ExcludeFromAndroidNETSdk="true" />
166-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.release.so')" ExcludeFromAndroidNETSdk="true" />
165+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+asan.release.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
166+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-android-checked+ubsan.release.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
167167
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api.so')" ExcludeFromAndroidNETSdk="true" />
168-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+asan.so')" ExcludeFromAndroidNETSdk="true" />
169-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" />
168+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+asan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
169+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxa-internal-api-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
170170
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-btls-shared.so')" ExcludeFromAndroidNETSdk="true" />
171171
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-btls-shared.d.so')" ExcludeFromAndroidNETSdk="true" />
172172
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmono-profiler-aot.so')" ExcludeFromAndroidNETSdk="true" />
@@ -179,8 +179,8 @@
179179
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libmonosgen-2.0.d.so')" ExcludeFromAndroidNETSdk="true" />
180180
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libsqlite3_xamarin.so')" ExcludeFromAndroidNETSdk="true" />
181181
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper.so')" ExcludeFromAndroidNETSdk="true" />
182-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+asan.so')" ExcludeFromAndroidNETSdk="true" />
183-
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" />
182+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+asan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
183+
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\%(Identity)\libxamarin-debug-app-helper-checked+ubsan.so')" ExcludeFromAndroidNETSdk="true" Condition=" '$(EnableNativeAnalyzers)' == 'true' " />
184184
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\interpreter-%(Identity)\libmono-btls-shared.so')" ExcludeFromAndroidNETSdk="true" />
185185
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\interpreter-%(Identity)\libmono-profiler-aot.so')" ExcludeFromAndroidNETSdk="true" />
186186
<_MSBuildFiles Include="@(AndroidSupportedTargetJitAbi->'$(MSBuildSrcDir)\lib\interpreter-%(Identity)\libmono-profiler-log.so')" ExcludeFromAndroidNETSdk="true" />

build-tools/xaprepare/xaprepare/Application/GeneratedMonodroidCmakeFiles.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,12 @@ void WriteMSBuildConfigureRuntimeCommands (StreamWriter sw, string indent, strin
403403
flags.Append (String.Join (" ", command.ExtraOptions));
404404
}
405405

406-
sw.WriteLine ($"{indent}<MakeDir Directories=\"{workingDirectory}\" />");
407-
sw.WriteLine ($"{indent}<ItemGroup>");
406+
var conditionString = (workingDirectory.IndexOf ("-asan", StringComparison.OrdinalIgnoreCase) >= 0
407+
|| workingDirectory.IndexOf ("-ubsan", StringComparison.OrdinalIgnoreCase) >= 0)
408+
? " Condition=\"'$(EnableNativeAnalyzers)' == 'true'\" " : string.Empty;
409+
410+
sw.WriteLine ($"{indent}<MakeDir Directories=\"{workingDirectory}\"{conditionString}/>");
411+
sw.WriteLine ($"{indent}<ItemGroup{conditionString}>");
408412
sw.WriteLine ($"{indent} <_ConfigureRuntimeCommands Include=\"{itemName}\">");
409413
sw.WriteLine ($"{indent} <Command>$(CmakePath)</Command>");
410414
WriteProperty (sw, $"{indent} ", "Arguments", flags, replacements);

src/monodroid/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ endif()
3535

3636
option(ENABLE_CLANG_ASAN "Enable the clang AddressSanitizer support" OFF)
3737
option(ENABLE_CLANG_UBSAN "Enable the clang UndefinedBehaviorSanitizer support" OFF)
38+
39+
if(ENABLE_CLANG_ASAN OR ENABLE_CLANG_UBSAN)
40+
set(STRIP_DEBUG_DEFAULT OFF)
41+
else()
42+
set(STRIP_DEBUG_DEFAULT ON)
43+
endif()
44+
3845
option(ENABLE_NET6 "Enable compilation for .NET6" OFF)
3946
option(ENABLE_TIMING "Build with timing support" OFF)
40-
option(STRIP_DEBUG "Strip debugging information when linking" ON)
47+
option(STRIP_DEBUG "Strip debugging information when linking" ${STRIP_DEBUG_DEFAULT})
4148
option(DISABLE_DEBUG "Disable the built-in debugging code" OFF)
4249
option(USE_CCACHE "Use ccache, if found, to speed up recompilation" ${CCACHE_OPTION_DEFAULT})
4350

src/monodroid/monodroid.targets

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</PropertyGroup>
2121

2222
<Target Name="_BuildRuntimes" BeforeTargets="Build"
23-
DependsOnTargets="_GenerateIncludeFiles;_ConfigureRuntimes;_BuildAndroidRuntimes;_BuildHostRuntimes">
23+
DependsOnTargets="_GenerateIncludeFiles;_ConfigureRuntimes;_BuildAndroidRuntimes;_BuildAndroidAnalyzerRuntimes;_BuildHostRuntimes">
2424
</Target>
2525
<Target Name="_TestPinvokeTables" Condition=" '$(HostOS)' == 'Linux' And '$(RunningOnCI)' == 'true' ">
2626
<Exec
@@ -89,21 +89,23 @@
8989
<_BuildAndroidRuntimesInputs Include="..\..\build-tools\scripts\Ndk.targets" />
9090
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android.debug.so')" />
9191
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android.debug.so')" />
92-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.debug.so')" />
93-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.debug.so')" />
94-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.debug.so')" />
95-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.debug.so')" />
9692
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android.release.so')" />
9793
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android.release.so')" />
98-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.release.so')" />
99-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.release.so')" />
100-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.release.so')" />
101-
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.release.so')" />
10294
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\Debug\libxamarin-app.so')" />
10395
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\Debug\libxamarin-app.so')" />
10496
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\Release\libxamarin-app.so')" />
10597
<_BuildAndroidRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\Release\libxamarin-app.so')" />
10698
</ItemGroup>
99+
<ItemGroup Condition=" '$(EnableNativeAnalyzers)' == 'true' ">
100+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.debug.so')" />
101+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.debug.so')" />
102+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.debug.so')" />
103+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.debug.so')" />
104+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+asan.release.so')" />
105+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+asan.release.so')" />
106+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android-checked+ubsan.release.so')" />
107+
<_BuildAndroidAnalyzerRuntimesOutputs Include="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)-net6\libmono-android-checked+ubsan.release.so')" />
108+
</ItemGroup>
107109
</Target>
108110

109111
<Target Name="_BuildAndroidRuntimes"
@@ -122,32 +124,40 @@
122124

123125
<Exec
124126
Command="$(NinjaPath) -v"
125-
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-asan-Debug"
127+
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-Release"
126128
/>
127129

128130
<Exec
129131
Command="$(NinjaPath) -v"
130-
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-asan-Debug"
132+
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-Release"
131133
/>
132134

135+
<Touch Files="@(_BuildAndroidRuntimesOutputs)" />
136+
</Target>
137+
138+
<Target Name="_BuildAndroidAnalyzerRuntimes"
139+
Condition=" '$(EnableNativeAnalyzers)' == 'true' "
140+
DependsOnTargets="_BuildAndroidRuntimesInputs"
141+
Inputs="@(_BuildAndroidRuntimesInputs)"
142+
Outputs="@(_BuildAndroidAnalyzerRuntimesOutputs)">
133143
<Exec
134144
Command="$(NinjaPath) -v"
135-
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-ubsan-Debug"
145+
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-asan-Debug"
136146
/>
137147

138148
<Exec
139149
Command="$(NinjaPath) -v"
140-
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-ubsan-Debug"
150+
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-asan-Debug"
141151
/>
142152

143153
<Exec
144154
Command="$(NinjaPath) -v"
145-
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-Release"
155+
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-ubsan-Debug"
146156
/>
147157

148158
<Exec
149159
Command="$(NinjaPath) -v"
150-
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-Release"
160+
WorkingDirectory="$(IntermediateOutputPath)%(AndroidSupportedTargetJitAbi.Identity)-net6-ubsan-Debug"
151161
/>
152162

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

173-
<Touch Files="@(_BuildAndroidRuntimesOutputs)" />
183+
<Touch Files="@(_BuildAndroidAnalyzerRuntimesOutputs)" />
174184
</Target>
175185

176186
<Target Name="_BuildHostRuntimesInputs"
@@ -270,7 +280,8 @@
270280
</Target>
271281

272282
<Target Name="ClangTidyCheck"
273-
DependsOnTargets="_GetCompileCommandsDirs">
283+
Condition=" '$(EnableNativeAnalyzers)' == 'true' "
284+
DependsOnTargets="_GetCompileCommandsDirs">
274285
<PropertyGroup>
275286
<ClangTidy>$(AndroidNdkDirectory)\toolchains\llvm\prebuilt\$(NdkLlvmTag)\bin\clang-tidy</ClangTidy>
276287
</PropertyGroup>

0 commit comments

Comments
 (0)