Skip to content

Commit

Permalink
test: add duplicate symbol test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Gabriel Schulhof authored and rvagg committed Jun 20, 2019
1 parent 1cfdb28 commit 34d22b7
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addon.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@

'conditions': [
[ 'OS=="mac"', {
'cflags': [
'-fvisibility=hidden'
],
'defines': [
'_DARWIN_USE_64_BIT_INODE=1'
],
'xcode_settings': {
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
'DYLIB_INSTALL_NAME_BASE': '@rpath'
},
}],
Expand Down
10 changes: 10 additions & 0 deletions test/node_modules/duplicate_symbols/binding.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/node_modules/duplicate_symbols/binding.gyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions test/node_modules/duplicate_symbols/common.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/node_modules/duplicate_symbols/extra.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/node_modules/duplicate_symbols/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/node_modules/duplicate_symbols/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions test/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ function runHello(hostProcess) {
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
}

function runDuplicateBindings() {
const hostProcess = process.execPath;
var testCode =
"console.log((function(bindings) {" +
"return bindings.pointerCheck1(bindings.pointerCheck2());" +
"})(require('duplicate_symbols')))"
console.log('running ', hostProcess);
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
}

function getEncoding() {
var code = 'import locale;print locale.getdefaultlocale()[1]'
return execFileSync('python', ['-c', code]).toString().trim()
Expand Down Expand Up @@ -52,6 +62,21 @@ test('build simple addon', function (t) {
proc.stderr.setEncoding('utf-8')
})

test('make sure addon symbols do not overlap', function (t) {
t.plan(3)

var addonPath = path.resolve(__dirname, 'node_modules', 'duplicate_symbols')
// Set the loglevel otherwise the output disappears when run via 'npm test'
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
execFile(process.execPath, cmd, function (err, stdout, stderr) {
var logLines = stderr.trim().split(/\r?\n/)
var lastLine = logLines[logLines.length-1]
t.strictEqual(err, null)
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
t.strictEqual(runDuplicateBindings().trim(), 'not equal')
})
})

test('build simple addon in path with non-ascii characters', function (t) {
t.plan(1)

Expand Down

0 comments on commit 34d22b7

Please sign in to comment.