#Get assembly output of binary or full build

1 messages · Page 1 of 1 (latest)

vapid kettle
#

Is it currently possible to get the assembly output of a binary (EXE) or full build?

When I want to see assembly code with Golang, I can do the following:
go build && go tool objdump test.exe > test.sout

Generally that gives me assembly corresponding to line numbers/functions and whatnot.

FYI: I'm a Windows user if that helps.

vapid kettle
#

Nm figured it out!

Updated my build to have the following:

exe.emit_asm = .emit;

ie. My full config

const std = @import("std");
const Sdk = @import("deps/SDL.zig/Sdk.zig"); // Import the Sdk at build time

pub fn build(b: *std.Build.Builder) !void {
    // Determine compilation target
    const target = b.standardTargetOptions(.{});

    // Create a new instance of the SDL2 Sdk
    const sdk = Sdk.init(b, null);

    // Create executable for our example
    const exe = b.addExecutable(.{
        .name = "game",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target, // must be done before calling sdk.link
        // .use_llvm = false,
        // .use_lld = false,
    });
    sdk.link(exe, .dynamic); // link SDL2 as a shared library

    // Add "sdl2" package that exposes the SDL2 api (like SDL_Init or SDL_CreateWindow)
    exe.addModule("sdl2", sdk.getNativeModule());

    // Add stb_image
    exe.addCSourceFile("deps/stb_image/stb_image_impl.c", &[_][]const u8{"-std=c99"});
    exe.addIncludePath("deps/stb_image");
    exe.addModule("stb_image", b.createModule(.{
        .source_file = .{ .path = "deps/stb_image/stb_image.zig" },
    }));

    // Install the executable into the prefix when invoking "zig build"
    b.installArtifact(exe);

    // const run_cmd = b.addRunArtifact(exe);
    // run_cmd.step.dependOn(b.getInstallStep());

    // const run_step = b.step("run", "Run the app");
    // run_step.dependOn(&run_cmd.step);
    exe.emit_asm = .emit;
}
#

If anyone has further insight into getting a bit more details out of it like mapping the assembly to the source file and line number like the aforementioned objdump example with Go code, that'd be great though.

heavy totem
#

I don't think there's currently a way of doing that unfortunately, not directly with build.zig or the command line directly anyway

#

so taking a look at that might be worthwhile

vapid kettle
wet quartz
#

objdump -S -l file