mirror of
https://github.com/opencv/opencv.git
synced 2024-11-23 18:50:21 +08:00
Page:
Running native OpenCV code with Hardware Address Sanitizer
Pages
.clang_format
2018
2019
2020
2021
2022
2023
2024
Archive
Branches
BuildOpenCV4OpenVINO
CI configuration
CPU optimizations build options
ChangeLog
CiteOpenCV
Coding_Style_Guide
Compact build advice
Contributing to G API: PRs
Custom OpenCV Android SDK and AAR package build
DNN Efficiency
Deep Learning in OpenCV
Documentation improvement plan
Enabling GStreamer source in G API
Enabling oneVPL source in G API
Evolution Proposals
FAQ
G API Ideas towards OpenCV 5.0
G API Python Bindings
GSoC_2017
GSoC_2018
GSoC_2019
GSoC_2020
GSoC_2021
GSoC_2022
GSoC_2023
GSoC_2024
Graph API
Home
HowToUsePerfTests
HowToWritePerfTests
How_to_contribute
Huawei CANN Backend
Intel OpenVINO backend
Linux_contribution_guide
MediaSDK encode decode backend
OE 0. Template
OE 1. Old C API
OE 10. FP16
OE 11. Logging
OE 12. Lapack
OE 13. DNN ONNX Importer
OE 14. DNN FP16
OE 15. Bit Exactness
OE 16. Mini Halide
OE 17. New Filter Engine
OE 18. Module Optflow
OE 19. Module Stereo
OE 2. OpenCV 2
OE 20. Module Calibration
OE 21. Module Tracking
OE 21. Tracking API
OE 22. Module Point Cloud
OE 23. Module GAPI
OE 24. Module HighGUI
OE 25. Fast VideoIO
OE 26. Samples
OE 27. Wide Universal Intrinsics
OE 28. Image Stitching
OE 29. Adding AVX512 Support
OE 3. OpenCV 3
OE 30. Color Calibration
OE 31. Julia Bindings
OE 32. Change OpenCV License to Apache 2
OE 33. 3D Module
OE 34. Named Parameters
OE 35. TFLite support
OE 4. OpenCV 4
OE 5. OpenCV 5
OpenCL optimizations
OpenCV 5
OpenCV Debugging Facilities
OpenCV Platforms
OpenCV RISC V
OpenCVLogo
OpenCV_GSoC
OpenCV_GSoC_Application
Opencv3
Opencv4
Profiling OpenCV Applications
QA_in_OpenCV
Running native OpenCV code with Hardware Address Sanitizer
TIM VX Backend For Running OpenCV On NPU
Template
TensorFlow Object Detection API
TensorFlow text graphs
Using G API with MS ONNX Runtime
Using G API with OpenCV AI Kit (OAK)
Using G API with OpenVINO Toolkit
Using G API with PlaidML backend
Video IO hardware acceleration
Video capture and write benchmark
[Deprecated] Tengine based acceleration
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Hardware Address Sanitizer or HWASan is an ARM64 processor feature that simplifies detection of potential memory problems such as stack/buffer overflow, double free and so on. To use it with OpenCV, the library should be build with HWASan support enabled. In this instruction we'll describe how to build it, run tests on a device and get actual stack traces when memory error is detected.
- Build OpenCV for Android:
- Clone the code from this branch: #25746 (or from 4.x branch if this PR is already merged)
- Open this instruction
- Add
--hwasan
and--debug
flags tobuild_sdk.py
script call - Use NDK with version not less than 25
- Optionally you can speed up build process by commenting out all configurations except
arm64-v8a
in a file$YOUR_OPENCV_REPO/platforms/android/ndk-18-api-level-21.config.py
- Do first 6 steps of the instruction (before building AAR archive)
- From here on we use variable names given in the script from the instruction
- Check if your Android device is ready to run tests:
- Connect the device
- Go to a directory containing ADB tool in terminal:
cd $ANDROID_SDK/platform-tools
- Run ADB:
./adb devices
You should see your connected device - On Linux you may get an error telling that you do not have enough permissions. It can be fixed by:
- adding your user to
plugdev
group:sudo usermod -aG plugdev $USER
- logging out then back in
- plugin out and then back in your Android device
- adding your user to
- Upload test application, test data and C++ STL shared library onto your device:
./adb push $YOUR_OPENCV_BUILD_FOLDER/o4a/bin/opencv_test_core /data/local/tmp
./adb push $YOUR_OPENCV_EXTRA_REPO/testdata /sdcard
./adb push $YOUR_OPENCV_BUILD_FOLDER/o4a/opencv_android/opencv/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libc++_shared.so /data/local/tmp
- Open ADB shell
./adb shell
and run tests on a device:export OPENCV_TEST_DATA_PATH=/sdcard/testdata cd /data/local/tmp LD_HWASAN=1 LD_PRELOAD=/data/local/tmp/libc++_shared.so ./opencv_test_core 2> out.txt
- Extract logs from device:
./adb pull /data/local/tmp/out.txt $YOUR_LOGS_FILE
(do not forget to setYOUR_LOGS_FILE
variable) - HWAsan logs contain stack traces with return addresses expressed in hexadecimal. We’d like to get source files and line numbers instead as we expect that from typical stack trace for a debug build. To get them, we post process these logs by
hwasan_symbolize
script:
$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.6/bin/hwasan_symbolize --symbols $YOUR_OPENCV_BUILD_FOLDER/o4a/bin/ < $YOUR_LOGS_FILE
- Home
- Deep Learning in OpenCV
- Running OpenCV on Various Platforms
- OpenCV 5
- OpenCV 4
- OpenCV 3
- Development process
- OpenCV GSoC
- Archive
© Copyright 2024, OpenCV team