ziglang / zig

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

-target thumb-freestanding-none includes std.target.Arch.isWasm #4715

Open markfirmware opened 4 years ago

markfirmware commented 4 years ago

No linker script shows the problem as well as a typical linker script.

export fn main() void {}

pub fn panic(message: []const u8, trace: ?*@import("std").builtin.StackTrace) noreturn {
    while (true) {}
}

$ zig build-exe -target thumb-freestanding-none main.zig
$ llvm-objdump -x --source zig-cache/bin/main > main.asm
$ grep -i wasm main.asm

0000000000000012 std.target.Arch.isWasm:
; pub fn isWasm(arch: Arch) bool {
      26:   04 d3   blo #8 <std.target.Arch.isWasm+0x20>
      28:   ff e7   b   #-2 <std.target.Arch.isWasm+0x18>
      30:   03 e0   b   #6 <std.target.Arch.isWasm+0x28>
; .wasm32, .wasm64 => true,
      38:   ff e7   b   #-2 <std.target.Arch.isWasm+0x28>
00000012 l     F .text       0000002e std.target.Arch.isWasm
LemonBoy commented 4 years ago

TLDR: Use -ffunction-sections

The compiler generates that function in case you may want to invoke it from a debugger, there's already an open ticket about being able to mark some functions as comptime-only.

markfirmware commented 4 years ago

Thanks. Let me think about that.

markfirmware commented 4 years ago

Ok, -ffunction-sections works.

markfirmware commented 4 years ago

@LemonBoy @andrewrk

How do I add -ffunction-sections in build.zig?

markfirmware commented 4 years ago

https://github.com/ziglang/zig/pull/4746/commits/27be16543e0370f795be0a596f2668a205583e51

@LemonBoy @andrewrk

How do I add -ffunction-sections in build.zig?

Thanks!

frmdstryr commented 4 years ago

Would something like a callconv(.Comptime) work to tag functions intended for comptime only?