Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1317039 - Make GYP clang sanitizer builds work with macOS r=franz…
…iskus

Differential Revision: https://nss-review.dev.mozaws.net/D56
  • Loading branch information
Tim Taubert committed Nov 14, 2016
1 parent 607c886 commit 490c80b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
13 changes: 0 additions & 13 deletions build.sh
Expand Up @@ -64,19 +64,6 @@ gyp_params=()
ninja_params=()
scanbuild=()

check_sanitizer()
{
# We can't run sanitizers on Mac for now.
if [ $(uname) != "Linux" ]; then
echo "
#### #### #### #### #### #### #### #### #### #### #### ####
#### Sorry, sanitizers only work on Linux for now ####
#### #### #### #### #### #### #### #### #### #### #### ####"
show_help
exit
fi
}

enable_fuzz()
{
nspr_sanitizer asan
Expand Down
55 changes: 46 additions & 9 deletions coreconf/config.gypi
Expand Up @@ -282,21 +282,58 @@
}],
[ 'use_asan==1 or use_ubsan==1', {
'cflags': ['-O1'],
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '1', # -O1
}
}],
[ 'use_asan==1', {
'cflags': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py asan)'],
'ldflags': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py asan)'],
'ldflags!': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py ld)'],
'variables': {
'asan_flags': '<!(<(python) <(DEPTH)/coreconf/sanitizers.py asan)',
'no_ldflags': '<!(<(python) <(DEPTH)/coreconf/sanitizers.py ld)',
},
'cflags': ['<@(asan_flags)'],
'ldflags': ['<@(asan_flags)'],
'ldflags!': ['<@(no_ldflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(asan_flags)'],
'OTHER_LDFLAGS!': ['<@(no_ldflags)'],
# We want to pass -fsanitize=... to our final link call,
# but not to libtool. OTHER_LDFLAGS is passed to both.
# To trick GYP into doing what we want, we'll piggyback on
# LIBRARY_SEARCH_PATHS, producing "-L/usr/lib -fsanitize=...".
# The -L/usr/lib is redundant but innocuous: it's a default path.
'LIBRARY_SEARCH_PATHS': ['/usr/lib <(asan_flags)'],
},
}],
[ 'use_ubsan==1', {
'cflags': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py ubsan)'],
'ldflags': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py ubsan)'],
'ldflags!': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py ld)'],
'variables': {
'ubsan_flags': '<!(<(python) <(DEPTH)/coreconf/sanitizers.py ubsan)',
'no_ldflags': '<!(<(python) <(DEPTH)/coreconf/sanitizers.py ld)',
},
'cflags': ['<@(ubsan_flags)'],
'ldflags': ['<@(ubsan_flags)'],
'ldflags!': ['<@(no_ldflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(ubsan_flags)'],
'OTHER_LDFLAGS!': ['<@(no_ldflags)'],
# See comment above.
'LIBRARY_SEARCH_PATHS': ['/usr/lib <(ubsan_flags)'],
},
}],
[ 'use_sancov!=0', {
'cflags': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py sancov <(use_sancov))'],
'ldflags': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py sancov <(use_sancov))'],
'ldflags!': ['<!@(<(python) <(DEPTH)/coreconf/sanitizers.py ld)'],
'variables': {
'sancov_flags': '<!(<(python) <(DEPTH)/coreconf/sanitizers.py sancov <(use_sancov))',
'no_ldflags': '<!(<(python) <(DEPTH)/coreconf/sanitizers.py ld)',
},
'cflags': ['<@(sancov_flags)'],
'ldflags': ['<@(sancov_flags)'],
'ldflags!': ['<@(no_ldflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(sancov_flags)'],
'OTHER_LDFLAGS!': ['<@(no_ldflags)'],
# See comment above.
'LIBRARY_SEARCH_PATHS': ['/usr/lib <(sancov_flags)'],
},
}],
[ 'OS=="android" and mozilla_client==0', {
'defines': [
Expand Down
1 change: 0 additions & 1 deletion coreconf/nspr.sh
Expand Up @@ -12,7 +12,6 @@ nspr_ldflags=

nspr_sanitizer()
{
check_sanitizer
nspr_cflags="$nspr_cflags $(python $cwd/coreconf/sanitizers.py $1 $2)"
nspr_cxxflags="$nspr_cxxflags $(python $cwd/coreconf/sanitizers.py $1 $2)"
nspr_ldflags="$nspr_ldflags $(python $cwd/coreconf/sanitizers.py $1 $2)"
Expand Down
9 changes: 8 additions & 1 deletion fuzz/libFuzzer/libFuzzer.gyp
Expand Up @@ -30,7 +30,14 @@
'cflags/': [
['exclude', '-fsanitize='],
['exclude', '-fsanitize-'],
]
],
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '2', # -O2
'OTHER_CFLAGS/': [
['exclude', '-fsanitize='],
['exclude', '-fsanitize-'],
],
},
}
],
}

0 comments on commit 490c80b

Please sign in to comment.