Created
November 18, 2023 21:27
-
-
Save travisstaloch/02820dc30e694a3baa48d2cddaae49a7 to your computer and use it in GitHub Desktop.
produce a small object file with zig and disassemble
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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