nodejs / node

Node.js JavaScript runtime βœ¨πŸ’πŸš€βœ¨
https://nodejs.org
Other
107.8k stars 29.7k forks source link

`collect2: fatal error: cannot find 'ld'` compiling v5.2.0 on Alpine Linux #4212

Closed mhart closed 8 years ago

mhart commented 8 years ago

I'm getting this error when compiling Node.js v5.2.0 on Alpine Linux 3.2. This error does not occur with any version <= v5.1.1 – including all io.js versions.

Any idea what may have changed that could cause this, or how to fix it?

You can reproduce using Docker and running alpine:3.2. The following packages have been installed:

$ apk add --update curl make gcc g++ python linux-headers paxctl libgcc libstdc++

After fetching the v5.2.0 source, here's the configure and make output:

$ ./configure --prefix=/usr
creating  ./icu_config.gypi
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'asan': 0,
                 'gas_version': '2.25',
                 'host_arch': 'x64',
                 'icu_small': 'false',
                 'node_byteorder': 'little',
                 'node_enable_v8_vtunejit': 'false',
                 'node_install_npm': 'true',
                 'node_prefix': '/usr',
                 'node_release_urlbase': '',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_lttng': 'false',
                 'node_use_openssl': 'true',
                 'node_use_perfctr': 'false',
                 'openssl_fips': '',
                 'openssl_no_asm': 0,
                 'python': '/usr/bin/python',
                 'target_arch': 'x64',
                 'uv_parent_path': '/deps/uv/',
                 'uv_use_dtrace': 'false',
                 'v8_enable_gdbjit': 0,
                 'v8_enable_i18n_support': 0,
                 'v8_no_strict_aliasing': 1,
                 'v8_optimized_debug': 0,
                 'v8_random_seed': 0,
                 'v8_use_snapshot': 'true',
                 'want_separate_host_toolset': 0}}
creating  ./config.gypi
creating  ./config.mk

$ make -j4
make -C out BUILDTYPE=Release V=1
make[1]: Entering directory '/node-v5.2.0/out'
  g++  -I../deps/gtest -I../deps/gtest/include  -pthread -Wall -Wextra -Wno-unused-parameter -m64 -Wno-missing-field-initializers -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF /node-v5.2.0/out/Release/.deps//node-v5.2.0/out/Release/obj.target/gtest/deps/gtest/src/gtest-death-test.o.d.raw   -c -o /node-v5.2.0/out/Release/obj.target/gtest/deps/gtest/src/gtest-death-test.o ../deps/gtest/src/gtest-death-test.cc
...
  rm -f /node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a && ar crs /node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a /node-v5.2.0/out/Release/obj.target/v8_nosnapshot/gen/libraries.o /node-v5.2.0/out/Release/obj.target/v8_nosnapshot/gen/code-stub-libraries.o /node-v5.2.0/out/Release/obj.target/v8_nosnapshot/gen/experimental-libraries.o /node-v5.2.0/out/Release/obj.target/v8_nosnapshot/gen/extras-libraries.o /node-v5.2.0/out/Release/obj.target/v8_nosnapshot/deps/v8/src/snapshot/snapshot-empty.o
  ln -f "/node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a" "/node-v5.2.0/out/Release/libv8_nosnapshot.a" 2>/dev/null || (rm -rf "/node-v5.2.0/out/Release/libv8_nosnapshot.a" && cp -af "/node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a" "/node-v5.2.0/out/Release/libv8_nosnapshot.a")
  g++ '-DV8_TARGET_ARCH_X64' '-DENABLE_DISASSEMBLER' -I../deps/v8  -pthread -Wall -Wextra -Wno-unused-parameter -m64 -B/node-v5.2.0/third_party/binutils/Linux_x64/Release/bin -fno-strict-aliasing -m64 -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fdata-sections -ffunction-sections -O3 -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF /node-v5.2.0/out/Release/.deps//node-v5.2.0/out/Release/obj.target/mksnapshot/deps/v8/src/snapshot/mksnapshot.o.d.raw   -c -o /node-v5.2.0/out/Release/obj.target/mksnapshot/deps/v8/src/snapshot/mksnapshot.o ../deps/v8/src/snapshot/mksnapshot.cc
  g++ -pthread -rdynamic -m64  -o /node-v5.2.0/out/Release/openssl-cli -Wl,--start-group /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/app_rand.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/apps.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/asn1pars.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ca.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ciphers.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/cms.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/crl.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/crl2p7.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dgst.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dh.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dhparam.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dsa.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dsaparam.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ec.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ecparam.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/enc.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/engine.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/errstr.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/gendh.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/gendsa.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/genpkey.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/genrsa.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/nseq.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ocsp.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/openssl.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/passwd.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkcs12.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkcs7.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkcs8.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkey.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkeyparam.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkeyutl.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/prime.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/rand.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/req.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/rsa.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/rsautl.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_cb.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_client.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_server.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_socket.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_time.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/sess_id.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/smime.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/speed.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/spkac.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/srp.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ts.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/verify.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/version.o /node-v5.2.0/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/x509.o /node-v5.2.0/out/Release/obj.target/deps/openssl/libopenssl.a -Wl,--end-group -ldl
  g++ -pthread -rdynamic -m64 -fuse-ld=gold -B/node-v5.2.0/third_party/binutils/Linux_x64/Release/bin -m64  -o /node-v5.2.0/out/Release/mksnapshot -Wl,--start-group /node-v5.2.0/out/Release/obj.target/mksnapshot/deps/v8/src/snapshot/mksnapshot.o /node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_base.a /node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a /node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_libplatform.a /node-v5.2.0/out/Release/obj.target/deps/v8/tools/gyp/libv8_libbase.a -Wl,--end-group -ldl -lrt
collect2: fatal error: cannot find 'ld'
compilation terminated.
deps/v8/tools/gyp/mksnapshot.target.mk:139: recipe for target '/node-v5.2.0/out/Release/mksnapshot' failed
make[1]: *** [/node-v5.2.0/out/Release/mksnapshot] Error 1
make[1]: Leaving directory '/node-v5.2.0/out'
Makefile:45: recipe for target 'node' failed
make: *** [node] Error 2

For comparison, here's the same output compiling v5.1.1 on the same setup:

$ ./configure --prefix=/usr
creating  ./icu_config.gypi
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'asan': 0,
                 'gas_version': '2.25',
                 'host_arch': 'x64',
                 'icu_small': 'false',
                 'node_byteorder': 'little',
                 'node_install_npm': 'true',
                 'node_prefix': '/usr',
                 'node_release_urlbase': '',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_lttng': 'false',
                 'node_use_openssl': 'true',
                 'node_use_perfctr': 'false',
                 'openssl_fips': '',
                 'openssl_no_asm': 0,
                 'python': '/usr/bin/python',
                 'target_arch': 'x64',
                 'uv_parent_path': '/deps/uv/',
                 'uv_use_dtrace': 'false',
                 'v8_enable_gdbjit': 0,
                 'v8_enable_i18n_support': 0,
                 'v8_no_strict_aliasing': 1,
                 'v8_optimized_debug': 0,
                 'v8_random_seed': 0,
                 'v8_use_snapshot': 1,
                 'want_separate_host_toolset': 0}}
creating  ./config.gypi
creating  ./config.mk

$ make -j4
make -C out BUILDTYPE=Release V=1
make[1]: Entering directory '/node-v5.1.1/out'
  g++  -I../deps/gtest -I../deps/gtest/include  -pthread -Wall -Wextra -Wno-unused-parameter -m64 -Wno-missing-field-initializers -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF /node-v5.1.1/out/Release/.deps//node-v5.1.1/out/Release/obj.target/gtest/deps/gtest/src/gtest-death-test.o.d.raw   -c -o /node-v5.1.1/out/Release/obj.target/gtest/deps/gtest/src/gtest-death-test.o ../deps/gtest/src/gtest-death-test.cc
...
  rm -f /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a && ar crs /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a /node-v5.1.1/out/Release/obj.target/v8_nosnapshot/gen/libraries.o /node-v5.1.1/out/Release/obj.target/v8_nosnapshot/gen/code-stub-libraries.o /node-v5.1.1/out/Release/obj.target/v8_nosnapshot/gen/experimental-libraries.o /node-v5.1.1/out/Release/obj.target/v8_nosnapshot/gen/extras-libraries.o /node-v5.1.1/out/Release/obj.target/v8_nosnapshot/deps/v8/src/snapshot/snapshot-empty.o
  ln -f "/node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a" "/node-v5.1.1/out/Release/libv8_nosnapshot.a" 2>/dev/null || (rm -rf "/node-v5.1.1/out/Release/libv8_nosnapshot.a" && cp -af "/node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a" "/node-v5.1.1/out/Release/libv8_nosnapshot.a")
  touch /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/v8_maybe_snapshot.stamp
  touch /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/v8.stamp
  g++ '-DGTEST_DONT_DEFINE_ASSERT_EQ=1' '-DGTEST_DONT_DEFINE_ASSERT_GE=1' '-DGTEST_DONT_DEFINE_ASSERT_GT=1' '-DGTEST_DONT_DEFINE_ASSERT_LE=1' '-DGTEST_DONT_DEFINE_ASSERT_LT=1' '-DGTEST_DONT_DEFINE_ASSERT_NE=1' -I../src -I../deps/v8/include -I../deps/gtest/include  -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF /node-v5.1.1/out/Release/.deps//node-v5.1.1/out/Release/obj.target/cctest/test/cctest/util.o.d.raw   -c -o /node-v5.1.1/out/Release/obj.target/cctest/test/cctest/util.o ../test/cctest/util.cc
  g++ -pthread -rdynamic -m64  -o /node-v5.1.1/out/Release/openssl-cli -Wl,--start-group /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/app_rand.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/apps.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/asn1pars.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ca.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ciphers.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/cms.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/crl.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/crl2p7.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dgst.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dh.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dhparam.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dsa.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/dsaparam.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ec.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ecparam.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/enc.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/engine.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/errstr.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/gendh.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/gendsa.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/genpkey.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/genrsa.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/nseq.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ocsp.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/openssl.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/passwd.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkcs12.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkcs7.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkcs8.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkey.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkeyparam.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/pkeyutl.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/prime.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/rand.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/req.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/rsa.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/rsautl.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_cb.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_client.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_server.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_socket.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/s_time.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/sess_id.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/smime.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/speed.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/spkac.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/srp.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/ts.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/verify.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/version.o /node-v5.1.1/out/Release/obj.target/openssl-cli/deps/openssl/openssl/apps/x509.o /node-v5.1.1/out/Release/obj.target/deps/openssl/libopenssl.a -Wl,--end-group -ldl
  g++ -pthread -rdynamic -m64  -o /node-v5.1.1/out/Release/cctest -Wl,--start-group /node-v5.1.1/out/Release/obj.target/cctest/test/cctest/util.o /node-v5.1.1/out/Release/obj.target/deps/gtest/libgtest.a /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_libplatform.a /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_base.a /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_libbase.a /node-v5.1.1/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a -Wl,--end-group -ldl -lrt
...
make[1]: Leaving directory '/node-v5.1.1/out'
ln -fs out/Release/node node
bnoordhuis commented 8 years ago

It's probably the -fuse-ld=gold flag. Does this patch help?

diff --git a/common.gypi b/common.gypi
index 5b8b2c0..1ebfa7c 100644
--- a/common.gypi
+++ b/common.gypi
@@ -23,6 +23,9 @@
     # Don't bake anything extra into the snapshot.
     'v8_use_external_startup_data%': 0,

+    # Don't use gold linker.
+    'linux_use_gold_flags%': 0,
+
     'conditions': [
       ['OS == "win"', {
         'os_posix': 0,
mhart commented 8 years ago

That may very well be it. Compiling now.

If so, question is – is it better to require gold linker to be installed (looks like there might be one for Alpine: https://pkgs.alpinelinux.org/package/main/x86_64/binutils-gold) – not use it at all (as your patch does) – or detect whether it's installed during the build and only use it then?

mhart commented 8 years ago

Hmmm, for some reason it's still including that flag (and failing)

After patching common.gypi I ran make clean && ./configure --prefix=/usr && make -j4

Did I need to do something else?

mhart commented 8 years ago

Now trying with the original common.gypi after installing binutils-gold

mhart commented 8 years ago

I wonder if linux_use_bundled_gold and/or linux_use_bundled_binutils are the flags to modify?

bnoordhuis commented 8 years ago

The flag is passed in deps/v8/build/toolchain.gypi based on the value of linux_use_gold_flags, which is set to 0 or 1 depending on whether we're on x86_64 linux. You may want to try modifying that file by hand.

mhart commented 8 years ago

Ok – so it just finished compiling successfully (using the original v5.2.0 source) after installing binutils-gold

I'm happy for that to be the solution for now (for me anyway) – another dependency in the build chain I guess!

Up to you whether you want to mark this as closed, or continue exploring options that don't require the gold linker as a dependency?

mscdex commented 8 years ago

FWIW I just encountered this on CentOS 6 with the compilers provided by devtoolset-2, which is a package used to provide a newer compiler.

jbergstroem commented 8 years ago

@mscdex we run the same toolset at ci for centos5/6; haven't seen this error so far.

mscdex commented 8 years ago

Follow up: using scl enable devtoolset-2 'bash' to get into a bash session that has everything set up for you allowed the compile to complete successfully.

Previously I was manually setting CC, CXX (and later LD). I guess I was missing another environment variable or something ...

jbergstroem commented 8 years ago

@mscdex or just prepend your path like we do here: 1, 2.

smebberson commented 8 years ago

@mhart, are you sure it was the original 5.2.0 source? I just tried to run your exact Dockerfile code and it fails with:

/usr/lib/gcc/x86_64-alpine-linux-musl/4.9.2/../../../../x86_64-alpine-linux-musl/bin/ld.gold: fatal error: /node-v5.2.0/out/Release/mksnapshot: Not supported
collect2: error: ld returned 1 exit status
deps/v8/tools/gyp/mksnapshot.target.mk:139: recipe for target '/node-v5.2.0/out/Release/mksnapshot' failed
make[1]: *** [/node-v5.2.0/out/Release/mksnapshot] Error 1
make[1]: Leaving directory '/node-v5.2.0/out'
Makefile:45: recipe for target 'node' failed
make: *** [node] Error 2
mhart commented 8 years ago

@smebberson Yeah, I built v5.2.0 using this exact Dockerfile and pushed it up to the Docker hub.

Also built a static version successfully using this Dockerfile and pushed it up too.

mhart commented 8 years ago

@smebberson Ah, I see you have an impressively similar Dockerfile here: https://github.com/smebberson/docker-alpine/blob/master/alpine-nodejs/Dockerfile :laughing:

Try mine as is and let me know how you go

smebberson commented 8 years ago

@mhart, I copied and pasted yours verbatim and it didn't work. I have no idea why though. I've even applied the patch (using my Dockerfile) and it still didn't build. The error message I posted above is what I received when running your exact Dockerfile.

jbergstroem commented 8 years ago

Try disabling snapshots (/.configure --without-snapshot); they might not be available on your architecture.

smebberson commented 8 years ago

@jbergstroem, that worked! Thanks.

jbergstroem commented 8 years ago

(We recently enabled this by default which is why you didn't see this earlier)

smebberson commented 8 years ago

@jbergstroem. Ah okay. I see. Well, I can confirm that I can also build it with:

hefangshi commented 8 years ago

We also encount this problem when we compile node.js 4.2.4.

What's the usage of --without-snapshot? Why we didn't have this problem in 4.2.3?

mhart commented 8 years ago

I believe compiling with --without-snapshot will make node' startup time slower because it can't take advantage of v8's snapshot feature.

hefangshi commented 8 years ago

so, could I infer that compile 4.2.4 with --without-snapshot will made node.js startup time slower than 4.2.3 ? Or, 4.2.3 didn't support snapshot feature by default?

bnoordhuis commented 8 years ago

See commit 49b3c3b, released in 4.2.4. Binaries were supposed to be built with snapshots enabled, but weren't.

The snapshot/nosnapshot performance difference is negligible for most use cases; it slows startup by perhaps 50 ms on x86.

hefangshi commented 8 years ago

@bnoordhuis Thanks;)

sjackman commented 8 years ago

I've encountered this issues as well trying to compile node on Linuxbrew. I'll try --without-snapshot workaround. Perhaps configure should check whether gold is available before trying to use it as the linker.

sjackman commented 8 years ago

The --without-snapshot workaround worked for me! https://github.com/Homebrew/linuxbrew/commit/17d7674278df0e9dc63ec0e49bf58069c604b200

jeremyd commented 8 years ago

Thanks for this! apk add binutils-gold fixed it for me. (node version 4.2.6)

bnoordhuis commented 8 years ago

I guess we can close this now. The workaround is to build with --without-snapshot or install the gold linker.

mhart commented 8 years ago

Just a follow up to this – installing binutils-gold works fine when compiling on boot2docker on my Mac, but there seem to be certain OS/architecture/platform combinations that this still doesn't work for – Docker's Automated Build environment being one of them.

The only method I've found so far that reliably works is manually editing linux_use_gold_flags% in deps/v8/build/toolchain.gypi as suggested earlier by @bnoordhuis

It looks like this change might be made permanent in #6603 ...?

mhart commented 8 years ago

It also works to set the GYP_DEFINES env variable – I had tried it with just linux_use_gold_flags=0 to no avail, but if you set it to linux_use_bundled_binutils=0 linux_use_bundled_gold=0 linux_use_gold_flags=0, then it also works – less hacky than editing toolchain.gypi in any case

mhart commented 8 years ago

Actually, turns out I was just being stupid and the problem before was that I wasn't exporting it. So, you can just do export GYP_DEFINES="linux_use_gold_flags=0" instead of editing toolchain.gypi or installing binutils-gold – that works for the Alpine Docker case anyway.