From: Bruno Haible Date: Tue, 5 May 2026 15:15:39 +0000 (+0200) Subject: HACKING: Explain how to use the undefined-behaviour sanitizer. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d760a401052e9573f50d9b258e1f94958a5f7389;p=thirdparty%2Fgettext.git HACKING: Explain how to use the undefined-behaviour sanitizer. * HACKING (Customizing the Undefined Behaviour Sanitizer): New section. --- diff --git a/HACKING b/HACKING index f33e5431b..33a145357 100644 --- a/HACKING +++ b/HACKING @@ -513,6 +513,28 @@ For C source code: Only static variables are better kept declared upfront in a function or block. +Customizing the Undefined Behaviour Sanitizer (UBSAN) +===================================================== + +Using gcc with UBSAN is as usual: + + CC="gcc -fsanitize=undefined,signed-integer-overflow,shift,integer-divide-by-zero -fno-sanitize-recover=undefined" + CXX="g++ -fsanitize=undefined,signed-integer-overflow,shift,integer-divide-by-zero -fno-sanitize-recover=undefined" + CFLAGS="-O1 -fno-omit-frame-pointer -ggdb" + CXXFLAGS="-O1 -fno-omit-frame-pointer -ggdb" + export CC CXX CFLAGS CXXFLAGS + +Using clang with UBSAN needs a customization, to avoid errors such as + "runtime error: call to function get_control_data through pointer to incorrect function type" +coming from libtextstyle, namely + + CC="clang -fsanitize=undefined,signed-integer-overflow,shift,integer-divide-by-zero -fno-sanitize=function -fno-sanitize-recover=undefined" + CXX="clang++ -fsanitize=undefined,signed-integer-overflow,shift,integer-divide-by-zero -fno-sanitize=function -fno-sanitize-recover=undefined" + CFLAGS="-O1 -fno-omit-frame-pointer -ggdb" + CXXFLAGS="-O1 -fno-omit-frame-pointer -ggdb" + export CC CXX CFLAGS CXXFLAGS + + Submitting patches ==================