Skip to content

Instantly share code, notes, and snippets.

@travisstaloch
Created November 18, 2023 21:27
Show Gist options
  • Save travisstaloch/02820dc30e694a3baa48d2cddaae49a7 to your computer and use it in GitHub Desktop.
Save travisstaloch/02820dc30e694a3baa48d2cddaae49a7 to your computer and use it in GitHub Desktop.
produce a small object file with zig and disassemble
// zig build-obj -fstrip -OReleaseSmall /tmp/tmp.zig -femit-bin=/tmp/tmp.o && objdump -d /tmp/tmp.o
const std = @import("std");
pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, start: ?usize) noreturn {
_ = .{ msg, st, start };
@trap();
}
pub export fn _start() callconv(.Naked) noreturn {
asm volatile (
\\ xorl %%ebp, %%ebp
\\ callq %[startFunction:P]
:
: [startFunction] "X" (&mainFn),
);
}
fn mainFn() void {
// do anything here
_ = std.os.write(1, "hello world") catch unreachable;
std.os.exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment