-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Leak wasm2c.c while building zig #21777
Comments
~Everyone who works on Zig bootstraps with
It seems unlikely that we'll fix this. The leak here is bounded and there's no real benefit to freeing the memory just before exiting; rather, doing so would just slow down the bootstrap. A total of 50491 bytes leaked should not cause an OOM on any reasonably usable machine today, anyway. More to the point, I suggest building without Address Sanitizer and, if |
That's a ridiculous argument in favor of leaking memory. It takes a non-zero amount of time, yes, but it's not slow until you have a profile saying so :) |
If there are users / use cases that want to leak memory and those who don't, the free-ing could be put behind a macro / compile flag.
Are you stating the produced zig binary crashes due to a segfault? If so, I see no relation between that and memory leaks when executing If the produced compiler executable segfaults, please ask in one of the community spaces for help, or file a separate issue - you'll probably have to provide more details about your system, the exact build commands used, etc. |
working as designed |
no. it's ridiculous to suggest adding additional, unnecessary syscalls to reclaim 50K virtual memory, when those 50K will be reclaimed by the OS. |
I was not suggesting anything, merely pointing out that @alexrp's "freeing this memory slows down bootstrap" doesn't match reality. |
Zig Version
latest dev as well as any
Steps to Reproduce and Observed Behavior
CARGS =
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_VERBOSE_MAKEFILE=ON
-DZIG2_NO_RTLIB=OFF
-DZIG_AR_WORKAROUND=OFF
-DZIG_EXTRA_BUILD_ARGS=OFF
-DZIG_HOST_TARGET_TRIPLE=x86_64-linux
-DZIG_NO_LIB=OFF
-DZIG_PIE=OFF
-DZIG_SHARED_LLVM=OFF
-DZIG_SINGLE_THREADED=OFF
-DZIG_STATIC=OFF
-DZIG_STATIC_CURSES=OFF
-DZIG_STATIC_LLVM=OFF
-DZIG_STATIC_ZLIB=OFF
-DZIG_STATIC_ZSTD=OFF
-DZIG_SYSTEM_LIBCXX=stdc++
-DZIG_TARGET_MCPU=x86_64
-DZIG_TARGET_TRIPLE=native
-Wno-dev \
-- The C compiler identification is Clang 19.1.2
-- The CXX compiler identification is Clang 19.1.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib/llvm/19/bin/clang-19 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib/llvm/19/bin/clang++-19 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring zig version 0.14.0-dev.1954+2d888a8e6
-- Found llvm: -lLLVM-19 (Required is at least version "19")
-- Found clang: /usr/lib/llvm/19/lib64/libclang-cpp.so.19.1 (Required is at least version "19")
-- Found lld: /usr/lib/llvm/19/lib64/liblldMinGW.so;/usr/lib/llvm/19/lib64/liblldELF.so;/usr/lib/llvm/19/lib64/liblldCOFF.so;/usr/lib/llvm/19/lib64/liblldWasm.so;/usr/lib/llvm/19/lib64/liblldMachO.so;/usr/lib/llvm/19/lib64/liblldCommon.so (Required is at least version "19")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done (2.7s)
-- Generating done (0.0s)
-- Build files have been written to: /var/tmp/lang-zig-bld20241023110438
[1/19] Building C object CMakeFiles/zig-wasm2c.dir/stage1/wasm2c.c.o
...
Direct leak of 20460 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc790 in realloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc790)
#1 0x00000042d388 in FuncGen_localAlloc /shr/git/rep/lang/zig/zig/stage1/FuncGen.h:72:22
#2 0x000000428eb3 in FuncGen_blockBegin /shr/git/rep/lang/zig/zig/stage1/FuncGen.h:166:22
#3 0x000000424cea in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:795:29
#4 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 14956 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x000000420084 in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:353:17
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 9920 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc790 in realloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc790)
#1 0x000000428e0c in FuncGen_blockBegin /shr/git/rep/lang/zig/zig/stage1/FuncGen.h:154:23
#2 0x000000424cea in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:795:29
#3 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 1488 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x00000041f220 in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:295:17
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 576 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x00000041f5e8 in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:313:19
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 560 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc790 in realloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc790)
#1 0x00000042a641 in FuncGen_stackPop /shr/git/rep/lang/zig/zig/stage1/FuncGen.h:133:23
#2 0x000000425087 in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:952:56
#3 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 240 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc790 in realloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc790)
#1 0x00000042afd2 in FuncGen_stackPush /shr/git/rep/lang/zig/zig/stage1/FuncGen.h:116:23
#2 0x0000004244cf in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:1372:29
#3 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 100 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x000000421ded in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:514:33
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 25 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x000000421ddd in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:513:28
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 12 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x0000004208fa in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:382:18
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x000000420d2a in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:407:16
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Direct leak of 2 byte(s) in 1 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x000000420e74 in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:425:19
#2 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Indirect leak of 844 byte(s) in 93 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x000000428260 in InputStream_readResultType /shr/git/rep/lang/zig/zig/stage1/InputStream.h:163:38
#2 0x00000041f26b in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:299:30
#3 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Indirect leak of 552 byte(s) in 24 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x0000004283e2 in InputStream_readName /shr/git/rep/lang/zig/zig/stage1/InputStream.h:137:18
#2 0x00000041f648 in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:316:30
#3 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Indirect leak of 422 byte(s) in 93 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x000000428260 in InputStream_readResultType /shr/git/rep/lang/zig/zig/stage1/InputStream.h:163:38
#2 0x00000041f386 in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:301:31
#3 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
Indirect leak of 326 byte(s) in 24 object(s) allocated from:
#0 0x0000003dc4e3 in malloc (/var/tmp/lang-zig-bld20241023110438/zig-wasm2c+0x3dc4e3)
#1 0x0000004283e2 in InputStream_readName /shr/git/rep/lang/zig/zig/stage1/InputStream.h:137:18
#2 0x00000041f68e in main /shr/git/rep/lang/zig/zig/stage1/wasm2c.c:317:31
#3 0x7f868f5d8a3c (/lib64/libc.so.6+0x24a3c)
SUMMARY: AddressSanitizer: 50491 byte(s) leaked in 246 allocation(s).
Expected Behavior
Every time I build ZIG I end up with Segfault by just executing zig stage3.
I have enabled all debugging options possible to track where it all comes from.
The problem has began already with wasm2c.c
Did anyone checked the code ever?
Expected no memory leak.
The full log can be attache, but I don't know where. No such option.
The text was updated successfully, but these errors were encountered: