ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.21k stars 2.57k forks source link

Unable to omit unwind tables from binary when using ReleaseSmall + LLVM #21942

Open wooster0 opened 3 weeks ago

wooster0 commented 3 weeks ago

Zig Version

0.14.0-dev.2164+6b2c8fc68

Steps to Reproduce and Observed Behavior

$ cat x.zig
pub fn main() void {}
$ zig build-exe x.zig -fno-unwind-tables -OReleaseSmall
error: <inline asm>:1:3: this directive must appear between .cfi_startproc and .cfi_endproc directives
         .cfi_undefined %rip
         ^

$

Expected Behavior

Successful compilation.

Rexicon226 commented 3 weeks ago

This is the line of inline asm that's causing this: https://github.com/ziglang/zig/blob/e5f5229fd6f9d0fe684ab32cce8f2b18e02c115b/lib/std/start.zig#L250 added in f289b82d0efda77b72ccf9c826023e904f9ffcab

alexrp commented 3 weeks ago

I have an upcoming PR that improves the compiler's handling of unwind tables, including adding a builtin.unwind_tables decl. With that, we can more easily decide whether to emit the .cfi_undefined directive.

Similar fix is needed in clone().

alexrp commented 1 week ago

22035 is the first step here. We'll need a zig1.wasm update before we can actually start using @import("builtin").unwind_tables in standard library code, though.