Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api: make more symbols local #16234

Closed

Conversation

gabrielschulhof
Copy link
Contributor

  • namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
    become part of Node's public symbols unless they are declared static.
  • the class uvimpl::Work needs to be enclosed in an anonymous namespace
    else it, too becomes part of Node's public symbols.
  • allow NAPI_EXTERN to be defined on the compiler's command line.
  • remove references to EXTERNAL_NAPI.
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

n-api

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Oct 16, 2017
@gabrielschulhof
Copy link
Contributor Author

@addaleax I actually realized that most of the problems can be fixed with static and with an anonymous namespace around uvimpl::Work. We can cherry-pick this commit into node-addon-api without grabbing the one that introduces the new V8 InstanceOf API, and we should be golden, even between 8.0.0 and 8.6.0.

@gabrielschulhof
Copy link
Contributor Author

gabrielschulhof commented Oct 16, 2017

@addaleax actually, we need one more delta: that we always call node::node_module_register() with the version set to NODE_MODULE_VERSION rather than -1. That is, in Node.js we should always set it to -1, whereas in node-addon-api we should always set it to NODE_MODULE_VERSION. The delta is growing...

@gabrielschulhof gabrielschulhof force-pushed the napi-extern-hidden branch 2 times, most recently from 6334156 to 5cbe2ec Compare October 16, 2017 14:01
@mhdawson mhdawson added the node-api Issues and PRs related to the Node-API. label Oct 16, 2017
Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/node_api.h Outdated
#ifdef EXTERNAL_NAPI
// Building external N-API, or native module against external N-API
#define NAPI_EXTERN /* nothing */
#ifndef NAPI_EXTERN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point of letting users override it. The definition needs to reflect how node_api.cc is compiled, otherwise linking won't work. You can't override NODE_EXTERN, UV_EXTERN or V8_EXPORT either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it helps us out in node-addon-api by letting us do this:

      'conditions': [
        [ "OS=='win'", {
          'defines': ['NAPI_EXTERN=']
        }, {
          'defines': ['NAPI_EXTERN=__attribute__((visibility("hidden")))']
        } ]
      ]

to prevent conflicts with Node.js between versions >= 8.0.0 and < 8.6.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... where both node-addon-api and Node.js provide the same symbols, but node-addon-api's symbols must be preferred.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's the wrong way to go about it. The right way is to fix the node-addon-api build so that the symbols from the static library are searched before symbols from the node binary.

This is in the context of nodejs/node-addon-api#142, right? If you look at the nm -C gist you posted, there are a lot of n-api symbols in there that are weak (W) when they shouldn't be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, those symbols belong to the C++ wrapper, and none of them overlap with Node.js. None of the symbols which overlap with Node.js are weak.

I could find no way to cause the symbols from the static library to be searched before the symbols from Node.js, because without this change they are both declared with default visibility. In fact, visibility hidden is explicitly designed to indicate that, although the symbols are declared global because they have to be in different compilation units, they are not intended for consumption outside the .so and are thus to be treated, in a way, as static.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, NM. I managed to get -fvisibility=hidden to work for node-addon-api. I guess you re-motivated me to try again :) Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those symbols belong to the C++ wrapper, and none of them overlap with Node.js

Still, they probably shouldn't be weak. Different versions might clash and, if nothing else, it means the dynamic linker has to do more work when the module is loaded. Might be worth adding a regression test for in node-addon-api.

* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
  become part of Node's public symbols unless they are declared static.
* the class uvimpl::Work needs to be enclosed in an anonymous namespace
  else it, too becomes part of Node's public symbols.
* remove references to EXTERNAL_NAPI.
@gabrielschulhof
Copy link
Contributor Author

@gabrielschulhof
Copy link
Contributor Author

Not sure if https://ci.nodejs.org/job/node-test-commit-aix/9461/ is related. @mhdawson?

@gabrielschulhof
Copy link
Contributor Author

@gabrielschulhof
Copy link
Contributor Author

The ARM failures are also unrelated.

@mhdawson
Copy link
Member

@gabrielschulhof the AIX failure is not related, I had modified the config and temporarily broken the job.

gabrielschulhof pushed a commit that referenced this pull request Oct 19, 2017
* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
  become part of Node's public symbols unless they are declared static.
* the class uvimpl::Work needs to be enclosed in an anonymous namespace
  else it, too becomes part of Node's public symbols.
* remove references to EXTERNAL_NAPI.

PR-URL: #16234
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@gabrielschulhof gabrielschulhof deleted the napi-extern-hidden branch October 19, 2017 06:58
@gabrielschulhof
Copy link
Contributor Author

Landed in 7be4a84.

MylesBorins pushed a commit that referenced this pull request Oct 23, 2017
* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
  become part of Node's public symbols unless they are declared static.
* the class uvimpl::Work needs to be enclosed in an anonymous namespace
  else it, too becomes part of Node's public symbols.
* remove references to EXTERNAL_NAPI.

PR-URL: #16234
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
  become part of Node's public symbols unless they are declared static.
* the class uvimpl::Work needs to be enclosed in an anonymous namespace
  else it, too becomes part of Node's public symbols.
* remove references to EXTERNAL_NAPI.

PR-URL: nodejs/node#16234
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
  become part of Node's public symbols unless they are declared static.
* the class uvimpl::Work needs to be enclosed in an anonymous namespace
  else it, too becomes part of Node's public symbols.
* remove references to EXTERNAL_NAPI.

PR-URL: nodejs/node#16234
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 16, 2018
* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
  become part of Node's public symbols unless they are declared static.
* the class uvimpl::Work needs to be enclosed in an anonymous namespace
  else it, too becomes part of Node's public symbols.
* remove references to EXTERNAL_NAPI.

PR-URL: nodejs#16234
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope
  become part of Node's public symbols unless they are declared static.
* the class uvimpl::Work needs to be enclosed in an anonymous namespace
  else it, too becomes part of Node's public symbols.
* remove references to EXTERNAL_NAPI.

Backport-PR-URL: #19447
PR-URL: #16234
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants