Skip to content

Commit

Permalink
nodejs: use PIE for host binaries
Browse files Browse the repository at this point in the history
* mksnapshot is built as host binary, but then gets executed under
  qemu-arm, because for 32bit target we need to run 32bit mksnapshot
  even when building on x86-64 host

* unfortunately since upgrade to qemu-8 in:
  https://git.openembedded.org/openembedded-core/commit/?id=fe8125565af07b73f9b29db2188ecb6e884bcc70

  the mksnapshot fails to execute with:
  LD_LIBRARY_PATH=/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/lib.host:/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../tools/v8_gypfiles; mkdir -p /OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/obj.target/v8_snapshot/geni; "/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/v8-qemu-wrapper.sh" "/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/mksnapshot" --turbo_instruction_scheduling "--target_os=linux" "--target_arch=arm" --startup_src "/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/obj.target/v8_snapshot/geni/snapshot.cc" --embedded_variant Default --embedded_src "/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/obj.target/v8_snapshot/geni/embedded.S" --no-native-code-counters

  #
  # Fatal process OOM in Failed to reserve virtual memory for CodeRange
  #

  /OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/node-v18.16.0/out/Release/v8-qemu-wrapper.sh: line 7: 669880 Trace/breakpoint trap   (core dumped) PSEUDO_UNLOAD=1 qemu-arm -r 5.15 -L /OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/recipe-sysroot -E LD_LIBRARY_PATH=/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/recipe-sysroot/usr/lib:/OE/build/oe-core/tmp-glibc/work/cortexa8t2hf-neon-oe-linux-gnueabi/nodejs/18.16.0-r0/recipe-sysroot/lib "$@"

  It was failing only in some of my builds first, in the end
  I was able to narrow the difference between the build where
  it fails and where it doesn't fail to
  require conf/distro/include/security_flags.inc
  then
  GCCPIE = "--enable-default-pie"
  and lastly this PIE enabled just for nodejs to work around
  this issue without downgrading qemu-native.

* using -strace with qemu doesn't help much, just confirms that
  the OOM error message is really caused by failed mmap2:

  --- SIGPROF {si_signo=SIGPROF, si_code=SI_TKILL, si_pid=2908258, si_uid=1026} ---
  clock_gettime64(CLOCK_MONOTONIC,0x407ef640) = 0 ({tv_sec=20187,tv_nsec=678404286})
  rt_sigreturn(0x407efb70) = -1 errno=513 (Successful exit from sigreturn)
  write(3,0x141e538,28) = 28
  write(3,0x141e538,28) = 28
  write(3,0x141e538,32) = 32
  mmap2(0x0097a000,33554432,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,-1,0) = -1 errno=12 (Cannot allocate memory)
  mmap2(0x0097a000,33554432,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,-1,0) = -1 errno=12 (Cannot allocate memory)

* diffoscope on this 1.7G binary didn't really help as it got killed by OOMK after a while
  Out of memory: Killed process 1136999 (diffoscope) total-vm:404300108kB, anon-rss:122594688kB, file-rss:512kB, shmem-rss:0kB, UID:1026 pgtables:764240kB oom_score_adj:0

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
  • Loading branch information
shr-project authored and kraj committed Jun 28, 2023
1 parent ca6cc46 commit 33c96b7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions meta-oe/recipes-devtools/nodejs/nodejs_18.16.0.bb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ PACKAGECONFIG[zlib] = "--shared-zlib,,zlib"
# and we need to use the right flags during host compile,
# too.
EXTRA_OEMAKE = "\
CC.host='${CC}' \
CC.host='${CC} -pie -fPIE' \
CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
CXX.host='${CXX}' \
CXX.host='${CXX} -pie -fPIE' \
CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
LDFLAGS.host='${LDFLAGS}' \
AR.host='${AR}' \
Expand Down

0 comments on commit 33c96b7

Please sign in to comment.