ptitSeb / box86

Box86 - Linux Userspace x86 Emulator with a twist, targeted at ARM Linux devices
https://box86.org
MIT License
3.36k stars 233 forks source link

Segfault during cross-build in a qemu emulated system #728

Closed mbenlioglu closed 11 months ago

mbenlioglu commented 1 year ago

System information:

Decription:

I'm attempting to bring arm64 support for a steamcmd docker image. Currently, the build and execution works fine on a native arm CPU (tested on Raspberry Pi4 with 64bit OS). However, unfortunately when I attempt to cross-build the arm image on an x86_64 system with qemu, following the docker documentation (which is what happens on automated builds in dockerhub or github actions etc.), during the execution of box86/box64 I get this error:

realloc(): invalid old size
Aborted (core dumped)

This happens anytime attempting to run something with box86 or box64, e.g. the following will trigger this:

box64 /opt/box64/bash

where /opt/box64/bash is the one provided here

You can see the configuration I use in my Dockerfile. Running the following in an attempt to cross-build the image on an x86 system will reproduce the error:

$ docker buildx build --platform linux/arm64 --target bullseye-root -t steamcmd:root -f bullseye/Dockerfile .

Error happens on Line 73 of the Dockerfile.

PS: I tried to build an image on native arm, then tried to run the image on an x86 system with qemu to see if that makes any difference, but the error occurs either way.

ptitSeb commented 1 year ago

I'm not sure I understand correctly: you run box64 in a arm64 docker image using qemu on x86_64? and box64 doesn't behave correctly? but the same box64 from then arm64 docker image running on arm64 directly works fine? If that is the case, it looks more like a qemu issue than a box issue? Or did I get something wrong (that's a lot of emulation layer here!)

mbenlioglu commented 1 year ago

yes box64 works fine on native arm but doesn't behave correctly using qemu on x86_64. If I want to use automated builds for dockerhub etc. I pretty much need to use it for automated deployments even though it's a lot of emulation, because my other option is to buy a native arm server for automated builds.

mbenlioglu commented 1 year ago

I was hoping it was some kind of UB that could be fixed because I think the reaction I'll get from qemu devs will probably be "just don't use double emulation"

ptitSeb commented 1 year ago

The problem is, the error "relloc() invalid old size" is super generic. Can you try to run with valgrind? (so that will be triple emulation :O ), it might give usefull detail on the issue.

ptitSeb commented 1 year ago

Also, does the test01 from the tests folder gives the same issue?

Also also, you can try to run with BOX64_DYNAREC=0 env. var. to disable the dynarec, it might run better under qemu.

mbenlioglu commented 1 year ago

I will try those in a bit and provide debug outputs

mbenlioglu commented 1 year ago

Interestingly, disabling dynarec with the env variable makes it run correctly. Here are the valgrind outputs for running test01 (segfault happens if I don't set the dynarec env var):


valgrind output: BOX64_DYNAREC environment variable NOT set ``` ==531== Memcheck, a memory error detector ==531== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==531== Using Valgrind-3.16.1-36d6727e1d-20200622X and LibVEX; rerun with -h for copyright info ==531== Command: box64 test01 ==531== --531-- Valgrind options: --531-- --tool=memcheck --531-- --gen-suppressions=all --531-- --leak-check=full --531-- --track-origins=yes --531-- --show-leak-kinds=all --531-- --verbose --531-- Contents of /proc/version: --531-- Linux version 5.15.0-53-generic (buildd@lcy02-amd64-047) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 --531-- --531-- Arch and hwcaps: ARM64, LittleEndian, baseline --531-- Page sizes: currently 4096, max supported 65536 --531-- Valgrind library directory: /usr/lib/aarch64-linux-gnu/valgrind --531-- Reading syms from /lib/aarch64-linux-gnu/ld-2.31.so --531-- Considering /usr/lib/debug/.build-id/ae/4da2e572cddd8f08179a9bcda3dc37a146e2eb.debug .. --531-- .. build-id is valid --531-- Reading syms from /usr/lib/aarch64-linux-gnu/valgrind/memcheck-arm64-linux --531-- Considering /usr/lib/debug/.build-id/55/2b6c08fce7efb631c7becbfdbaf99ee9bb045e.debug .. --531-- .. build-id is valid --531-- object doesn't have a dynamic symbol table --531-- Reading syms from /usr/local/bin/box64 --531-- Scheduler: using generic scheduler lock implementation. --531-- Reading suppressions file: /usr/lib/aarch64-linux-gnu/valgrind/default.supp ==531== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-531-by-steam-on-d2f8e1897b22 ==531== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-531-by-steam-on-d2f8e1897b22 ==531== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-531-by-steam-on-d2f8e1897b22 ==531== ==531== TO CONTROL THIS PROCESS USING vgdb (which you probably ==531== don't want to do, unless you know exactly what you're doing, ==531== or are doing some strange experiment): ==531== /usr/bin/vgdb --pid=531 ...command... ==531== ==531== TO DEBUG THIS PROCESS USING GDB: start GDB like this ==531== /path/to/gdb box64 ==531== and then give GDB the following command ==531== target remote | /usr/bin/vgdb --pid=531 ==531== --pid is optional if only one valgrind process is running ==531== --531-- REDIR: 0x4019680 (ld-linux-aarch64.so.1:strlen) redirected to 0x580c8258 (vgPlain_arm64_linux_REDIR_FOR_strlen) --531-- REDIR: 0x4018680 (ld-linux-aarch64.so.1:strcmp) redirected to 0x580c82ac (vgPlain_arm64_linux_REDIR_FOR_strcmp) --531-- REDIR: 0x4018580 (ld-linux-aarch64.so.1:index) redirected to 0x580c8280 (vgPlain_arm64_linux_REDIR_FOR_index) --531-- Reading syms from /usr/lib/aarch64-linux-gnu/valgrind/vgpreload_core-arm64-linux.so --531-- Considering /usr/lib/debug/.build-id/86/2ef07f508ed868e9ce3095734b2ce9a19f61ad.debug .. --531-- .. build-id is valid --531-- Reading syms from /usr/lib/aarch64-linux-gnu/valgrind/vgpreload_memcheck-arm64-linux.so --531-- Considering /usr/lib/debug/.build-id/5b/38e3948c6b3565f564e907d1c4867e69b35835.debug .. --531-- .. build-id is valid --531-- Reading syms from /lib/aarch64-linux-gnu/libc-2.31.so --531-- Considering /usr/lib/debug/.build-id/76/89b99bf17371e7f441bdc217f4a0d17f449dd9.debug .. --531-- .. build-id is valid --531-- Reading syms from /lib/aarch64-linux-gnu/libm-2.31.so --531-- Considering /usr/lib/debug/.build-id/ae/78fc1be92ef39904b5b19fb2e5dcf5292bc879.debug .. --531-- .. build-id is valid --531-- Reading syms from /lib/aarch64-linux-gnu/libdl-2.31.so --531-- Considering /usr/lib/debug/.build-id/20/b17e8019b2e358363fd2f57808c7d63d3b76fd.debug .. --531-- .. build-id is valid --531-- Reading syms from /lib/aarch64-linux-gnu/librt-2.31.so --531-- Considering /usr/lib/debug/.build-id/77/4ba134055bb1a66a0d8edc55f1226673c52ac1.debug .. --531-- .. build-id is valid --531-- Reading syms from /lib/aarch64-linux-gnu/libpthread-2.31.so --531-- Considering /usr/lib/debug/.build-id/50/698f111196e410c367ad6031b3cb34c4dfc1e4.debug .. --531-- .. build-id is valid --531-- Reading syms from /lib/aarch64-linux-gnu/libresolv-2.31.so --531-- Considering /usr/lib/debug/.build-id/f8/9b5cd98638f300c32b00c82000166bf4f6dcaf.debug .. --531-- .. build-id is valid --531-- REDIR: 0x40e4ff0 (libc.so.6:memchr) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --531-- REDIR: 0x40e3dc0 (libc.so.6:strlen) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --531-- REDIR: 0x40e4240 (libc.so.6:rindex) redirected to 0x404cd00 (rindex) --531-- REDIR: 0x6496e220 (NONE:calloc) redirected to 0x404c0c0 (calloc) --531-- REDIR: 0x40e3540 (libc.so.6:strcmp) redirected to 0x404e338 (strcmp) --531-- REDIR: 0x40ece40 (libc.so.6:__GI_strlen) redirected to 0x404d328 (__GI_strlen) --531-- REDIR: 0x6496e210 (NONE:malloc) redirected to 0x4049dd8 (malloc) --531-- REDIR: 0x40eb500 (libc.so.6:__GI_memcpy) redirected to 0x404f070 (__GI_memcpy) --531-- REDIR: 0x40e70c0 (libc.so.6:strchrnul) redirected to 0x4051930 (strchrnul) --531-- REDIR: 0x40e4c20 (libc.so.6:strstr) redirected to 0x4052158 (strstr) --531-- REDIR: 0x40ecc40 (libc.so.6:__GI_memchr) redirected to 0x404e528 (__GI_memchr) --531-- REDIR: 0x40e401c (libc.so.6:strncmp) redirected to 0x404daa8 (strncmp) --531-- REDIR: 0x6496e2c0 (NONE:realloc) redirected to 0x404c2e8 (realloc) ==531== Invalid free() / delete / delete[] / realloc() ==531== at 0x404C368: realloc (vg_replace_malloc.c:834) ==531== by 0x40CA6EF: getdelim (iogetdelim.c:102) ==531== by 0x64AE52D3: getline (stdio.h:120) ==531== by 0x64AE52D3: grabNCpu (wrappedlibc.c:1341) ==531== by 0x64AE53CB: getNCpu (wrappedlibc.c:1360) ==531== by 0x64966F47: GatherDynarecExtensions.part.0 (main.c:310) ==531== by 0x64965073: main (main.c:1081) ==531== Address 0x1fff000770 is on thread 1's stack ==531== in frame #2, created by grabNCpu (stdio.h:1332) ==531== { Memcheck:Free fun:realloc fun:getdelim fun:getline fun:grabNCpu fun:getNCpu fun:GatherDynarecExtensions.part.0 fun:main } --531-- REDIR: 0x6496e260 (NONE:free) redirected to 0x404af70 (free) --531-- REDIR: 0x40e03b0 (libc.so.6:calloc) redirected to 0x404c0c0 (calloc) --531-- REDIR: 0x40e52e0 (libc.so.6:memset) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --531-- REDIR: 0x40ec700 (libc.so.6:__GI_memset) redirected to 0x4050df0 (memset) --531-- REDIR: 0x40dfec0 (libc.so.6:realloc) redirected to 0x404c2e8 (realloc) --531-- REDIR: 0x40e7080 (libc.so.6:rawmemchr) redirected to 0x4051960 (rawmemchr) --531-- REDIR: 0x40e3440 (libc.so.6:index) redirected to 0x404ceb0 (index) --531-- REDIR: 0x40e41e0 (libc.so.6:strncpy) redirected to 0x404d5d8 (strncpy) --531-- REDIR: 0x40e5900 (libc.so.6:memcpy) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --531-- REDIR: 0x40e5500 (libc.so.6:stpcpy) redirected to 0x40506b8 (stpcpy) --531-- REDIR: 0x40dfc70 (libc.so.6:free) redirected to 0x404af70 (free) --531-- REDIR: 0x40e51d0 (libc.so.6:memmove) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --531-- REDIR: 0x40eb690 (libc.so.6:__GI_memmove) redirected to 0x40511f8 (__GI_memmove) --531-- REDIR: 0x40e33f0 (libc.so.6:strcat) redirected to 0x404cfa0 (strcat) --531-- REDIR: 0x40e3680 (libc.so.6:strcpy) redirected to 0x404d418 (strcpy) --531-- REDIR: 0x40df6a0 (libc.so.6:malloc) redirected to 0x4049dd8 (malloc) --531-- REDIR: 0x40e02b4 (libc.so.6:memalign) redirected to 0x404c660 (memalign) valgrind: m_libcproc.c:1297 (vgPlain_flush_dcache): Assertion 'cls == 64 || cls == 128' failed. host stacktrace: ==531== at 0x58045CE4: show_sched_status_wrk (m_libcassert.c:406) ==531== by 0x58045E23: report_and_quit (m_libcassert.c:477) ==531== by 0x58045F83: vgPlain_assert_fail (m_libcassert.c:543) ==531== by 0x5804C897: vgPlain_flush_dcache (m_libcproc.c:1297) ==531== by 0x580A56E3: vgPlain_scheduler (scheduler.c:1686) ==531== by 0x580F05A3: thread_wrapper (syswrap-linux.c:101) ==531== by 0x580F05A3: run_a_thread_NORETURN (syswrap-linux.c:154) ==531== by 0xFFFFFFFFFFFFFFFF: ??? sched status: running_tid=1 Thread 1: status = VgTs_Runnable (lwpid 531) ==531== at 0x64F0F3B4: __aarch64_sync_cache_range (in /usr/local/bin/box64) ==531== by 0x64B834CF: FillBlock64 (dynarec_native.c:582) ==531== by 0x64B816DF: internalDBGetBlock.constprop.0 (dynablock.c:190) ==531== by 0x64B818B3: DBGetBlock (dynablock.c:220) ==531== by 0x649729C7: DynaRun (dynarec.c:184) ==531== by 0x649AB3BF: my___libc_start_main (x64run_private.c:45) ==531== by 0x64A8653F: iFEpippppp (wrapper.c:4172) ==531== by 0x64988EA3: Run (x64run.c:1088) ==531== by 0x64966243: main (main.c:1578) client stack range: [0x1FFEFFE000 0x1FFF000FFF] client SP: 0x1FFF000650 valgrind stack range: [0x100919C000 0x100929BFFF] top usage: 19216 of 1048576 Note: see also the FAQ in the source distribution. It contains workarounds to several common problems. In particular, if Valgrind aborted or crashed after identifying problems in your program, there's a good chance that fixing those problems will prevent Valgrind aborting or crashing, especially if it happened in m_mallocfree.c. If that doesn't help, please report this bug to: www.valgrind.org In the bug report, send all the above text, the valgrind version, and what OS and version you are using. Thanks. ```

Program output (no valgrind):

Dynarec for ARM64, with extension: ASIMD AES CRC32 PMULL ATOMICS PageSize:4096realloc(): invalid pointer
Aborted (core dumped)

valgrind output: BOX64_DYNAREC=0 set ``` ==542== Memcheck, a memory error detector ==542== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==542== Using Valgrind-3.16.1-36d6727e1d-20200622X and LibVEX; rerun with -h for copyright info ==542== Command: box64 test01 ==542== --542-- Valgrind options: --542-- --tool=memcheck --542-- --gen-suppressions=all --542-- --leak-check=full --542-- --track-origins=yes --542-- --show-leak-kinds=all --542-- --verbose --542-- Contents of /proc/version: --542-- Linux version 5.15.0-53-generic (buildd@lcy02-amd64-047) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 --542-- --542-- Arch and hwcaps: ARM64, LittleEndian, baseline --542-- Page sizes: currently 4096, max supported 65536 --542-- Valgrind library directory: /usr/lib/aarch64-linux-gnu/valgrind --542-- Reading syms from /lib/aarch64-linux-gnu/ld-2.31.so --542-- Considering /usr/lib/debug/.build-id/ae/4da2e572cddd8f08179a9bcda3dc37a146e2eb.debug .. --542-- .. build-id is valid --542-- Reading syms from /usr/lib/aarch64-linux-gnu/valgrind/memcheck-arm64-linux --542-- Considering /usr/lib/debug/.build-id/55/2b6c08fce7efb631c7becbfdbaf99ee9bb045e.debug .. --542-- .. build-id is valid --542-- object doesn't have a dynamic symbol table --542-- Reading syms from /usr/local/bin/box64 --542-- Scheduler: using generic scheduler lock implementation. --542-- Reading suppressions file: /usr/lib/aarch64-linux-gnu/valgrind/default.supp ==542== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-542-by-steam-on-d2f8e1897b22 ==542== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-542-by-steam-on-d2f8e1897b22 ==542== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-542-by-steam-on-d2f8e1897b22 ==542== ==542== TO CONTROL THIS PROCESS USING vgdb (which you probably ==542== don't want to do, unless you know exactly what you're doing, ==542== or are doing some strange experiment): ==542== /usr/bin/vgdb --pid=542 ...command... ==542== ==542== TO DEBUG THIS PROCESS USING GDB: start GDB like this ==542== /path/to/gdb box64 ==542== and then give GDB the following command ==542== target remote | /usr/bin/vgdb --pid=542 ==542== --pid is optional if only one valgrind process is running ==542== --542-- REDIR: 0x4019680 (ld-linux-aarch64.so.1:strlen) redirected to 0x580c8258 (vgPlain_arm64_linux_REDIR_FOR_strlen) --542-- REDIR: 0x4018680 (ld-linux-aarch64.so.1:strcmp) redirected to 0x580c82ac (vgPlain_arm64_linux_REDIR_FOR_strcmp) --542-- REDIR: 0x4018580 (ld-linux-aarch64.so.1:index) redirected to 0x580c8280 (vgPlain_arm64_linux_REDIR_FOR_index) --542-- Reading syms from /usr/lib/aarch64-linux-gnu/valgrind/vgpreload_core-arm64-linux.so --542-- Considering /usr/lib/debug/.build-id/86/2ef07f508ed868e9ce3095734b2ce9a19f61ad.debug .. --542-- .. build-id is valid --542-- Reading syms from /usr/lib/aarch64-linux-gnu/valgrind/vgpreload_memcheck-arm64-linux.so --542-- Considering /usr/lib/debug/.build-id/5b/38e3948c6b3565f564e907d1c4867e69b35835.debug .. --542-- .. build-id is valid --542-- Reading syms from /lib/aarch64-linux-gnu/libc-2.31.so --542-- Considering /usr/lib/debug/.build-id/76/89b99bf17371e7f441bdc217f4a0d17f449dd9.debug .. --542-- .. build-id is valid --542-- Reading syms from /lib/aarch64-linux-gnu/libm-2.31.so --542-- Considering /usr/lib/debug/.build-id/ae/78fc1be92ef39904b5b19fb2e5dcf5292bc879.debug .. --542-- .. build-id is valid --542-- Reading syms from /lib/aarch64-linux-gnu/libdl-2.31.so --542-- Considering /usr/lib/debug/.build-id/20/b17e8019b2e358363fd2f57808c7d63d3b76fd.debug .. --542-- .. build-id is valid --542-- Reading syms from /lib/aarch64-linux-gnu/librt-2.31.so --542-- Considering /usr/lib/debug/.build-id/77/4ba134055bb1a66a0d8edc55f1226673c52ac1.debug .. --542-- .. build-id is valid --542-- Reading syms from /lib/aarch64-linux-gnu/libpthread-2.31.so --542-- Considering /usr/lib/debug/.build-id/50/698f111196e410c367ad6031b3cb34c4dfc1e4.debug .. --542-- .. build-id is valid --542-- Reading syms from /lib/aarch64-linux-gnu/libresolv-2.31.so --542-- Considering /usr/lib/debug/.build-id/f8/9b5cd98638f300c32b00c82000166bf4f6dcaf.debug .. --542-- .. build-id is valid --542-- REDIR: 0x40e4ff0 (libc.so.6:memchr) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --542-- REDIR: 0x40e3dc0 (libc.so.6:strlen) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --542-- REDIR: 0x40e4240 (libc.so.6:rindex) redirected to 0x404cd00 (rindex) --542-- REDIR: 0x6496e220 (NONE:calloc) redirected to 0x404c0c0 (calloc) --542-- REDIR: 0x40e3540 (libc.so.6:strcmp) redirected to 0x404e338 (strcmp) --542-- REDIR: 0x40ece40 (libc.so.6:__GI_strlen) redirected to 0x404d328 (__GI_strlen) --542-- REDIR: 0x40e401c (libc.so.6:strncmp) redirected to 0x404daa8 (strncmp) --542-- REDIR: 0x40e70c0 (libc.so.6:strchrnul) redirected to 0x4051930 (strchrnul) --542-- REDIR: 0x6496e210 (NONE:malloc) redirected to 0x4049dd8 (malloc) --542-- REDIR: 0x40eb500 (libc.so.6:__GI_memcpy) redirected to 0x404f070 (__GI_memcpy) --542-- REDIR: 0x40e4c20 (libc.so.6:strstr) redirected to 0x4052158 (strstr) --542-- REDIR: 0x40e03b0 (libc.so.6:calloc) redirected to 0x404c0c0 (calloc) --542-- REDIR: 0x40e52e0 (libc.so.6:memset) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --542-- REDIR: 0x40ec700 (libc.so.6:__GI_memset) redirected to 0x4050df0 (memset) --542-- REDIR: 0x40dfec0 (libc.so.6:realloc) redirected to 0x404c2e8 (realloc) --542-- REDIR: 0x40ecc40 (libc.so.6:__GI_memchr) redirected to 0x404e528 (__GI_memchr) --542-- REDIR: 0x40e7080 (libc.so.6:rawmemchr) redirected to 0x4051960 (rawmemchr) --542-- REDIR: 0x6496e260 (NONE:free) redirected to 0x404af70 (free) --542-- REDIR: 0x6496e2c0 (NONE:realloc) redirected to 0x404c2e8 (realloc) --542-- REDIR: 0x40e3440 (libc.so.6:index) redirected to 0x404ceb0 (index) --542-- REDIR: 0x40e41e0 (libc.so.6:strncpy) redirected to 0x404d5d8 (strncpy) --542-- REDIR: 0x40e5900 (libc.so.6:memcpy) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --542-- REDIR: 0x40e5500 (libc.so.6:stpcpy) redirected to 0x40506b8 (stpcpy) --542-- REDIR: 0x40dfc70 (libc.so.6:free) redirected to 0x404af70 (free) --542-- REDIR: 0x40e51d0 (libc.so.6:memmove) redirected to 0x40346c8 (_vgnU_ifunc_wrapper) --542-- REDIR: 0x40eb690 (libc.so.6:__GI_memmove) redirected to 0x40511f8 (__GI_memmove) --542-- REDIR: 0x40e33f0 (libc.so.6:strcat) redirected to 0x404cfa0 (strcat) --542-- REDIR: 0x40e3680 (libc.so.6:strcpy) redirected to 0x404d418 (strcpy) ==542== ==542== HEAP SUMMARY: ==542== in use at exit: 18,979 bytes in 57 blocks ==542== total heap usage: 262 allocs, 205 frees, 746,357 bytes allocated ==542== ==542== Searching for pointers to 57 not-freed blocks ==542== Checked 27,567,520 bytes ==542== ==542== 11 bytes in 1 blocks are indirectly lost in loss record 1 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x64B0957F: wrappedlibrt_init (wrappedlib_init.h:143) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:box_strdup fun:wrappedlibrt_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs } ==542== 16 bytes in 1 blocks are indirectly lost in loss record 2 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x64B08FFB: wrappedlibpthread_init (wrappedlib_init.h:143) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:box_strdup fun:wrappedlibpthread_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs } ==542== 17 bytes in 1 blocks are definitely lost in loss record 3 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x64968A1B: GatherEnv (main.c:731) ==542== by 0x6496554B: main (main.c:1197) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:box_strdup fun:GatherEnv fun:main } ==542== 21 bytes in 1 blocks are definitely lost in loss record 4 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x6496574F: main (main.c:1238) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:box_strdup fun:main } ==542== 23 bytes in 1 blocks are definitely lost in loss record 5 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x6496894F: GatherEnv (main.c:742) ==542== by 0x6496554B: main (main.c:1197) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:box_strdup fun:GatherEnv fun:main } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 6 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6D87: NewBridge (bridge.c:68) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64AEA3CB: wrappedlibc_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedlibc_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 7 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6C6B: NewBrick (bridge.c:52) ==542== by 0x649C6D93: NewBridge (bridge.c:69) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64AEA3CB: wrappedlibc_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBrick fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedlibc_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 8 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B88E3: setNeededLibs (library.c:1057) ==542== by 0x64AEA733: wrappedlibc_init (wrappedlib_init.h:200) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:setNeededLibs fun:wrappedlibc_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 9 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6D87: NewBridge (bridge.c:68) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64ADFACB: wrappedldlinux_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedldlinux_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 10 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6C6B: NewBrick (bridge.c:52) ==542== by 0x649C6D93: NewBridge (bridge.c:69) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64ADFACB: wrappedldlinux_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBrick fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedldlinux_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 11 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6D87: NewBridge (bridge.c:68) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64B09017: wrappedlibpthread_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedlibpthread_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 12 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6C6B: NewBrick (bridge.c:52) ==542== by 0x649C6D93: NewBridge (bridge.c:69) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64B09017: wrappedlibpthread_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBrick fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedlibpthread_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 13 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6D87: NewBridge (bridge.c:68) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64B0959F: wrappedlibrt_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedlibrt_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib } ==542== 24 bytes in 1 blocks are indirectly lost in loss record 14 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649C6C6B: NewBrick (bridge.c:52) ==542== by 0x649C6D93: NewBridge (bridge.c:69) ==542== by 0x649B6A43: WrappedLib_CommonInit (library.c:88) ==542== by 0x64B0959F: wrappedlibrt_init (wrappedlib_init.h:145) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewBrick fun:NewBridge fun:WrappedLib_CommonInit fun:wrappedlibrt_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add } ==542== 34 bytes in 1 blocks are definitely lost in loss record 15 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x649689F3: GatherEnv (main.c:734) ==542== by 0x6496554B: main (main.c:1197) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:box_strdup fun:GatherEnv fun:main } ==542== 48 bytes in 1 blocks are indirectly lost in loss record 16 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B7EAF: addLinkMapLib (library.c:969) ==542== by 0x649B801B: initWrappedLib (library.c:230) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:addLinkMapLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 48 bytes in 3 blocks are indirectly lost in loss record 17 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x649B8933: setNeededLibs (library.c:1061) ==542== by 0x64AEA733: wrappedlibc_init (wrappedlib_init.h:200) ==542== by 0x649B7F63: initWrappedLib (library.c:211) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:box_strdup fun:setNeededLibs fun:wrappedlibc_init fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 64 bytes in 1 blocks are indirectly lost in loss record 18 of 28 ==542== at 0x4049D84: malloc (vg_replace_malloc.c:306) ==542== by 0x404C3CF: realloc (vg_replace_malloc.c:834) ==542== by 0x649B8743: add_neededlib (library.c:1015) ==542== by 0x649B207B: AddNeededLib_add (librarian.c:253) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:malloc fun:realloc fun:add_neededlib fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 113 bytes in 4 blocks are definitely lost in loss record 19 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x649B78A3: GetLibGlobalSymbolStartEnd (library.c:660) ==542== by 0x649B0F5B: GetGlobalSymbolStartEnd_internal (librarian.c:452) ==542== by 0x649B2EC7: GetGlobalSymbolStartEnd (librarian.c:482) ==542== by 0x64979923: RelocateElfRELA (elfloader.c:615) ==542== by 0x6497A80F: RelocateElf (elfloader.c:840) ==542== by 0x64966177: main (main.c:1550) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:box_strdup fun:GetLibGlobalSymbolStartEnd fun:GetGlobalSymbolStartEnd_internal fun:GetGlobalSymbolStartEnd fun:RelocateElfRELA fun:RelocateElf fun:main } ==542== 113 bytes in 4 blocks are definitely lost in loss record 20 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x649B78A3: GetLibGlobalSymbolStartEnd (library.c:660) ==542== by 0x649B34BF: GetGlobalNoWeakSymbolStartEnd (librarian.c:570) ==542== by 0x64979C67: RelocateElfRELA (elfloader.c:682) ==542== by 0x6497A80F: RelocateElf (elfloader.c:840) ==542== by 0x64966177: main (main.c:1550) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:box_strdup fun:GetLibGlobalSymbolStartEnd fun:GetGlobalNoWeakSymbolStartEnd fun:RelocateElfRELA fun:RelocateElf fun:main } ==542== 144 bytes in 3 blocks are indirectly lost in loss record 21 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B7EAF: addLinkMapLib (library.c:969) ==542== by 0x649B801B: initWrappedLib (library.c:230) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:addLinkMapLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 192 bytes in 3 blocks are indirectly lost in loss record 22 of 28 ==542== at 0x4049D84: malloc (vg_replace_malloc.c:306) ==542== by 0x404C3CF: realloc (vg_replace_malloc.c:834) ==542== by 0x649B882B: add_dependedbylib (library.c:1037) ==542== by 0x649B22B7: AddNeededLib_add (librarian.c:254) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:malloc fun:realloc fun:add_dependedbylib fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 264 bytes in 1 blocks are indirectly lost in loss record 23 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B81BF: NewLibrary (library.c:356) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 431 bytes in 14 blocks are definitely lost in loss record 24 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x6496E7A3: box_strdup (mallochook.c:133) ==542== by 0x649689A7: GatherEnv (main.c:723) ==542== by 0x6496554B: main (main.c:1197) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:box_strdup fun:GatherEnv fun:main } ==542== 792 bytes in 3 blocks are indirectly lost in loss record 25 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B81BF: NewLibrary (library.c:356) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 4,096 bytes in 1 blocks are indirectly lost in loss record 26 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B695B: Path2Name (library.c:60) ==542== by 0x649B81FB: NewLibrary (library.c:363) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:Path2Name fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 12,288 bytes in 3 blocks are indirectly lost in loss record 27 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B695B: Path2Name (library.c:60) ==542== by 0x649B81FB: NewLibrary (library.c:363) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649B7FEB: initWrappedLib (library.c:225) ==542== by 0x649B85BB: NewLibrary (library.c:397) ==542== by 0x649B2067: AddNeededLib_add (librarian.c:247) ==542== by 0x649B23D7: AddNeededLib (librarian.c:342) ==542== by 0x649776BF: LoadNeededLibs (elfloader.c:1123) ==542== by 0x64966123: main (main.c:1543) ==542== { Memcheck:Leak match-leak-kinds: indirect fun:calloc fun:Path2Name fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:initWrappedLib fun:NewLibrary fun:AddNeededLib_add fun:AddNeededLib fun:LoadNeededLibs fun:main } ==542== 18,227 (48 direct, 18,179 indirect) bytes in 1 blocks are definitely lost in loss record 28 of 28 ==542== at 0x404C164: calloc (vg_replace_malloc.c:760) ==542== by 0x649B7ED3: addLinkMapLib (library.c:962) ==542== by 0x649B8667: AddMainElfToLinkmap (library.c:987) ==542== by 0x64966067: main (main.c:1533) ==542== { Memcheck:Leak match-leak-kinds: definite fun:calloc fun:addLinkMapLib fun:AddMainElfToLinkmap fun:main } ==542== LEAK SUMMARY: ==542== definitely lost: 800 bytes in 27 blocks ==542== indirectly lost: 18,179 bytes in 30 blocks ==542== possibly lost: 0 bytes in 0 blocks ==542== still reachable: 0 bytes in 0 blocks ==542== suppressed: 0 bytes in 0 blocks ==542== ==542== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0) ```

Program output (no valgrind) :

Dynarec is off
Box64 with Dynarec v0.2.0 6668614 built on Nov 26 2022 23:02:04
Using default BOX64_LD_LIBRARY_PATH: ./:lib/:lib64/:x86_64/:bin64/:libs64/
Using default BOX64_PATH: ./:bin/
Counted 13 Env var
Looking for test01
Rename process to "test01"
Using native(wrapped) libc.so.6
Using native(wrapped) ld-linux-x86-64.so.2
Using native(wrapped) libpthread.so.0
Using native(wrapped) librt.so.1
Hello x86_64 World!
ptitSeb commented 1 year ago

Ok, I think I found the issue that is triggering the realloc error. I have pushed a fix on both box86 & box64. Hopefully, it will make it work good enough for you now.

ptitSeb commented 1 year ago

@mbenlioglu did you tried? Can this ticket be closed?

mbenlioglu commented 1 year ago

Last weeks were a bit busy. I was about to run a test today. Will update you later today

mbenlioglu commented 1 year ago

Results are interesting. I thought it's fixed at first because I ran all the tests in the repo in both native arm and qemu system like the following:

for x in {01..20};  do
    echo -e "\ntest$x" >> tests86
    box86 ./box86/tests/test$x >> tests86
done

for x in {01..22}; do
    echo -e "\ntest$x" >> tests64
    box64 ./box64/tests/test$x >> tests64
done

Outputs were the same and there were no errors that I could see. But when I run steamcmd.sh with box86 both systems gave segfault.

Box86 with Dynarec v0.2.9 47581dd built on Dec 14 2022 11:41:41
Error: reading elf header of /tmp/steamcmd/steamcmd.sh, try to launch using bash instead
Box86 with Dynarec v0.2.9 47581dd built on Dec 14 2022 11:41:41
Error: reading elf header of /opt/box64/bash, try to launch using box64 instead
Segmentation fault (core dumped)

(Sidenote: I realized that segfault happens running any bash script (discovered it while trying to run test.sh below). Note that BOX64_BASH variable is set to the location of x64 bash provided in box64 repo)

I tried running it with box64 instead, but that fails on qemu system. The problem comes down to steamcmd.sh calling itself with exec to do a restart when it needs. This test script mimics the behavior:

#!/usr/bin/env bash

FILE_NAME=`basename "$0" .sh`
UNAME=`uname`
ARCH=`uname -m`
ARG=${1:-first}

echo "Hello, my name is ${FILE_NAME}. I'm running on a ${ARCH} ${UNAME} machine. This is my ${ARG} run"

if [[ "${ARG}" == "first" ]]; then
    exec "$0" second
fi

Native output (no box86/box64 emulation):

Hello, my name is test. I'm running on a aarch64 Linux machine. This is my first run
Hello, my name is test. I'm running on a aarch64 Linux machine. This is my second run
Output of `box64` on native arm (expected result) ``` Box64 with Dynarec v0.2.1 73467dc built on Dec 14 2022 12:10:10 Error: reading elf header of /tmp/test.sh, try to launch using bash instead Box64 with Dynarec v0.2.1 73467dc built on Dec 14 2022 12:10:10 Hello, my name is test. I'm running on a x86_64 Linux machine. This is my first run Dynarec for ARM64, with extension: ASIMD CRC32 PageSize:4096 Cores:4 Params database has 11 entries Box64 with Dynarec v0.2.1 73467dc built on Dec 14 2022 12:10:10 BOX64_LD_LIBRARY_PATH: ./:lib/:lib64/ BOX64_PATH: ./:bin/ Counted 12 Env var Looking for /opt/box64/bash bash detected, disabling banner argv[1]="/tmp/test.sh" argv[2]="second" Rename process to "bash" Using native(wrapped) libtinfo.so.6 Using native(wrapped) libdl.so.2 Using native(wrapped) libc.so.6 Using native(wrapped) ld-linux-x86-64.so.2 Using native(wrapped) libpthread.so.0 Using native(wrapped) librt.so.1 Hello, my name is test. I'm running on a x86_64 Linux machine. This is my second run ```
Output of `box64` on Qemu ``` Box64 with Dynarec v0.2.1 73467dc built on Dec 14 2022 11:53:15 Error: reading elf header of /tmp/test.sh, try to launch using bash instead Box64 with Dynarec v0.2.1 73467dc built on Dec 14 2022 11:53:15 Hello, my name is test. I'm running on a x86_64 Linux machine. This is my first run Dynarec for ARM64, with extension: ASIMD AES CRC32 PMULL ATOMICS PageSize:4096 Cores:16 Params database has 11 entries Box64 with Dynarec v0.2.1 73467dc built on Dec 14 2022 11:53:15 BOX64_LD_LIBRARY_PATH: ./:lib/:lib64/ BOX64_PATH: ./:bin/ Counted 12 Env var Looking for /opt/box64/bash bash detected, disabling banner argv[1]="/tmp/test.sh" argv[2]="second" Rename process to "bash" Using native(wrapped) libtinfo.so.6 Using native(wrapped) libdl.so.2 Using native(wrapped) libc.so.6 Using native(wrapped) ld-linux-x86-64.so.2 Using native(wrapped) libpthread.so.0 Using native(wrapped) librt.so.1 /tmp/test.sh: line 3: basename: command not found /tmp/test.sh: line 4: uname: command not found /tmp/test.sh: line 5: uname: command not found Hello, my name is . I'm running on a machine. This is my second run ```
mbenlioglu commented 1 year ago

Outputs were the same and there were no errors that I could see. But when I run steamcmd.sh with box86 both systems gave segfault.

Valgrind outputs for running box86 $BOX64_BASH command:

valgrind-native.txt valgrind-qemu.txt

mbenlioglu commented 1 year ago

I'm periodically trying with the latest updates, issues still persist. Segfault when calling box86 $BOX64_BASH might have higher priority since it's also present in native arm. The problem with the script calling itself with exec is only present in qemu (I also tested different versions of qemu to no avail).

mbenlioglu commented 1 year ago

@ptitSeb I played around a little bit and discovered a few things related to this.

Segfault on running box86 $BOX64_BASH happens only on Debian and RaspberryPi OS, and not on Ubuntu (all 64-bit). This is reproducible on Raspberry Pi 4 with latest 64-bit Raspberry Pi OS natively (based on Debian bullseye). Apparently, a null pointer is being sent to the function internalFreeX86. Here's a gdb output of the backtrace of the segfault:

(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x629aff14 in internalFreeX86 (emu=0x1) at /home/testPi/repos/box86/src/emu/x86emu.c:187
187         if(emu->stack2free)
(gdb) backtrace
#0  0x629aff14 in internalFreeX86 (emu=0x1) at /home/testPi/repos/box86/src/emu/x86emu.c:187
#1  0x629affe0 in FreeX86Emu (emu=0x63a18198) at /home/testPi/repos/box86/src/emu/x86emu.c:198
#2  0x62a775bc in emuthread_destroy (p=0x63a18190) at /home/testPi/repos/box86/src/libtools/threads.c:180
#3  0x62a7db7c in fini_pthread_helper (context=0x63a1a120) at /home/testPi/repos/box86/src/libtools/threads.c:1038
#4  0x6288e76c in finiAllHelpers (context=0x63a1a120) at /home/testPi/repos/box86/src/box86context.c:53
#5  0x6288f7d8 in FreeBox86Context (context=0x63748ca4 <my_context>) at /home/testPi/repos/box86/src/box86context.c:360
#6  0x6288cf6c in main (argc=2, argv=0xfffef534, env=0xfffef540) at /home/testPi/repos/box86/src/main.c:1408

The second issue related to the test script was caused by $BOX64_PATH$ and $BOX64_LD_LIBRARY_PATH$ overriding $PATH$ and $LD_LIBRARY_PATH$ environment variables, respectively. I couldn't reproduce this issue natively, and it only presents itself in the qemu emulated system, but as a temporary workaround I managed to get it working by exporting $BOX64_PATH=$BOX64_PATH:$PATH. I'm not sure if this one is caused by an underlying undefined behavior or not, but the temporary workaround works fine for that one, so it's not as important as the first one.

ptitSeb commented 1 year ago

I pushed something that should help. But this look like a QEMU specific issue to me: a pthread_getspecific(...) will not return a NULL value if it has never been initialized before. Well, I suppose it's not bad to have proper code and initlialize it anyway,

mbenlioglu commented 1 year ago

segfault was actually happening in baremetal Raspberry Pi with Raspberry Pi OS. I'll try your patch now and update you