node icon indicating copy to clipboard operation
node copied to clipboard

Cannot compile node

Open bgnx opened this issue 6 years ago • 8 comments

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

bgnx avatar Oct 30 '19 14:10 bgnx

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 avatar Oct 30 '19 18:10 addaleax

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 avatar Oct 30 '19 18:10 addaleax

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:

addaleax avatar Oct 31 '19 11:10 addaleax

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

bgnx avatar Oct 31 '19 22:10 bgnx

@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 avatar Oct 31 '19 22:10 addaleax

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

emerzon avatar Jan 13 '22 14:01 emerzon

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

alexnagelberg avatar Feb 16 '23 21:02 alexnagelberg

Issue persists in Node v20.3.1 ( 9869bdc93d7bd8b439c4a2598607ee779483ee53 ). 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 a2f3b1df9362a694b78444b7de28878a75fcc457

bugwelle avatar Jun 22 '23 11:06 bugwelle