Bug Description
box64 crashes with SIGSEGV immediately on startup on LoongArch64 (Loongson-3A5000M, LA64).
Environment
- OS: Kylin Linux V10 SP1 (LoongArch64)
- CPU: Loongson-3A5000M
- gcc version: 8.3.0
- glibc: 2.28
- box64: compiled from source (latest main branch)
- cmake: 3.16.3
Reproduction
Build with default settings on LA64:
mkdir build && cd build
cmake .. -DBOX64_LAZYPATCH=1
make -j$(nproc)
./box64 --version
→ Segmentation fault (core dumped)
Root Cause (GDB analysis)
Crash occurs in init_malloc_hook() at mallochook.c:1085:
box_malloc_usable_size = dlsym(RTLD_NEXT, "malloc_usable_size")
Call stack:
#0 0x0000000000000000 in ?? ()
#1 0x000000003510ed24 in dlsym (handle=0xffffffffffffffff, symbol="malloc_usable_size")
#2 0x000000003498307c in init_malloc_hook () ← mallochook.c:1085
#3 0x000000003483d53c in initialize () ← core.c:776
#4 0x000000003482fd90 in main ()
The handle value 0xffffffffffffffff is correct (RTLD_NEXT).
The crash happens because box64's custom dlsym wrapper calls real_dlsym,
but real_dlsym's GOT entry is NULL at this early initialization stage.
Additional Notes
- Disabling DYNAREC (DLARCH64_DYNAREC=OFF) does not fix it
- STATICBUILD=ON does not fix it
- ARM64 build does not have this issue (different code path)
- The problem is specific to LA64 + DYNAREC combination
Bug Description
box64 crashes with SIGSEGV immediately on startup on LoongArch64 (Loongson-3A5000M, LA64).
Environment
Reproduction
Build with default settings on LA64:
mkdir build && cd build
cmake .. -DBOX64_LAZYPATCH=1
make -j$(nproc)
./box64 --version
→ Segmentation fault (core dumped)
Root Cause (GDB analysis)
Crash occurs in init_malloc_hook() at mallochook.c:1085:
box_malloc_usable_size = dlsym(RTLD_NEXT, "malloc_usable_size")
Call stack:
#0 0x0000000000000000 in ?? ()
#1 0x000000003510ed24 in dlsym (handle=0xffffffffffffffff, symbol="malloc_usable_size")
#2 0x000000003498307c in init_malloc_hook () ← mallochook.c:1085
#3 0x000000003483d53c in initialize () ← core.c:776
#4 0x000000003482fd90 in main ()
The handle value 0xffffffffffffffff is correct (RTLD_NEXT).
The crash happens because box64's custom dlsym wrapper calls real_dlsym,
but real_dlsym's GOT entry is NULL at this early initialization stage.
Additional Notes