From d4c8131d570e926aa6fd89b6de2cacd13bf32714 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sun, 24 Nov 2024 21:44:50 +0800 Subject: [PATCH] disable sanitize --- Makefile | 1 + README.org | 5 ++++- zigcc/__init__.py | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8a707d3..baad2a1 100644 --- a/Makefile +++ b/Makefile @@ -14,5 +14,6 @@ lint: readme: pandoc -f org -t markdown README.org -o README.md + sed -i 's/{.verbatim}//g' README.md .PHONY: build clean fix lint readme diff --git a/README.org b/README.org index 508742b..deab397 100644 --- a/README.org +++ b/README.org @@ -43,7 +43,10 @@ Then you can invoke =zigcc= =zigcxx= =zigcargo= in following steps. * Config There some are env variable to config zigcc: -- =ZIGCC_FLAGS=, space separated flags, pass to zig cc. An example is set this to =-fno-sanitize=undefined= to disable sanitize since they may break your programs. See [[https://nathancraddock.com/blog/zig-cc-undefined-behavior/][Catching undefined behavior with zig cc]] +- =ZIGCC_FLAGS=, space separated flags, pass to zig cc. +- =ZIGCC_ENABLE_SANITIZE= By default Zig will pass =-fsanitize=undefined -fsanitize-trap=undefined= to clang when compile without =-O2=, =-O3=, this causes Undefined Behavior to cause an Illegal Instruction, see [[https://nathancraddock.com/blog/zig-cc-undefined-behavior/][Catching undefined behavior with zig cc]]. + + So we disable it by default, set this variable to =1= to re-enable it. - =ZIGCC_BLACKLIST_FLAGS=, space separated flags, used to filter flags =zig cc= don't support, such as =-Wl,-dylib= otherwise you could see errors below #+begin_src bash note: error: unsupported linker arg: -dylib diff --git a/zigcc/__init__.py b/zigcc/__init__.py index 4350214..38106cf 100755 --- a/zigcc/__init__.py +++ b/zigcc/__init__.py @@ -11,21 +11,24 @@ # # Supported env vars: # 1. `ZIGCC_VERBOSE`, enable verbose log -# 2. `ZIGCC_FLAGS`, extra flags passed to zig, such as `-fno-sanitize=undefined` +# 2. `ZIGCC_FLAGS`, extra flags passed to zig import sys import os import logging import subprocess -__VERSION__ = '1.0.0' +__VERSION__ = '1.0.1' UNKNOWN = 0 RUST = 1 GO = 2 ENABLE_LOG = os.getenv('ZIGCC_VERBOSE', '0') == '1' +ENABLE_SANITIZE = os.getenv('ZIGCC_ENABLE_SANITIZE', '0') == '1' APPEND_SYSROOT = os.getenv('ZIGCC_APPEND_SYSROOT', '0') == '1' -FLAGS = os.getenv('ZIGCC_FLAGS', '').split(' ') +FLAGS = os.getenv( + 'ZIGCC_FLAGS', '' if ENABLE_SANITIZE else '-fno-sanitize=undefined' +).split(' ') FLAGS = [f for f in FLAGS if f != ''] # Blacklist flags, wild match