Skip to content
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

fuzz testing: support macOS #20986

Open
andrewrk opened this issue Aug 8, 2024 · 2 comments
Open

fuzz testing: support macOS #20986

andrewrk opened this issue Aug 8, 2024 · 2 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. fuzzing os-macos
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Aug 8, 2024

Extracted from #20958.

Trying to use --fuzz on macOS right now results in this (reproduce with zig init):

andy@Andrews-MBP abc % zig build test --fuzz
info: web interface listening at http://127.0.0.1:56813/
info: hint: pass --port 56813 to use this same port next time
error: step 'run test': failed to load debug information for '/Users/andy/tmp/abc/.zig-cache/o/52bd85d2709e39b1f21486f283727281/test': InvalidElfMagic
thread 8357656 panic: attempt to use null value
/Users/andy/dev/zig/lib/std/Build/Fuzz/WebServer.zig:650:63: 0x10092e007 in addEntryPoint (build)
    const coverage_map = ws.coverage_files.getPtr(coverage_id).?;
                                                              ^
/Users/andy/dev/zig/lib/std/Build/Fuzz/WebServer.zig:552:56: 0x1008cb0db in coverageRun (build)
            .entry_point => |entry_point| addEntryPoint(ws, entry_point.coverage_id, entry_point.addr) catch |err| switch (err) {
                                                       ^
/Users/andy/dev/zig/lib/std/Thread.zig:409:13: 0x100860ac3 in callFn__anon_17378 (build)
            @call(.auto, f, args);
            ^
/Users/andy/dev/zig/lib/std/Thread.zig:678:30: 0x1008096bf in entryFn (build)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x19dec026b in ??? (libsystem_pthread.dylib)
???:?:?: 0xb37c80019debb08b in ??? (???)
error: the following build command crashed:
/Users/andy/tmp/abc/.zig-cache/o/9cd3d93aaf58e80ab03f0c3c3e468034/build /Users/andy/dev/zig/build-assert/stage3/bin/zig /Users/andy/dev/zig/lib /Users/andy/tmp/abc /Users/andy/tmp/abc/.zig-cache /Users/andy/.cache/zig --seed 0x2d1b321 -Z59eacecfcf979b53 test --fuzz

Not sure why that crash happens, that is a separate bug that should be addressed first.

But the main reason macOS is not supported yet is that this code incorrectly assumes ELF:

pub fn load(gpa: Allocator, path: Path, coverage: *Coverage) LoadError!Info {
var sections: Dwarf.SectionArray = Dwarf.null_section_array;
var elf_module = try Dwarf.ElfModule.loadPath(gpa, path, null, null, &sections, null);
try elf_module.dwarf.sortCompileUnits();
var info: Info = .{
.address_map = .{},
.coverage = coverage,
};
try info.address_map.put(gpa, elf_module.base_address, elf_module);
return info;
}

Zig has MachO support for debug info in the standard library already, only some straightforward glue code is missing.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-macos fuzzing labels Aug 8, 2024
@andrewrk andrewrk added this to the 0.14.0 milestone Aug 8, 2024
@jrasanen
Copy link

jrasanen commented Oct 7, 2024

On an Apple Silicon M3 Pro I get the following:

jussiras@R4427 ~/tmp> mkdir foobar
jussiras@R4427 ~/tmp> cd foobar
jussiras@R4427 ~/t/foobar> zig init
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see zig build --help for a menu of options
jussiras@R4427 ~/t/foobar> zig build test --fuzz
test
└─ run test
└─ zig test Debug native failure
error: LLVM ERROR: Global variable '_sancov_gen.0' has an invalid section specifier '__sancov_cntrs': mach-o section specifier requires a segment and section separated by a comma.

error: the following command terminated unexpectedly:
/Users/jussiras/local/bin/zig test -ffuzz -ODebug -Mroot=/Users/jussiras/tmp/foobar/src/main.zig --cache-dir /Users/jussiras/tmp/foobar/.zig-cache --global-cache-dir /Users/jussiras/.cache/zig --name test --zig-lib-dir /Users/jussiras/local/lib/ --listen=-
error: one or more unit tests failed to be rebuilt in fuzz mode
error: the following build command failed with exit code 1:
/Users/jussiras/tmp/foobar/.zig-cache/o/ada4088d82150dbb81c5fce270c5a619/build /Users/jussiras/local/bin/zig /Users/jussiras/local/lib /Users/jussiras/tmp/foobar /Users/jussiras/tmp/foobar/.zig-cache /Users/jussiras/.cache/zig --seed 0xd8e701d3 -Z3272a6e6ddb67b07 test --fuzz

I built Zig using:

mkdir build
cmake .. -DZIG_STATIC_LLVM=ON -DCMAKE_PREFIX_PATH="$(brew --prefix llvm@19);$(brew --prefix lld);$(brew --prefix zstd)"
make install

Latest commit I have is:

ea527f7a850f0200681630d8f36131eca31ef48b (HEAD -> master, origin/master, origin/HEAD) Merge pull request #21618 from mlugg/validate-runtime-value]

@dravenk
Copy link
Sponsor Contributor

dravenk commented Oct 9, 2024

I got this message.

Chip:  Apple M2 Max
MacOS version:15.0 (24A335)
image
test
└─ run test
   └─ zig test Debug native failure
error: LLVM ERROR: Global variable '__sancov_gen_.0' has an invalid section specifier '__sancov_cntrs': mach-o section specifier requires a segment and section separated by a comma.

error: the following command terminated unexpectedly:
/Users/dk/src/zig/zig/build/stage3/bin/zig test -ffuzz -ODebug -Mroot=/Users/dk/projects/mine/temp/foobar/src/main.zig --cache-dir /Users/dk/projects/mine/temp/foobar/.zig-cache --global-cache-dir /Users/dk/.cache/zig --name test --zig-lib-dir /Users/dk/src/zig/zig/lib/ --listen=- 
error: one or more unit tests failed to be rebuilt in fuzz mode
error: the following build command failed with exit code 1:
/Users/dk/projects/mine/temp/foobar/.zig-cache/o/52390df78d3fd86f945441816598bdf6/build /Users/dk/src/zig/zig/build/stage3/bin/zig /Users/dk/src/zig/zig/lib /Users/dk/projects/mine/temp/foobar /Users/dk/projects/mine/temp/foobar/.zig-cache /Users/dk/.cache/zig --seed 0xa9704b18 -Z13dfa00cabd04d4d test --fuzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. fuzzing os-macos
Projects
None yet
Development

No branches or pull requests

3 participants