Skip to content

Commit 101db80

Browse files
skomskirvagg
authored andcommitted
build: add --enable-asan with builtin leakcheck
PR-URL: #2376 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 609db5a commit 101db80

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

common.gypi

+20-2
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,34 @@
173173
},
174174
'msvs_disabled_warnings': [4351, 4355, 4800],
175175
'conditions': [
176-
['asan != 0', {
176+
['asan == 1 and OS != "mac"', {
177177
'cflags+': [
178178
'-fno-omit-frame-pointer',
179179
'-fsanitize=address',
180-
'-w', # http://crbug.com/162783
180+
'-DLEAK_SANITIZER'
181181
],
182182
'cflags_cc+': [ '-gline-tables-only' ],
183183
'cflags!': [ '-fomit-frame-pointer' ],
184184
'ldflags': [ '-fsanitize=address' ],
185185
}],
186+
['asan == 1 and OS == "mac"', {
187+
'xcode_settings': {
188+
'OTHER_CFLAGS+': [
189+
'-fno-omit-frame-pointer',
190+
'-gline-tables-only',
191+
'-fsanitize=address',
192+
'-DLEAK_SANITIZER'
193+
],
194+
'OTHER_CFLAGS!': [
195+
'-fomit-frame-pointer',
196+
],
197+
},
198+
'target_conditions': [
199+
['_type!="static_library"', {
200+
'xcode_settings': {'OTHER_LDFLAGS': ['-fsanitize=address']},
201+
}],
202+
],
203+
}],
186204
['OS == "win"', {
187205
'msvs_cygwin_shell': 0, # prevent actions from trying to use cygwin
188206
'defines': [

configure

+6
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ parser.add_option('--xcode',
335335
dest='use_xcode',
336336
help='generate build files for use with xcode')
337337

338+
parser.add_option('--enable-asan',
339+
action='store_true',
340+
dest='enable_asan',
341+
help='build with asan')
342+
338343
parser.add_option('--enable-static',
339344
action='store_true',
340345
dest='enable_static',
@@ -707,6 +712,7 @@ def configure_node(o):
707712
if options.linked_module:
708713
o['variables']['library_files'] = options.linked_module
709714

715+
o['variables']['asan'] = int(options.enable_asan or 0)
710716

711717
def configure_library(lib, output):
712718
shared_lib = 'shared_' + lib

src/node.cc

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
#include <string.h>
5353
#include <sys/types.h>
5454

55+
#if defined(LEAK_SANITIZER)
56+
#include <sanitizer/lsan_interface.h>
57+
#endif
58+
5559
#if defined(_MSC_VER)
5660
#include <direct.h>
5761
#include <io.h>
@@ -3967,6 +3971,10 @@ static void StartNodeInstance(void* arg) {
39673971
instance_data->set_exit_code(exit_code);
39683972
RunAtExit(env);
39693973

3974+
#if defined(LEAK_SANITIZER)
3975+
__lsan_do_leak_check();
3976+
#endif
3977+
39703978
env->Dispose();
39713979
env = nullptr;
39723980
}

test/sequential/test-child-process-emfile.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ if (common.isWindows) {
99
return;
1010
}
1111

12+
var openFds = [];
13+
1214
for (;;) {
1315
try {
14-
fs.openSync(__filename, 'r');
16+
openFds.push(fs.openSync(__filename, 'r'));
1517
} catch (err) {
1618
assert(err.code === 'EMFILE' || err.code === 'ENFILE');
1719
break;
@@ -27,3 +29,8 @@ proc.on('error', common.mustCall(function(err) {
2729

2830
// 'exit' should not be emitted, the process was never spawned.
2931
proc.on('exit', assert.fail);
32+
33+
// close one fd for LSan
34+
if (openFds.length >= 1) {
35+
fs.closeSync(openFds.pop());
36+
}

tools/lsan_suppressions.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Usage: LSAN_OPTIONS=suppressions=`pwd`/tools/lsan_suppressions.txt make check
2+
3+
# Suppress small (intentional) leaks in glibc
4+
leak:libc.so

0 commit comments

Comments
 (0)