lovell / farmhash

Node.js implementation of FarmHash, Google's family of high performance hash functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Illegal instruction (core dumped)` on Alpine 3.8

asilvas opened this issue · comments

Related to lovell/sharp-libvips#13 (by mistake, closing the other issue).

Was able to repro:

node -e "require('farmhash').hash32('sdflkjsdf')"

The most puzzling thing is why all the sudden this is happening.

Verified performing an npm rebuild farmhash resolved. Probably more of an issue from my end as to why different instruction sets are supported between the docker build environment and the release environment. But i'd at least like to better understand the exact difference and perhaps the pre-built could work around the issue?

For this issue, we used the pre-compiled binaries and the server had SSE4.2 cpu flag. Here are the flags when comparing a working server and non-working server:

  • flags missing on broken server: fma movbe abm bmi1 avx2 bmi2 invpcid
  • additional flags on broken server: stibp intel_stibp

Prebuilt binaries are not currently provided for musl-based Linux such as Alpine.

If the build host and runtime target differ you can specify the target architecture at compile time:

CXXFLAGS="-march=ivybridge" npm install

I suspect you have just started using build servers with support for AVX2 intrinsics.

Your help and insight is much appreciated, @lovell! Running your recommendation on the host seems to work, however when run from our build slaves via Docker it does not seem to produce the same binaries. No luck determining why the delta. Please advise if you have any ideas.

RUN CXXFLAGS="-march=ivybridge" NODE_ENV=production SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm i --no-optional --no-save --only=prod --build-from-source

Yet running from within the container on the "bad" host, this resolves the Illegal instruction problem:

CXXFLAGS="-march=ivybridge" npm rebuild farmhash

Appears to be an ordering of instructions problem since the default config already supplies -march=native. Going the route of only adding opt-out instructions (ala -mno-avx2 -mno-bmi2) seems to do the trick so far.

I'll close this topic for now, but perhaps others will find it of use. Thanks again.