Skip to content

Cannot compile node #30180

Description

@bgnx

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

Activity

  1. added
    buildIssues and PRs related to Node.js builds or CI infrastructure.
    confirmed-bugIssues and PRs for confirmed bugs.
    i18n-apiIssues and PRs related to Node.js internationalization support.
    on Oct 30, 2019
  2. addaleax commented on Oct 30, 2019

    @addaleax
    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.

  3. addaleax commented on Oct 30, 2019

    @addaleax
    Member

    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++.

  4. addaleax commented on Oct 31, 2019

    @addaleax
    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:
  5. bgnx commented on Oct 31, 2019

    @bgnx
    Author

    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

  6. addaleax commented on Oct 31, 2019

    @addaleax
    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.

  7. emerzon commented on Jan 13, 2022

    @emerzon

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

  8. alexnagelberg commented on Feb 16, 2023

    @alexnagelberg

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

  9. bugwelle commented on Jun 22, 2023

    @bugwelle

    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

  10. YanghangZheng-GDUT commented on Nov 18, 2024

    @YanghangZheng-GDUT

    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.

  11. skyone-wzw commented on Nov 18, 2024

    @skyone-wzw

    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.

  12. YanghangZheng-GDUT commented on Nov 18, 2024

    @YanghangZheng-GDUT

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildIssues and PRs related to Node.js builds or CI infrastructure.confirmed-bugIssues and PRs for confirmed bugs.i18n-apiIssues and PRs related to Node.js internationalization support.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions