zig icon indicating copy to clipboard operation
zig copied to clipboard

Compilation failure on latest mater for target AVR25 (ATTiny13A MCU)

Open seletskiy opened this issue 1 year ago • 1 comments

Zig Version

0.14.0-dev.1632+d83a3f174

Steps to Reproduce and Observed Behavior

Minimal case to repro:

  • build.zig.zon

    .{
        .name = "tmp.CsP3FWngBQ",
        .version = "0.0.0",
        .paths = .{
            "build.zig",
            "build.zig.zon",
            "src",
        },
    }
    
  • build.zig

    const std = @import("std");
    
    pub fn build(b: *std.Build) void {
        const target = b.resolveTargetQuery(std.Target.Query{
            .cpu_arch = .avr,
            .cpu_model = .{ .explicit = &std.Target.avr.cpu.attiny13a },
            .os_tag = .freestanding,
            .abi = .none,
        });
    
        const optimize = std.builtin.OptimizeMode.ReleaseSmall;
    
        const exe = b.addExecutable(.{
            .name = "tmp.CsP3FWngBQ",
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
        });
    
        b.installArtifact(exe);
    }
    
  • src/main.zig

    pub export fn _start() void {}
    

zig build output:

install
└─ install tmp.CsP3FWngBQ
   └─ zig build-exe tmp.CsP3FWngBQ ReleaseSmall avr-freestanding-none failure
error: error: <unknown>:0: out of range branch target (expected an integer in the range -4096 to 4095)

Expected Behavior

Code compiles successfully. Confirmed to work on 0.13.0.

seletskiy avatar Sep 22 '24 06:09 seletskiy

Haven't looked closely at this yet, but my suspicion would be that this is fixed by https://github.com/llvm/llvm-project/pull/109124.

alexrp avatar Sep 22 '24 07:09 alexrp

Seems like https://github.com/llvm/llvm-project/pull/118015 might resolve this.

alexrp avatar Nov 28 '24 17:11 alexrp

Note that there's also a follow-up pull request - https://github.com/llvm/llvm-project/pull/121498.

Patryk27 avatar Jan 02 '25 16:01 Patryk27

Status: there's a backport ready, but it won't be accepted, because LLVM 20 is already on its way - if you want, you can pull it manually to Zig:

https://github.com/llvm/llvm-project/pull/125081

Patryk27 avatar Feb 11 '25 07:02 Patryk27

I've merged https://github.com/ziglang/zig-bootstrap/pull/207 so the fix for this will be included in Zig 0.14.1. For master, it'll be fixed with #22780.

Thanks @Patryk27!

alexrp avatar Mar 09 '25 08:03 alexrp