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 \
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 and use Clang's 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 \

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` (0x00007ffc941a7000) => /lib/x86_64-linux-gnu/ (0x00007fa0a9e40000) => /lib/x86_64-linux-gnu/ (0x00007fa0a9c56000) => /lib/x86_64-linux-gnu/ (0x00007fa0a9a39000) => /usr/local/lib/ (0x00007fa0a9a06000) => /usr/lib/x86_64-linux-gnu/ (0x00007fa0a97f4000) => /usr/lib/x86_64-linux-gnu/ (0x00007fa0a9529000) => /usr/lib/x86_64-linux-gnu/ (0x00007fa0a9498000) => /usr/local/lib/ (0x00007fa0a914a000) => /usr/local/lib/ (0x00007fa0a8f24000) => /lib/x86_64-linux-gnu/ (0x00007fa0a8f1e000) => /usr/local/lib/ (0x00007fa0a8e50000) => /usr/local/lib/ (0x00007fa0a8e15000) => /lib/x86_64-linux-gnu/ (0x00007fa0a8c86000) => /lib/x86_64-linux-gnu/ (0x00007fa0a8c65000)
        /lib64/ (0x00007fa0a9e7c000) => /lib/x86_64-linux-gnu/ (0x00007fa0a8c5b000) => /lib/x86_64-linux-gnu/ (0x00007fa0a8c40000) => /usr/local/lib/ (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.