laverdet / isolated-vm

Secure & isolated JS environments for nodejs
ISC License
2.2k stars 154 forks source link

Compilation fails on Ubuntu Xenial: `error: result of 'operator->()' yields non-pointer result` #373

Closed aramprice closed 1 year ago

aramprice commented 1 year ago

The issue https://github.com/laverdet/isolated-vm/issues/118 seems possibly related though the errors are coming from a different source file in this case.

Error messages:

npm ERR! ../src/isolate/environment.cc:34:0: warning: "_GNU_SOURCE" redefined
npm ERR!  #define _GNU_SOURCE
npm ERR!  ^
npm ERR! <command-line>:0:0: note: this is the location of the previous definition
npm ERR! In file included from ../src/module/context_handle.cc:1:0:
npm ERR! ../src/isolate/run_with_timeout.h: In lambda function:
npm ERR! ../src/isolate/run_with_timeout.h:91:36: error: result of 'operator->()' yields non-pointer result
npm ERR!        auto lock = isolate.scheduler->Lock();
npm ERR!                                     ^
npm ERR! ../src/isolate/run_with_timeout.h:96:37: error: result of 'operator->()' yields non-pointer result
npm ERR!         auto lock = isolate.scheduler->Lock();
npm ERR!                                      ^
npm ERR! make: *** [Release/obj.target/isolated_vm/src/module/context_handle.o] Error 1
npm ERR! make: *** Waiting for unfinished jobs....
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2

Reproduction steps:

docker run -it ubuntu:xenial /bin/bash

Within the docker container run the following:

apt update
apt -y install \
  apt-transport-https \
  lsb-release \
  build-essential \
  curl \
  g++ \
  git-core \
  libbz2-dev \
  libcurl4-openssl-dev \
  liblzma-dev \
  libncurses-dev \
  libreadline-dev \
  libssl-dev \
  libsqlite3-dev \
  libxml2-dev

curl -sL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash -
export PYENV_ROOT="$HOME/.pyenv" PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv install 3.6
pyenv virtualenv 3.6 general
pyenv global general

curl -sL https://deb.nodesource.com/setup_16.x | bash -
apt install -y nodejs

npm install -g --verbose isolated-vm

Full output from npm install -g isolated-vm

npm install -g isolated-vm
npm ERR! code 1
npm ERR! path /usr/lib/node_modules/isolated-vm
npm ERR! command failed
npm ERR! command sh -c -- node-gyp rebuild --release -j 4
npm ERR! make: Entering directory '/usr/lib/node_modules/isolated-vm/build'
npm ERR!   CXX(target) Release/obj.target/nortti/src/external_copy/serializer_nortti.o
npm ERR!   CXX(target) Release/obj.target/nortti/src/isolate/allocator_nortti.o
npm ERR!   AR(target) Release/obj.target/nortti.a
npm ERR!   COPY Release/nortti.a
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/external_copy/external_copy.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/external_copy/serializer.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/external_copy/string.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/environment.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/cpu_profile_manager.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/executor.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/holder.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/inspector.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/platform_delegate.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/scheduler.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/stack_trace.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/isolate/three_phase_task.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/lib/thread_pool.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/lib/timer.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/module/callback.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/module/context_handle.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/module/evaluation.o
npm ERR!   CXX(target) Release/obj.target/isolated_vm/src/module/external_copy_handle.o
npm ERR! isolated_vm.target.mk:192: recipe for target 'Release/obj.target/isolated_vm/src/module/context_handle.o' failed
npm ERR! make: Leaving directory '/usr/lib/node_modules/isolated-vm/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.1.0
npm ERR! gyp info using node@16.19.1 | linux | x64
npm ERR! gyp info find Python using Python version 3.6.15 found at "/root/.pyenv/versions/general/bin/python3"
npm ERR! gyp info spawn /root/.pyenv/versions/general/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/lib/node_modules/isolated-vm/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/root/.cache/node-gyp/16.19.1/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/16.19.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/16.19.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/usr/lib/node_modules/isolated-vm',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 4 ]
npm ERR! ../src/isolate/environment.cc:34:0: warning: "_GNU_SOURCE" redefined
npm ERR!  #define _GNU_SOURCE
npm ERR!  ^
npm ERR! <command-line>:0:0: note: this is the location of the previous definition
npm ERR! In file included from ../src/module/context_handle.cc:1:0:
npm ERR! ../src/isolate/run_with_timeout.h: In lambda function:
npm ERR! ../src/isolate/run_with_timeout.h:91:36: error: result of 'operator->()' yields non-pointer result
npm ERR!        auto lock = isolate.scheduler->Lock();
npm ERR!                                     ^
npm ERR! ../src/isolate/run_with_timeout.h:96:37: error: result of 'operator->()' yields non-pointer result
npm ERR!         auto lock = isolate.scheduler->Lock();
npm ERR!                                      ^
npm ERR! make: *** [Release/obj.target/isolated_vm/src/module/context_handle.o] Error 1
npm ERR! make: *** Waiting for unfinished jobs....
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:201:23)
[2023-07-19T22_18_12_678Z-debug-0.log](https://github.com/laverdet/isolated-vm/files/12100534/2023-07-19T22_18_12_678Z-debug-0.log)

npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm ERR! gyp ERR! System Linux 6.1.32-0-virt
npm ERR! gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--release" "-j" "4"
npm ERR! gyp ERR! cwd /usr/lib/node_modules/isolated-vm
npm ERR! gyp ERR! node -v v16.19.1
npm ERR! gyp ERR! node-gyp -v v9.1.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-07-19T22_17_23_761Z-debug-0.log

Attached file is the output of npm install -g --verbose isolated-vm

System info:

# gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# ldd --version
ldd (Ubuntu GLIBC 2.23-0ubuntu11.3) 2.23
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

# npm --version
8.19.3

# node --version
v16.19.1

# python --version
Python 3.6.15

# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.7 LTS"
aramprice commented 1 year ago

Installing on ubuntu:jammy succeeds with the following setup:

docker run -it ubuntu:jammy /bin/bash

Note: python is installed via apt rather than using pyenv since Jammy packages have a modern Python.

apt update \
&& apt -y install \
  apt-transport-https \
  lsb-release \
  build-essential \
  curl \
  g++ \
  git-core \
  libbz2-dev \
  libcurl4-openssl-dev \
  liblzma-dev \
  libncurses-dev \
  libreadline-dev \
  libssl-dev \
  libsqlite3-dev \
  libxml2-dev \
  python3 \
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt install -y nodejs \
&& npm install -g --verbose isolated-vm
laverdet commented 1 year ago

I took a stab at this and couldn't get this fixed. GCC 5.4 is ancient. #366 might help.

aramprice commented 1 year ago

@laverdet thank you for taking a look, I'll check out #366