Skip to content

Commit e54f258

Browse files
authored
Merge pull request #85 from mapbox/local-sanitizers
make sanitize
2 parents 38041fe + 5b7be9d commit e54f258

File tree

9 files changed

+48
-14
lines changed

9 files changed

+48
-14
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ tidy:
2727
format:
2828
./scripts/clang-format.sh
2929

30+
sanitize:
31+
./scripts/sanitize.sh
32+
3033
clean:
3134
rm -rf lib/binding
3235
rm -rf build

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ Note: by default the build errors on compiler warnings. To disable this do:
5555
WERROR=false make
5656
```
5757

58-
Enable additional sanitizers to catch hard-to-find bugs, for example:
58+
Run tests locally with compile flags enabled to catch hard-to-find bugs (see [this PR](https://github.com/mapbox/node-cpp-skel/pull/85) for more info):
5959

6060
```shell
61-
export LDFLAGS="-fsanitize=address,undefined,integer"
62-
export CXXFLAGS="-fsanitize=address,undefined,integer"
63-
64-
make
61+
make sanitize
6562
```
6663

64+
The sanitizers [are part of the compiler](https://github.com/mapbox/cpp/blob/master/glossary.md#sanitizers) and are also run in a specific job on Travis.
65+
6766
# Add Custom Code
6867

6968
`node-cpp-skel` was designed to make adding custom code simple and scalable, to form to whatever usecase you may need. Here's how:

scripts/sanitize.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
: '
7+
8+
Rebuilds the code with the sanitizers and runs the tests
9+
10+
'
11+
# Set up the environment by installing mason and clang++
12+
# See https://github.com/mapbox/node-cpp-skel/blob/master/docs/extended-tour.md#configuration-files
13+
./scripts/setup.sh --config local.env
14+
source local.env
15+
make clean
16+
export CXXFLAGS="${MASON_SANITIZE_CXXFLAGS} ${CXXFLAGS:-}"
17+
export LDFLAGS="${MASON_SANITIZE_LDFLAGS} ${LDFLAGS:-}"
18+
make debug
19+
export ASAN_OPTIONS=fast_unwind_on_malloc=0:${ASAN_OPTIONS}
20+
if [[ $(uname -s) == 'Darwin' ]]; then
21+
# NOTE: we must call node directly here rather than `npm test`
22+
# because OS X blocks `DYLD_INSERT_LIBRARIES` being inherited by sub shells
23+
# If this is not done right we'll see
24+
# ==18464==ERROR: Interceptors are not working. This may be because AddressSanitizer is loaded too late (e.g. via dlopen).
25+
#
26+
DYLD_INSERT_LIBRARIES=${MASON_LLVM_RT_PRELOAD} \
27+
node test/*test.js
28+
else
29+
LD_PRELOAD=${MASON_LLVM_RT_PRELOAD} \
30+
npm test
31+
fi
32+

scripts/setup.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
set -eu
44
set -o pipefail
55

6-
export MASON_RELEASE="${MASON_RELEASE:-v0.14.1}"
7-
export MASON_LLVM_RELEASE="${MASON_LLVM_RELEASE:-4.0.1}"
6+
export MASON_RELEASE="${MASON_RELEASE:-eeba3b5}"
7+
export MASON_LLVM_RELEASE="${MASON_LLVM_RELEASE:-5.0.0}"
88

99
PLATFORM=$(uname | tr A-Z a-z)
1010
if [[ ${PLATFORM} == 'darwin' ]]; then
@@ -89,8 +89,8 @@ function run() {
8989
echo "export MSAN_SYMBOLIZER_PATH=${llvm_toolchain_dir}/bin/llvm-symbolizer" >> ${config}
9090
echo "export UBSAN_OPTIONS=print_stacktrace=1" >> ${config}
9191
echo "export LSAN_OPTIONS=suppressions=${SUPPRESSION_FILE}" >> ${config}
92-
echo "export ASAN_OPTIONS=symbolize=1:abort_on_error=1:detect_container_overflow=1:check_initialization_order=1:detect_stack_use_after_return=1" >> ${config}
93-
echo 'export MASON_SANITIZE="-fsanitize=address,undefined,integer -fno-sanitize=vptr,function"' >> ${config}
92+
echo "export ASAN_OPTIONS=detect_leaks=1:symbolize=1:abort_on_error=1:detect_container_overflow=1:check_initialization_order=1:detect_stack_use_after_return=1" >> ${config}
93+
echo 'export MASON_SANITIZE="-fsanitize=address,undefined,integer,leak -fno-sanitize=vptr,function"' >> ${config}
9494
echo 'export MASON_SANITIZE_CXXFLAGS="${MASON_SANITIZE} -fno-sanitize=vptr,function -fsanitize-address-use-after-scope -fno-omit-frame-pointer -fno-common"' >> ${config}
9595
echo 'export MASON_SANITIZE_LDFLAGS="${MASON_SANITIZE}"' >> ${config}
9696

src/module_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ inline void CallbackError(std::string message,
2424
v8::Local<v8::Value> argv[1] = {Nan::Error(message.c_str())};
2525
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, 1, argv);
2626
}
27-
}
27+
} // namespace utils

src/object_async/hello_async.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ class HelloObjectAsync : public Nan::ObjectWrap {
3333
// specific to each instance of the class
3434
std::string name_;
3535
};
36-
}
36+
} // namespace object_async

src/object_sync/hello.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ class HelloObject : public Nan::ObjectWrap {
3131
// specific to each instance of the class
3232
std::string name_;
3333
};
34-
}
34+
} // namespace object_sync

src/standalone/hello.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ namespace standalone {
3333
// hello, custom sync method tied to module.cpp
3434
// method's logic lives in hello.cpp
3535
NAN_METHOD(hello);
36-
}
36+
} // namespace standalone

src/standalone_async/hello_async.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ namespace standalone_async {
3232
// hello, custom sync method tied to module.cpp
3333
// method's logic lives in hello.cpp
3434
NAN_METHOD(helloAsync);
35-
}
35+
} // namespace standalone_async

0 commit comments

Comments
 (0)