zig icon indicating copy to clipboard operation
zig copied to clipboard

undefined memory being written to output file from dwarf linker code

Open andrewrk opened this issue 1 year ago • 0 comments

Zig Version

0.12.0-dev.3405+31791ae15

Steps to Reproduce and Observed Behavior

$ valgrind stage4/bin/zig test ../test/behavior.zig -fno-llvm -fno-lld
==1663319== Thread 1:
==1663319== Syscall param pwritev(vector[0]) points to uninitialised byte(s)
==1663319==    at 0x106066C0: pwritev (in /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib/libc.so.6)
==1663319==    by 0x63207D2: posix.pwritev (posix.zig:1463)
==1663319==    by 0x5FB6677: fs.File.pwritev (File.zig:1326)
==1663319==    by 0x5CFD194: fs.File.pwritevAll (File.zig:1340)
==1663319==    by 0x624048A: link.Dwarf.pwriteDbgInfoNops (Dwarf.zig:2293)
==1663319==    by 0x62417B3: link.Dwarf.writeDeclDebugInfo (Dwarf.zig:1625)
==1663319==    by 0x62446FB: link.Dwarf.commitDeclState (Dwarf.zig:1508)
==1663319==    by 0x64D4967: link.Elf.ZigObject.updateFunc (ZigObject.zig:1108)
==1663319==    by 0x64D651B: link.Elf.updateFunc (Elf.zig:3027)
==1663319==    by 0x618A6BD: link.File.updateFunc (link.zig:439)
==1663319==    by 0x5EF50C8: Module.ensureFuncBodyAnalyzed (Module.zig:3279)
==1663319==    by 0x5EF22EB: Compilation.processOneJob (Compilation.zig:3434)
==1663319==  Address 0x24ce17ba is 74 bytes inside a block of size 105 alloc'd
==1663319==    at 0x103E776B: malloc (in /nix/store/4yj7p7b95fjbr9dp6cnnqdnq476622w1-valgrind-3.22.0/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1663319==    by 0x5C36A02: heap.rawCAlloc (heap.zig:188)
==1663319==    by 0x60BAC2C: rawAlloc (Allocator.zig:86)
==1663319==    by 0x60BAC2C: mem.Allocator.allocBytesWithAlignment__anon_77149 (Allocator.zig:225)
==1663319==    by 0x5E0333A: mem.Allocator.allocWithSizeAndAlignment__anon_57566 (Allocator.zig:211)
==1663319==    by 0x5E18918: allocAdvancedWithRetAddr (Allocator.zig:205)
==1663319==    by 0x5E18918: mem.Allocator.alignedAlloc__anon_60282 (Allocator.zig:193)
==1663319==    by 0x5E183AD: array_list.ArrayListAligned(u8,null).ensureTotalCapacityPrecise (array_list.zig:457)
==1663319==    by 0x5D67EFD: array_list.ArrayListAligned(u8,null).ensureTotalCapacity (array_list.zig:434)
==1663319==    by 0x624CD35: array_list.ArrayListAligned(u8,null).resize (array_list.zig:389)
==1663319==    by 0x624A9C2: link.Dwarf.DeclState.addDbgInfoType (Dwarf.zig:508)
==1663319==    by 0x6244061: link.Dwarf.commitDeclState (Dwarf.zig:1439)
==1663319==    by 0x64D4967: link.Elf.ZigObject.updateFunc (ZigObject.zig:1108)
==1663319==    by 0x64D651B: link.Elf.updateFunc (Elf.zig:3027)

Expected Behavior

Never write undefined memory to the output file. Padding should be omitted, or set to zero bytes before passing the data to the kernel.


Related:

  • #13538

andrewrk avatar Mar 22 '24 03:03 andrewrk