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

Problem with loading native modules which built with --release #362

Closed
katyo opened this issue Sep 29, 2018 · 3 comments
Closed

Problem with loading native modules which built with --release #362

katyo opened this issue Sep 29, 2018 · 3 comments

Comments

@katyo
Copy link
Contributor

katyo commented Sep 29, 2018

The neon build --release produces broken NodeJS native modules:

Error: Module did not self-register.
    at Object.Module._extensions..node (module.js:681:18)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
...

I understand, this is possibly a Cargo/Rust problem related to inapproppriate config.
Experimentally I found that it actual for all opt-level's > 0
But I don't know a proper solution.

@katyo
Copy link
Contributor Author

katyo commented Sep 30, 2018

Link to rust issue rust-lang/rust#54691

@katyo
Copy link
Contributor Author

katyo commented Oct 1, 2018

I found temporary workaround.

  1. Add init function which calls __LOAD_NEON_MODULE itself:
#[no_mangle]
pub extern "C" fn node_addon_init() {
    __LOAD_NEON_MODULE();
}

register_module!(mut cx, {
  // your module code
}

The no_mangle directive is important.

  1. Fix "install" script in package.json:
"scripts": {
    "install": "RUSTFLAGS='-C link-arg=-Wl,-init=node_addon_init' neon build --release",
  },

This solution uses ".init" section instead of ".ctors"/".init_array".
Of course, I tested this on linux only.

See https://github.com/katyo/ledb/tree/master/ledb-node

katyo added a commit to katyo/ledb that referenced this issue Oct 1, 2018
katyo added a commit to katyo/neon that referenced this issue Jan 28, 2019
During link-time optimization (particularly when you build with --release)
linker removes unused static symbol `__LOAD_NEON_MODULE`.

I forced it to be used to avoid such incorrect behavior.
dherman added a commit that referenced this issue Mar 9, 2019
@kjvalencik
Copy link
Member

This was fixed in #392.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants