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

Link issue with static library of nodejs #27431

Closed
wolfviking0 opened this issue Apr 26, 2019 · 9 comments
Closed

Link issue with static library of nodejs #27431

wolfviking0 opened this issue Apr 26, 2019 · 9 comments
Assignees
Labels
build Issues and PRs related to build files or the CI. regression Issues related to regressions.

Comments

@wolfviking0
Copy link

Hello, I want to use nodejs with swig. In order to do that I need to link my library with node.
But I cannot build shared library for nodejs only static (it's a requirement). So I build node js using this config ./configure --prefix=${NODEJS_INSTALL} --enable-static
So far everything build fine and smoothly, but when I link I have some missing symbol related to cache:

"node::native_module::has_code_cache"
"node::native_module::NativeModuleEnv::InitializeCodeCache()"

I am not sure what I am doing wrong, it seems this file can be autogenerated but not sure why is missing. I also try using whole archive when linking but change nothing.

Any thought ?

  • Version: v12.0.0
  • Platform: OSX

LINK ERROR :

Undefined symbols for architecture x86_64:
"node::native_module::has_code_cache", referenced from:
node::Initialize(v8::Localv8::Object, v8::Localv8::Value, v8::Localv8::Context) in libnode.a(node_config.o)
"node::native_module::NativeModuleEnv::InitializeCodeCache()", referenced from:
node::InitializeNodeWithArgs(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > >*) in libnode.a(node.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

@Cian-Chambliss
Copy link

I am running into the same error attempting to build with the dll option.

  • Version: v12.0.0
  • Platform: Windows x86

this occurs after running

vcbuild dll x86

@refack
Copy link
Contributor

refack commented Apr 27, 2019

So far everything build fine and smoothly, but when I link I have some missing symbol related to cache:

"node::native_module::has_code_cache"
"node::native_module::NativeModuleEnv::InitializeCodeCache()"

Hello @wolfviking0 and @Cian-Chambliss, this is probably a bug (regression) introduced in #27161. Up until that change we used to link the code-cache symbols into the intermediary libnode target. But now we only link those into the final binary product.

I'm working on a fix.

@refack refack self-assigned this Apr 27, 2019
@refack refack added build Issues and PRs related to build files or the CI. regression Issues related to regressions. labels Apr 27, 2019
@refack
Copy link
Contributor

refack commented Apr 27, 2019

P.S. as a workaround you could link your final binary with either the code cache stub (src/node_code_cache_stub.cc) or the full generated one (<(SHARED_INTERMEDIATE_DIR)/node_code_cache.cc)

@wolfviking0
Copy link
Author

@refack thanks, I used this approach initially in order to link, but because I am using node with swig I need to revert back to an older version of nodejs 10.15.3.
This version works fine.

@Cian-Chambliss
Copy link

Thanks, adding node_code_cache.cc as you suggested to the nodelib.vcxproj fixed that project.

@jeroen
Copy link
Contributor

jeroen commented Jun 12, 2019

Seeing the same linking errors with libnode (12.1.0) which is now in the Debian experimental branch.

Here the error appears when external software (in this case r-cran-v8) links to libnode.so. Hence the bug is not limited to static libraries as the topic suggests, but to anything trying to link to libnode that is not nodejs itself.

@QuLogic
Copy link

QuLogic commented Jun 21, 2019

Also failing on Fedora Rawhide with R-V8, similarly to @jeroen on Debian, but using 12.4.0 (though I understand with this still being open, it's not been fixed yet.)

@jeroen
Copy link
Contributor

jeroen commented Jul 26, 2019

Is there anyone who can take a look at this? This is blocking node 12 on Fedora and Debian now.

@jeroen
Copy link
Contributor

jeroen commented Jul 29, 2019

@joyeecheung I tried to patch this but I realized we probably need to fix this:

node/node.gyp

Lines 1161 to 1166 in 62a809f

# TODO(joyeecheung): do not depend on node_lib,
# instead create a smaller static library node_lib_base that does
# just enough for node_native_module.cc and the cache builder to
# compile without compiling the generated code cache C++ file.
# So generate_code_cache -> mkcodecache -> node_lib_base,
# node_lib -> node_lib_base & generate_code_cache

The reason why the shared library is currently missing the code cache symbols is because of the cyclical dependency between libnode and mkcodecache in node.gyp.

We need mkcodecache to generate the cache symbols, but currently mkcodecache depends on libnode so we cannot include the generated symbols to libnode.

The solution is exactly as said in the comment above: modify the mkcodecache build such that it does not depend on the full libnode, but instead on a smaller libnode_base which suffices to generate the cache symbols. And then we can add those symbols when building the real libnode in a later step.

@Trott Trott closed this as completed in ed138ba Aug 1, 2019
targos pushed a commit that referenced this issue Aug 2, 2019
This is needed for external applications that link to shared libnode.
Fixes #27431

PR-URL: #28897
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. regression Issues related to regressions.
Projects
None yet
5 participants