Categories
Tags
3d algorithms alignment analyze APIT Arc Architecture arm ascii assembly asynchronous base64 BitHacks Blogging box c c23 clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete doc DP drawio dtruss Dynamic emulator example Example FFI flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative interop invariant iterator join justfile kernel LaTeX leak LFU linux lto MachineLearning macOS map Markdown math ML mmap mod nc OnceLock optimization OS ownership panic parallels perf physics pin postgresql product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift sin size SmallProjects socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous tan thread time toml tracing traits triangulation uint32_t UnsafeRust utf16 utf8 Video vulkan wsl x86_64 xilem zig
306 words
2 minutes
Sanitizer_is_a_tool_developed_by_Google
link
C언어에서 sanitizer컴파일 옵션
- justfile로 자동화 시킴
# Clang Sanitize(ASan=address / LSan=leak / TSan=thread / MSan=memory / UBSan=undefined (Undefined Behavior)
clang_which := `which clang`
# Files
source := src_dir+"/main.c"
san SAN:
rm -rf target
mkdir -p target
{{clang_which}} -g -fsanitize={{SAN}} -fno-omit-frame-pointer -c {{source}}
{{clang_which}} -g -fsanitize={{SAN}} *.o
mv a.out *.o {{target_dir}}
{{target_dir}}/a.out출력된 모습
$ LSAN_OPTIONS=suppressions=../.lsan.supp
rm -rf target
mkdir -p target
/opt/homebrew/opt/llvm/bin/clang -g -fsanitize=leak -fno-omit-frame-pointer -c ./src/main.c
/opt/homebrew/opt/llvm/bin/clang -g -fsanitize=leak *.o
mv a.out *.o ./target
./target/a.out
Hello, Worl
sizeof(*s) = 1
-----------------------------------------------------
Suppressions used:
count bytes template
3 120 libobjc.A.dylibSanitizers - Tools|🔝|
AddressSanitizer(ASan)
- detects addressability issues
LeakSanitizer(LSan)
ThreadSanitizer(TSan)
- detects data races and deadlocks
MemorySanitizer(MSan)
UndefinedBehaviorSanitizer(UBSan)
- dectects undefined behavior
(19min나옴)Harnessing constexpr - A Path to Safer C++ - Mikhail Svetkin - C++Now 2025 | CppNow
sanitizers 설명서
Thread 설명서
gcc로 하는 방법
https://www.osc.edu/resources/getting_started/howto/howto_use_address_sanitizer
In one command, this looks like:
gcc main.c -o main -fsanitize=address -static-libasan -g- Or, splitting into separate compiling and linking stages:
gcc -c main.c -fsanitize=address -g
gcc main.o -o main -fsanitize=address -static-libasancmake로 자동화 시키기(C23)
address 샘플
CMakeLists.txt
cmake_minimum_required(VERSION 4.0)
get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId} LANGUAGES C)
# Force GCC 15
set(CMAKE_C_COMPILER "/opt/gcc-15/bin/gcc")
# Force Clang 20(macOS)
# set(CMAKE_CXX_COMPILER "/opt/homebrew/opt/llvm/bin/clang")
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
SET (CMAKE_C_FLAGS_INIT "-Wall -std=c23")
SET (CMAKE_C_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
SET (CMAKE_CXX_FLAGS_INIT "-Wall -std=c++23")
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
# Common compile flags
add_compile_options(
-pedantic
-pthread
-pedantic-errors
-lm
-Wall
-Wextra
-ggdb
-g
-fsanitize=address
# -std=c23
)
# Main executable with C23 sources
add_executable(${ProjectId}
src/main.c
# src/add_sources.c
)
target_link_options(${ProjectId} PRIVATE -pthread -lm -fsanitize=address)
# Output directory
set_target_properties(${ProjectId} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target
)Sanitizer_is_a_tool_developed_by_Google
https://younghakim7.github.io/blog/posts/sanitizer_is_a_tool_developed_by_google/