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

Cannot compile node #30180

Open
bgnx opened this issue Oct 30, 2019 · 11 comments · May be fixed by #30199
Open

Cannot compile node #30180

bgnx opened this issue Oct 30, 2019 · 11 comments · May be fixed by #30199
Labels
build Issues and PRs related to build files or the CI. confirmed-bug Issues with confirmed bugs. i18n-api Issues and PRs related to the i18n implementation.

Comments

@bgnx
Copy link

bgnx commented Oct 30, 2019

Cannot compile node 13.0.1 with flags ./configure --fully-static --with-intl=full-icu inside docker image for node

Getting this output

  LD_LIBRARY_PATH=/node/out/Release/lib.host:/node/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../tools/v8_gypfiles; mkdir -p /node/out/Release/obj/gen/src/regexp; python ../../deps/v8/tools/run.py "/node/out/Release/gen-regexp-special-case" "/node/out/Release/obj/gen/src/regexp/special-case.cc"
tools/v8_gypfiles/run_gen-regexp-special-case.target.mk:13: recipe for target '/node/out/Release/obj/gen/src/regexp/special-case.cc' failed
make[1]: *** [/node/out/Release/obj/gen/src/regexp/special-case.cc] Error 245
make[1]: *** Waiting for unfinished jobs....
rm 889aa6e08bf291915b2edfb5755eacba271e7d14.intermediate
Makefile:101: recipe for target 'node' failed
make: *** [node] Error 2

Steps to reproduce:

  1. Install docker
  2. docker run -it node bash
    //inside docker shell
  3. git clone https://github.com/nodejs/node.git
  4. cd node
  5. git checkout v13.0.1
  6. ./configure --fully-static --with-intl=full-icu
  7. make -j8

Also not working with flags ./configure --fully-static --enable-static --with-intl=full-icu with the same error

But it compiles without errors with version 11.1.0 with flags ./configure --fully-static --with-intl=full-icu --download=all

@addaleax addaleax added build Issues and PRs related to build files or the CI. confirmed-bug Issues with confirmed bugs. i18n-api Issues and PRs related to the i18n implementation. labels Oct 30, 2019
@addaleax
Copy link
Member

Relevant bits of the stack trace:

#0  0x0000000000000000 in ?? ()
#1  0x0000000000538d09 in std::condition_variable::notify_all() ()
#2  0x000000000043e67b in icu_64::umtx_initImplPostInit (uio=...) at ../deps/icu-small/source/common/umutex.cpp:151

It looks like initCondition() calls out to the std::condition_variable constructor but actually returns an useless object in the end.

@addaleax
Copy link
Member

addaleax commented Oct 30, 2019

Machine code of the stdlib method in question:

0000000000538d00 <_ZNSt18condition_variable10notify_allEv>:
  538d00:       48 83 ec 08             sub    $0x8,%rsp
  538d04:       e8 f7 72 ac ff          callq  0 <_nl_current_LC_CTYPE>
  538d09:       85 c0                   test   %eax,%eax
  538d0b:       75 05                   jne    538d12 <_ZNSt18condition_variable10notify_allEv+0x12>
  538d0d:       48 83 c4 08             add    $0x8,%rsp
  538d11:       c3                      retq   
  538d12:       89 c7                   mov    %eax,%edi
  538d14:       e8 a7 e9 f9 ff          callq  4d76c0 <_ZSt20__throw_system_errori>
  538d19:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)

Obviously call 0 isn’t quite right.¹ This only happens when linking out/Debug/gen-regexp-special-case with -static.

¹ Edit: Looks like that should have been a call to pthread_cond_broadcast, according to the relocation data in my static libstdc++.

@addaleax
Copy link
Member

Tiny repro:

$ cat test.cpp 
#include <condition_variable>
int main () {
  std::condition_variable a;  a.notify_all();
}
$ g++ -g -pthread -static -Wall -o  test test.cpp && ./test
Segmentation fault (core dumped)

Googling a bit gives https://stackoverflow.com/questions/35116327/when-g-static-link-pthread-cause-segmentation-fault-why, which does not quite seem to answer why this is crashing but does provide a helpful solution.

@bgnx Can you confirm that this solves your issue?

diff --git a/configure.py b/configure.py
index 8790b3c13fcc..5f7fdb55aed9 100755
--- a/configure.py
+++ b/configure.py
@@ -1266,7 +1266,7 @@ def configure_static(o):
       return
 
     if options.fully_static:
-      o['libraries'] += ['-static']
+      o['libraries'] += ['-static', '-Wl,--whole-archive', '-lpthread', '-Wl,--no-whole-archive']
     elif options.partly_static:
       o['libraries'] += ['-static-libgcc', '-static-libstdc++']
       if options.enable_asan:

@bgnx
Copy link
Author

bgnx commented Oct 31, 2019

Yes, now it compiles without errors. Thanks! (By the way I don't understand what has caused this error - I've tested different node versions and node compiles without this error up to 12.8.1 release and starting from 12.9.0 release static compilation breaks with this error)

And little off-topic question - do I need to add --enable-static flag if I already added --fully-static flag ? I just need statically compiled node to run inside docker "FROM scratch" image and seems like in both cases (with and without --enable-static flag) I am getting executable /out/Release/node file

@addaleax
Copy link
Member

@bgnx I think --enable-static just means that it (also?) builds a static library from Node.js for embedding, in addition to the binary, but I think I might be wrong.

addaleax added a commit to addaleax/node that referenced this issue Oct 31, 2019
This resolves a crash during the build of Node.js when built
with `./configure --fully-static`.

Fixes: nodejs#30180
@addaleax addaleax linked a pull request Oct 31, 2019 that will close this issue
2 tasks
@emerzon
Copy link

emerzon commented Jan 13, 2022

Issues persist on v17.3.1. Unfortunately, the provided patch didn't solve it for me. Not present on v11.15.0.

@alexnagelberg
Copy link

Issue still exists in v18.14.0 -- I used the patch and it worked.

@bugwelle
Copy link

bugwelle commented Jun 22, 2023

Issue persists in Node v20.3.1 ( 9869bdc ). I applied the patch and it works on:

  • openSUSE Leap 15.5 with
  • clang-14
  • Python 3.6.15
  • command ./configure --fully-static --enable-static --ninja

Update 2024-04-23: Same with a2f3b1d

@YanghangZheng-GDUT
Copy link

Issue still exists in v18.14.0 -- I used the patch and it worked.

May I ask which patch you used? I have met the same problem.

@skyone-wzw
Copy link

May I ask which patch you used? I have met the same problem.

@YanghangZheng-GDUT I use

sed -i "s/'-static'/'-static', '-Wl,--whole-archive', '-lpthread', '-Wl,--no-whole-archive'/" configure.py
./configure --fully-static --enable-static

And it has been successfully compiled.

@YanghangZheng-GDUT
Copy link

Thank you so much! My question seems to be done.

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. confirmed-bug Issues with confirmed bugs. i18n-api Issues and PRs related to the i18n implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants