wiki:Tools/Node

NodeJS

NodeJS is a compiler and runtime for Javascript. It is crap, but we have no choice. This world belongs to idiots. Look at Babel for a short overview.

So, there is how to cope with it.

rebuild all C++ dependencies with clang++ and optimizations for your CPU -march=native -mtune=native

export CC=clang
export CXX=clang++
export LD=ld.lld

with -std=c++1y standard, -fno-rtti -fno-exceptions native optimizations and -flto

export CXXFLAGS="-Wformat -Wformat-security -Werror=format-security \
    -fstack-protector-strong -fstack-protector-all --param ssp-buffer-size=4 \
    -fno-strict-aliasing -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
    -std=c++1y -stdlib=libc++ \
    -fno-rtti -fno-exceptions \
    -ffunction-sections -fdata-sections \
    -m64 -march=native -mtune=native -O3 \
    -fPIC \
    -flto \
    -I/usr/local/include"
export CXXLDFLAGS="-L/usr/local/lib \
    -rtlib=compiler-rt -stdlib=libc++ \
    -fPIC \
    -flto \
    -pthread \
    -lgcc_s \ 
    -Wl,--gc-sections -Wl,-as-needed \
    -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"

This setup will ensure that we do not link with GNU libstdc++.so.6 and use Clang's libc++.so instead. This is a big deal.

cd node
git checkout v11.7.0   # or whatever it is
./configure --prefix=/usr/local \
    --with-intl=system-icu \
    --shared-openssl \
    --shared-zlib \
    --shared-cares \
    --shared-libuv \
    --ninja

add the following to the config.gypi

'cflags': '-stdlib=libc++ -flto',

'libs': '-stdlib=libc++ -rtlib=compiler-rt -flo'
make -s -j4 all

You should get something like this:

schiptsov@ideapad:~$ ldd `which node`
        linux-vdso.so.1 (0x00007ffc941a7000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa0a9e40000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa0a9c56000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fa0a9a39000)
        libuv.so.1 => /usr/local/lib/libuv.so.1 (0x00007fa0a9a06000)
        libcares.so.2 => /usr/lib/x86_64-linux-gnu/libcares.so.2 (0x00007fa0a97f4000)
        libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fa0a9529000)
        libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007fa0a9498000)
        libicui18n.so.63 => /usr/local/lib/libicui18n.so.63 (0x00007fa0a914a000)
        libicuuc.so.63 => /usr/local/lib/libicuuc.so.63 (0x00007fa0a8f24000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa0a8f1e000)
        libc++.so.1 => /usr/local/lib/libc++.so.1 (0x00007fa0a8e50000)
        libc++abi.so.1 => /usr/local/lib/libc++abi.so.1 (0x00007fa0a8e15000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa0a8c86000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa0a8c65000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa0a9e7c000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa0a8c5b000)
        libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fa0a8c40000)
        libicudata.so.63 => /usr/local/lib/libicudata.so.63 (0x00007fa0a7252000)

see also Babel, Webpack, Eslint, Flow, React

Last modified 13 months ago Last modified on Jan 19, 2019, 5:27:23 AM
Note: See TracWiki for help on using the wiki.