Skip to content

Commit

Permalink
disable sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Nov 24, 2024
1 parent bef26c7 commit d4c8131
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions zigcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4c8131

Please sign in to comment.