Skip to content

Commit c67bd33

Browse files
author
Gabriel Schulhof
committed
test: add duplicate symbol test
On OSX symbols are exported by default, and they overlap if two different copies of the same symbol appear in a process. This change ensures that, on OSX, symbols are hidden by default. Re: nodejs/node-addon-api#456
1 parent bb8b294 commit c67bd33

File tree

8 files changed

+123
-0
lines changed

8 files changed

+123
-0
lines changed

addon.gypi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@
9090

9191
'conditions': [
9292
[ 'OS=="mac"', {
93+
'cflags': [
94+
'-fvisibility=hidden'
95+
],
9396
'defines': [
9497
'_DARWIN_USE_64_BIT_INODE=1'
9598
],
9699
'xcode_settings': {
100+
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
97101
'DYLIB_INSTALL_NAME_BASE': '@rpath'
98102
},
99103
}],

test/node_modules/duplicate_symbols/binding.cc

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/duplicate_symbols/binding.gyp

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/duplicate_symbols/common.h

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/duplicate_symbols/extra.cc

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/duplicate_symbols/index.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/duplicate_symbols/package.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-addon.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ function runHello(hostProcess) {
1919
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
2020
}
2121

22+
function runDuplicateBindings(hostProcess) {
23+
if (!hostProcess) {
24+
hostProcess = process.execPath
25+
}
26+
var testCode =
27+
"console.log((function(bindings) {" +
28+
"return bindings.pointerCheck1(bindings.pointerCheck2());" +
29+
"})(require('duplicate_symbols')))"
30+
console.log('running ', hostProcess);
31+
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
32+
}
33+
2234
function getEncoding() {
2335
var code = 'import locale;print locale.getdefaultlocale()[1]'
2436
return execFileSync('python', ['-c', code]).toString().trim()
@@ -52,6 +64,23 @@ test('build simple addon', function (t) {
5264
proc.stderr.setEncoding('utf-8')
5365
})
5466

67+
test('make sure addon symbols do not overlap', function (t) {
68+
t.plan(3)
69+
70+
var addonPath = path.resolve(__dirname, 'node_modules', 'duplicate_symbols')
71+
// Set the loglevel otherwise the output disappears when run via 'npm test'
72+
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
73+
var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
74+
var logLines = stderr.toString().trim().split(/\r?\n/)
75+
var lastLine = logLines[logLines.length-1]
76+
t.strictEqual(err, null)
77+
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
78+
t.strictEqual(runDuplicateBindings().trim(), 'not equal')
79+
})
80+
proc.stdout.setEncoding('utf-8')
81+
proc.stderr.setEncoding('utf-8')
82+
})
83+
5584
test('build simple addon in path with non-ascii characters', function (t) {
5685
t.plan(1)
5786

0 commit comments

Comments
 (0)