mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
build: add --enable-asan with builtin leakcheck
PR-URL: https://github.com/nodejs/node/pull/2376 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
32037b78a2
commit
6ed0603fb1
5 changed files with 46 additions and 3 deletions
22
common.gypi
22
common.gypi
|
@ -173,16 +173,34 @@
|
||||||
},
|
},
|
||||||
'msvs_disabled_warnings': [4351, 4355, 4800],
|
'msvs_disabled_warnings': [4351, 4355, 4800],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['asan != 0', {
|
['asan == 1 and OS != "mac"', {
|
||||||
'cflags+': [
|
'cflags+': [
|
||||||
'-fno-omit-frame-pointer',
|
'-fno-omit-frame-pointer',
|
||||||
'-fsanitize=address',
|
'-fsanitize=address',
|
||||||
'-w', # http://crbug.com/162783
|
'-DLEAK_SANITIZER'
|
||||||
],
|
],
|
||||||
'cflags_cc+': [ '-gline-tables-only' ],
|
'cflags_cc+': [ '-gline-tables-only' ],
|
||||||
'cflags!': [ '-fomit-frame-pointer' ],
|
'cflags!': [ '-fomit-frame-pointer' ],
|
||||||
'ldflags': [ '-fsanitize=address' ],
|
'ldflags': [ '-fsanitize=address' ],
|
||||||
}],
|
}],
|
||||||
|
['asan == 1 and OS == "mac"', {
|
||||||
|
'xcode_settings': {
|
||||||
|
'OTHER_CFLAGS+': [
|
||||||
|
'-fno-omit-frame-pointer',
|
||||||
|
'-gline-tables-only',
|
||||||
|
'-fsanitize=address',
|
||||||
|
'-DLEAK_SANITIZER'
|
||||||
|
],
|
||||||
|
'OTHER_CFLAGS!': [
|
||||||
|
'-fomit-frame-pointer',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
'target_conditions': [
|
||||||
|
['_type!="static_library"', {
|
||||||
|
'xcode_settings': {'OTHER_LDFLAGS': ['-fsanitize=address']},
|
||||||
|
}],
|
||||||
|
],
|
||||||
|
}],
|
||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
'msvs_cygwin_shell': 0, # prevent actions from trying to use cygwin
|
'msvs_cygwin_shell': 0, # prevent actions from trying to use cygwin
|
||||||
'defines': [
|
'defines': [
|
||||||
|
|
6
configure
vendored
6
configure
vendored
|
@ -335,6 +335,11 @@ parser.add_option('--xcode',
|
||||||
dest='use_xcode',
|
dest='use_xcode',
|
||||||
help='generate build files for use with xcode')
|
help='generate build files for use with xcode')
|
||||||
|
|
||||||
|
parser.add_option('--enable-asan',
|
||||||
|
action='store_true',
|
||||||
|
dest='enable_asan',
|
||||||
|
help='build with asan')
|
||||||
|
|
||||||
parser.add_option('--enable-static',
|
parser.add_option('--enable-static',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='enable_static',
|
dest='enable_static',
|
||||||
|
@ -707,6 +712,7 @@ def configure_node(o):
|
||||||
if options.linked_module:
|
if options.linked_module:
|
||||||
o['variables']['library_files'] = options.linked_module
|
o['variables']['library_files'] = options.linked_module
|
||||||
|
|
||||||
|
o['variables']['asan'] = int(options.enable_asan or 0)
|
||||||
|
|
||||||
def configure_library(lib, output):
|
def configure_library(lib, output):
|
||||||
shared_lib = 'shared_' + lib
|
shared_lib = 'shared_' + lib
|
||||||
|
|
|
@ -52,6 +52,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#if defined(LEAK_SANITIZER)
|
||||||
|
#include <sanitizer/lsan_interface.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
@ -3967,6 +3971,10 @@ static void StartNodeInstance(void* arg) {
|
||||||
instance_data->set_exit_code(exit_code);
|
instance_data->set_exit_code(exit_code);
|
||||||
RunAtExit(env);
|
RunAtExit(env);
|
||||||
|
|
||||||
|
#if defined(LEAK_SANITIZER)
|
||||||
|
__lsan_do_leak_check();
|
||||||
|
#endif
|
||||||
|
|
||||||
env->Dispose();
|
env->Dispose();
|
||||||
env = nullptr;
|
env = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,11 @@ if (common.isWindows) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var openFds = [];
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
try {
|
try {
|
||||||
fs.openSync(__filename, 'r');
|
openFds.push(fs.openSync(__filename, 'r'));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert(err.code === 'EMFILE' || err.code === 'ENFILE');
|
assert(err.code === 'EMFILE' || err.code === 'ENFILE');
|
||||||
break;
|
break;
|
||||||
|
@ -27,3 +29,8 @@ proc.on('error', common.mustCall(function(err) {
|
||||||
|
|
||||||
// 'exit' should not be emitted, the process was never spawned.
|
// 'exit' should not be emitted, the process was never spawned.
|
||||||
proc.on('exit', assert.fail);
|
proc.on('exit', assert.fail);
|
||||||
|
|
||||||
|
// close one fd for LSan
|
||||||
|
if (openFds.length >= 1) {
|
||||||
|
fs.closeSync(openFds.pop());
|
||||||
|
}
|
||||||
|
|
4
tools/lsan_suppressions.txt
Normal file
4
tools/lsan_suppressions.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Usage: LSAN_OPTIONS=suppressions=`pwd`/tools/lsan_suppressions.txt make check
|
||||||
|
|
||||||
|
# Suppress small (intentional) leaks in glibc
|
||||||
|
leak:libc.so
|
Loading…
Add table
Add a link
Reference in a new issue