onnxruntime/tools/ci_build/github/azure-pipelines/templates/c-api-linux-cpu.yml
Changming Sun 0e8d4c3d21
Enable Address Sanitizer in CI (#19073)
### Description
1. Add two build jobs for enabling Address Sanitizer in CI. One for
Windows CPU, One for Linux CPU.
2. Set default compiler flags/linker flags in build.py for normal
Windows/Linux/MacOS build. This can help control compiler flags in a
more centralized way.
3. All Windows binaries in our official packages will be built with
"/PROFILE" flag. Symbols of onnxruntime.dll can be found at [Microsoft
public symbol
server](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/microsoft-public-symbols).

Limitations:
1. On Linux Address Sanitizer ignores RPATH settings in ELF binaries.
Therefore once Address Sanitizer is enabled, before running tests we
need to manually set LD_LIBRARY_PATH properly otherwise
libonnxruntime.so may not be able to find custom ops and shared EPs.
4. On Linux we also need to set LD_PRELOAD before running some tests(if
the main executable, like python, is not built with address sanitizer.
On Windows we do not need to.
5. On Windows before running python tests we should manually copy
address sanitizer DLL to the onnxruntime/capi directory, because python
3.8 and above has enabled "Safe DLL Search Mode" that wouldn't use the
information provided by PATH env.
6. On Linux Address Sanitizer found a lot of memory leaks from our
python binding code. Therefore right now we cannot enable Address
Sanitizer when building ONNX Runtime with python binding.
7. Address Sanitizer itself uses a lot of memory address space and
delays memory deallocations, which is easy to cause OOM issues in 32-bit
applications. We cannot run all the tests in onnxruntime_test_all in
32-bit mode with Address Sanitizer due to this reason. However, we still
can run individual tests in such a way. We just cannot run all of them
in one process.

### Motivation and Context
To catch memory issues.
2024-01-12 07:24:40 -08:00

108 lines
4.1 KiB
YAML

# This file contains the ADO job that build libonnxruntime.so on Linux
parameters:
- name: AdditionalBuildFlags
displayName: Additional build flags for build.py
type: string
default: ''
- name: BaseImage
type: string
- name: OnnxruntimeArch
type: string
- name: OnnxruntimeNodejsBindingArch
type: string
values:
- arm64
- x64
- name: PoolName
type: string
default: 'onnxruntime-Ubuntu2004-AMD-CPU'
- name: ArtifactNamePrefix
type: string
default: "onnxruntime"
- name: PackageJava
type: boolean
default: true
- name: PackageNodejs
type: boolean
default: true
jobs:
- job: Linux_C_API_Packaging_CPU_${{parameters.OnnxruntimeArch}}
workspace:
clean: all
variables:
- name: skipComponentGovernanceDetection
value: ${{eq('${{parameters.OnnxruntimeNodejsBindingArch}}', 'arm64')}}
timeoutInMinutes: 210
pool: ${{parameters.PoolName}}
steps:
- checkout: self
clean: true
submodules: none
- template: set-version-number-variables-step.yml
- template: get-docker-image-steps.yml
parameters:
Dockerfile: tools/ci_build/github/linux/docker/inference/${{parameters.OnnxruntimeArch}}/default/cpu/Dockerfile
Context: tools/ci_build/github/linux/docker/inference/${{parameters.OnnxruntimeArch}}/default/cpu
DockerBuildArgs: "--build-arg BUILD_UID=$( id -u ) --build-arg BASEIMAGE=${{parameters.BaseImage}}"
Repository: onnxruntimecpubuildcentos8${{parameters.OnnxruntimeArch}}
${{ if eq(parameters.OnnxruntimeArch, 'aarch64') }}:
UpdateDepsTxt: false
- task: CmdLine@2
inputs:
script: |
mkdir -p $HOME/.onnx
docker run --rm --volume /data/onnx:/data/onnx:ro --volume $(Build.SourcesDirectory):/onnxruntime_src --volume $(Build.BinariesDirectory):/build \
--volume $HOME/.onnx:/home/onnxruntimedev/.onnx -e NIGHTLY_BUILD onnxruntimecpubuildcentos8${{parameters.OnnxruntimeArch}} /bin/bash -c "python3.9 \
/onnxruntime_src/tools/ci_build/build.py --enable_lto --build_java --build_nodejs --build_dir /build --config Release \
--skip_submodule_sync --parallel --build_shared_lib ${{ parameters.AdditionalBuildFlags }} && cd /build/Release && make install DESTDIR=/build/linux-${{parameters.OnnxruntimeArch}}"
workingDirectory: $(Build.SourcesDirectory)
displayName: 'Build'
- script: |
set -e -x
mkdir $(Build.ArtifactStagingDirectory)/testdata
cp $(Build.BinariesDirectory)/Release/libcustom_op_library.so* $(Build.ArtifactStagingDirectory)/testdata
ls -al $(Build.ArtifactStagingDirectory)
displayName: 'Create Artifacts'
- ${{ if eq(parameters.PackageJava, 'true') }}:
- template: java-api-artifacts-package-and-publish-steps-posix.yml
parameters:
arch: 'linux-${{parameters.OnnxruntimeArch}}'
buildConfig: 'Release'
artifactName: 'onnxruntime-java-linux-${{parameters.OnnxruntimeArch}}'
version: '$(OnnxRuntimeVersion)'
libraryName: 'libonnxruntime.so'
nativeLibraryName: 'libonnxruntime4j_jni.so'
- template: c-api-artifacts-package-and-publish-steps-posix.yml
parameters:
buildConfig: 'Release'
artifactName: '${{parameters.ArtifactNamePrefix}}-linux-${{parameters.OnnxruntimeArch}}-$(OnnxRuntimeVersion)'
artifactNameNoVersionString: '${{parameters.ArtifactNamePrefix}}-linux-${{parameters.OnnxruntimeArch}}'
libraryName: 'libonnxruntime.so.$(OnnxRuntimeVersion)'
- ${{ if eq(parameters.PackageNodejs, 'true') }}:
- template: nodejs-artifacts-package-and-publish-steps-posix.yml
parameters:
arch: '${{parameters.OnnxruntimeNodejsBindingArch}}'
os: 'linux'
artifactName: 'drop-onnxruntime-nodejs-linux-${{parameters.OnnxruntimeArch}}'
- ${{ if not(eq(parameters.OnnxruntimeNodejsBindingArch, 'arm64')) }}:
- template: component-governance-component-detection-steps.yml
parameters:
condition: 'succeeded'
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
displayName: 'Clean Agent Directories'
condition: always()