Skip to content

Commit 2761afb

Browse files
Gabriel Schulhofrvagg
Gabriel Schulhof
authored andcommitted
build,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 Fixes: nodejs/node#26765 PR-URL: #1689 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent a757239 commit 2761afb

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed

addon.gypi

+4
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

+10
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

+19
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

+37
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

+6
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

+5
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

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-addon.js

+25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ function runHello(hostProcess) {
1919
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
2020
}
2121

22+
function runDuplicateBindings() {
23+
const hostProcess = process.execPath;
24+
var testCode =
25+
"console.log((function(bindings) {" +
26+
"return bindings.pointerCheck1(bindings.pointerCheck2());" +
27+
"})(require('duplicate_symbols')))"
28+
console.log('running ', hostProcess);
29+
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
30+
}
31+
2232
function getEncoding() {
2333
var code = 'import locale;print locale.getdefaultlocale()[1]'
2434
return execFileSync('python', ['-c', code]).toString().trim()
@@ -52,6 +62,21 @@ test('build simple addon', function (t) {
5262
proc.stderr.setEncoding('utf-8')
5363
})
5464

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

0 commit comments

Comments
 (0)