From 4a8b3151b97eb350c953090d229cae07b440edd7 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 19 Feb 2025 17:13:30 +0200 Subject: [PATCH] examples: add minimal_c_like_program_using_puts.v showing how to produce a much smaller executable on Linux, using clang, mold and sstrip. --- examples/minimal_c_like_program_using_puts.v | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/minimal_c_like_program_using_puts.v diff --git a/examples/minimal_c_like_program_using_puts.v b/examples/minimal_c_like_program_using_puts.v new file mode 100644 index 0000000000..6a4cb2b02a --- /dev/null +++ b/examples/minimal_c_like_program_using_puts.v @@ -0,0 +1,14 @@ +module no_main + +// Compile with: +// v -cc clang -prod -gc none -cflags '-s -fuse-ld=mold' -o hw examples/minimal_c_like_program_using_puts.v && ll hw && sstrip -z hw && ll hw +// With clang-10, on Ubuntu 20.04, it produces an executable with a size of 2331 bytes, after stripping. +// Note: the above uses sstrip 2.1 (from https://git.sr.ht/~breadbox/ELFkickers) and mold 2.32.0 (from https://github.com/rui314/mold). + +fn C.puts(const_msg &char) int + +@[export: 'main'] +fn hello() int { + C.puts(c'Hello world') + return 0 +}