lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.22k stars 1.29k forks source link

Illegal hardware instruction (core dumped) #4218

Closed IgorKowalczyk closed 1 month ago

IgorKowalczyk commented 1 month ago

Possible install-time or require-time problem

Are you using the latest version of sharp?

Are you using a supported runtime?

Are you using a supported package manager and installing optional dependencies?

What is the complete error message, including the full stack trace?

$ node -e "require('sharp')"

[1]    194174 illegal hardware instruction (core dumped)  node -e "require('sharp')"

What is the complete output of running npm install --verbose --foreground-scripts sharp in an empty directory?

npm verb cli /root/.nvm/versions/node/v20.12.0/bin/node /root/.nvm/versions/node/v20.12.0/bin/npm npm info using npm@10.5.0 npm info using node@v20.12.0 npm verb title npm install sharp npm verb argv "install" "--loglevel" "verbose" "--foreground-scripts" "sharp" npm verb logfile logs-max:10 dir:/root/.npm/_logs/2024-09-21T17_31_12_646Z- npm verb logfile /root/.npm/_logs/2024-09-21T17_31_12_646Z-debug-0.log npm http fetch GET 200 https://registry.npmjs.org/sharp 481ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-arm64 150ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-x64 148ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-arm64 194ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-x64 174ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm 152ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm64 140ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-s390x 193ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-arm64 213ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-x64 117ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm 200ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm64 159ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-s390x 172ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-arm64 189ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-x64 583ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-wasm32 202ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-ia32 139ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-x64 187ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/@emnapi%2fruntime 150ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/tslib 95ms (cache revalidated) npm verb reify failed optional dependency /root/node_modules/@img/sharp-win32-x64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-win32-ia32 npm verb reify failed optional dependency /root/node_modules/@img/sharp-wasm32 npm verb reify failed optional dependency /root/node_modules/@emnapi/runtime npm verb reify failed optional dependency /root/node_modules/tslib npm verb reify failed optional dependency /root/node_modules/@img/sharp-linuxmusl-x64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-linuxmusl-arm64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-linux-s390x npm verb reify failed optional dependency /root/node_modules/@img/sharp-linux-arm64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-linux-arm npm verb reify failed optional dependency /root/node_modules/@img/sharp-libvips-linuxmusl-x64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-libvips-linuxmusl-arm64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-libvips-linux-s390x npm verb reify failed optional dependency /root/node_modules/@img/sharp-libvips-linux-arm64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-libvips-linux-arm npm verb reify failed optional dependency /root/node_modules/@img/sharp-libvips-darwin-x64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-libvips-darwin-arm64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-darwin-x64 npm verb reify failed optional dependency /root/node_modules/@img/sharp-darwin-arm64 up to date in 6s 3 packages are looking for funding run `npm fund` for details npm verb exit 0 npm info ok

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

system:    OS: Linux 6.10 Fedora Linux 39 (Cloud Edition)
CPU: (2) x64 AMD G-T56N Processor
Memory: 2.21 GB / 3.30 GB
Container: Yes
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.0 - ~/.nvm/versions/node/v20.12.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v20.12.0/bin/yarn
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.0/bin/npm
pnpm: 8.15.5 - ~/.nvm/versions/node/v20.12.0/bin/pnpm
IgorKowalczyk commented 1 month ago
$ cat /proc/cpuinfo

processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 20
model           : 2
model name      : AMD G-T56N Processor
stepping        : 0
microcode       : 0x5000101
cpu MHz         : 1646.337
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 6
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni monitor ssse3 cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch ibs skinit wdt hw_pstate vmmcall arat npt lbrv svm_lock nrip_save pausefilter
bugs            : fxsave_leak sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 3292.64
TLB size        : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

processor       : 1
vendor_id       : AuthenticAMD
cpu family      : 20
model           : 2
model name      : AMD G-T56N Processor
stepping        : 0
microcode       : 0x5000101
cpu MHz         : 1655.916
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 6
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni monitor ssse3 cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch ibs skinit wdt hw_pstate vmmcall arat npt lbrv svm_lock nrip_save pausefilter
bugs            : fxsave_leak sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 3292.64
TLB size        : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate
lovell commented 1 month ago

Please see https://github.com/lovell/sharp/issues/2723

IgorKowalczyk commented 1 month ago

I built libvips from source

$ pkg-config --modversion vips-cpp
8.15.3

and added

 “config": {
    “libvips": “8.15.3”
 }

to package.json

and still node -e “require(‘sharp’)” returns the same error.

lovell commented 1 month ago

Please see https://sharp.pixelplumbing.com/install#building-from-source and ensure all additional dependencies are made available at install time. Use the npm install --foreground-scripts flag to force npm to display all decisions being taken.

IgorKowalczyk commented 1 month ago
$ npm install --foreground-scripts
(##################) ⠦ reify:@img/sharp-libvips-linux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
> sharp@0.33.5 install
> node install/check

sharp: Detected globally-installed libvips v8.15.3nux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
sharp: Attempting to build from source via node-gyp
sharp: Found node-addon-api 8.1.0
sharp: Found node-gyp 10.2.0:@img/sharp-libvips-linux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
sharp: See https://sharp.pixelplumbing.com/install#building-from-source
gyp info it worked if it ends with okrp-libvips-linux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
gyp info using node-gyp@10.2.0
gyp info using node@20.12.0 | linux | x64
gyp info chdir src
gyp info find Python using Python version 3.12.6 found at "/usr/bin/python3"node_modules/node-gyp Completed in 3770ms
(##################) ⠦ reify:@img/sharp-libvips-linux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/root/sharp/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/root/sharp/node_modules/sharp/src/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/root/sharp/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/root/.cache/node-gyp/20.12.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/20.12.0',
gyp info spawn args '-Dnode_gyp_dir=/root/sharp/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/20.12.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/root/sharp/node_modules/sharp/src',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
<string>:114: SyntaxWarning: invalid escape sequence '\/': timing reifyNode:node_modules/node-gyp Completed in 3770ms
gyp info spawn make) ⠦ reify:@img/sharp-libvips-linux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/root/sharp/node_modules/sharp/src/build'
  CC(target) Release/obj.target/nothing/../../node-addon-api/nothing.o
rm -f Release/obj.target/../../node-addon-api/nothing.a Release/obj.target/../../node-addon-api/nothing.a.ar-file-list; mkdir -p `dirname Release/obj.target/../../node-addon-api/nothing.a`
ar crs Release/obj.target/../../node-addon-api/nothing.a @Release/obj.target/../../node-addon-api/nothing.a.ar-file-list
  COPY Release/nothing.aeify:@img/sharp-libvips-linux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp-linux-x64/common.o: timing reifyNode:node_modules/node-gyp Completed in 3770ms
  CXX(target) Release/obj.target/sharp-linux-x64/metadata.otiming reifyNode:node_modules/node-gyp Completed in 3770ms
  CXX(target) Release/obj.target/sharp-linux-x64/stats.o4: timing reifyNode:node_modules/node-gyp Completed in 3770ms
  CXX(target) Release/obj.target/sharp-linux-x64/operations.oming reifyNode:node_modules/node-gyp Completed in 3770ms
  CXX(target) Release/obj.target/sharp-linux-x64/pipeline.otiming reifyNode:node_modules/node-gyp Completed in 3770ms
  CXX(target) Release/obj.target/sharp-linux-x64/utilities.oiming reifyNode:node_modules/node-gyp Completed in 3770ms
  CXX(target) Release/obj.target/sharp-linux-x64/sharp.o4: timing reifyNode:node_modules/node-gyp Completed in 3770ms
  SOLINK_MODULE(target) Release/obj.target/sharp-linux-x64.nodeng reifyNode:node_modules/node-gyp Completed in 3770ms
  COPY Release/sharp-linux-x64.nodeharp-libvips-linux-x64: timing reifyNode:node_modules/node-gyp Completed in 3770ms
  TOUCH Release/obj.target/copy-dll.stamp
make: Leaving directory '/root/sharp/node_modules/sharp/src/build'reifyNode:node_modules/node-gyp Completed in 3770ms
gyp info ok 

added 110 packages, and audited 111 packages in 2m

17 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
$ node  -e "require('sharp')"
[1]    263242 illegal hardware instruction (core dumped)  node -e "require('sharp')"

The displayed code is different this time.

lovell commented 1 month ago

What's the output of ldd node_modules/sharp/src/build/Release/sharp-linux-x64.node?

IgorKowalczyk commented 1 month ago
        linux-vdso.so.1 (0x00007f75b0563000)
        libvips-cpp.so.42 => not found
        libvips.so.42 => not found
        libgio-2.0.so.0 => /lib64/libgio-2.0.so.0 (0x00007f75b0330000)
        libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f75b02d0000)
        libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f75b0186000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f75afe00000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f75b00a3000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f75b007e000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f75afc1e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f75b0565000)
        libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f75b0077000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f75b005d000)
        libmount.so.1 => /lib64/libmount.so.1 (0x00007f75afbcd000)
        libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f75afba0000)
        libffi.so.8 => /lib64/libffi.so.8 (0x00007f75afb90000)
        libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f75afaf5000)
        libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f75afab9000)

also

$ where vips   
/usr/local/bin/vips
$ vips --version
vips: error while loading shared libraries: libvips.so.42: cannot open shared object file: No such file or directory

It seems that the files libvips-cpp.so.42 and libvips.so.42 do not exist where they should.

IgorKowalczyk commented 1 month ago

I think the missing files are:

/usr/local/lib64/libvips.so.42.17.3
/usr/local/lib64/libvips-cpp.so.42.17.3

or in the directory where I previously installed sharp

/root/sharp/node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.42
/root/sharp/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/libvips-cpp.so.42
IgorKowalczyk commented 1 month ago

So, I copied these files:

/usr/local/lib64/libvips.so.42.17.3
/usr/local/lib64/libvips-cpp.so.42.17.3

into /lib64/keeping their original names. Nothing has changed.

Then I tried renaming them by deleting the version in the filename? E.g. libvips.so.42.17.3 -> libvips.so.42. This worked. So

$ vips --version                                               
vips-8.15.3

and

$ node -e “require(‘sharp’)”

work without any problems. So I consider the problem solved.


I also discovered one thing - pnpm very much dislikes to build sharp from the source. Despite installing node-addon-api node-gyp pnpm does not build sharp, it just installs the pre-built versions. This can be fixed by using pnpm rebuild. If I find another solution in the pnpm documentation, I will let you know about it, and I will try to improve the documentation about the installation from the source.

lovell commented 1 month ago

Rather than manually copy files around, when building libvips with Meson, its --prefix flag can be used to set the installation directory, e.g. you might want to try meson configure --prefix /usr/lib64.

IgorKowalczyk commented 1 month ago
Installing symlink pointing to libvips.so.42.17.3 to /usr/lib64/lib64/libvips.so.42
Installing symlink pointing to libvips.so.42 to /usr/lib64/lib64/libvips.so
Installing symlink pointing to libvips-cpp.so.42.17.3 to /usr/lib64/lib64/libvips-cpp.so.42
Installing symlink pointing to libvips-cpp.so.42 to /usr/lib64/lib64/libvips-cpp.so

It doesn't look very good

lovell commented 1 month ago

Sorry, I meant --prefix /usr

sacru2red commented 1 month ago

updated comment... 0.27.2 works with E5310, but not upper