Skip to content

AVR cross-compilation leads to invalid bitcast #3645

Closed

Description

@schroffl

This is semi-related to #3634. @MasterQ32 made me aware of the setTarget deprecation. After replacing that call with setTheTarget I am now getting a different error:

broken LLVM module found: Invalid bitcast
void (%"[]u8"*, %std.builtin.StackTrace*)* bitcast (void (%"[]u8"*, %std.builtin.StackTrace*) addrspace(1)* @panic to void (%"[]u8"*, %std.builtin.StackTrace*)*)

These are the relevant files:

src/main.zig

const std = @import("std");
const builtin = @import("builtin");

pub nakedcc fn _start() noreturn {
    while (true) {}
}

pub fn panic(msg: []const u8, trace: ?*builtin.StackTrace) noreturn {
    while (true) {}
}

build.zig

const std = @import("std");
const Builder = std.build.Builder;
const builtin = @import("builtin");

pub fn build(b: *Builder) void {
    const mode = b.standardReleaseOptions();
    const exe = b.addExecutable("zig-avr", "src/main.zig");
    exe.setBuildMode(mode);
    exe.setTheTarget(std.Target{
        .Cross = std.Target.Cross{
            .arch = .avr,
            .os = .freestanding,
            .abi = .eabi,
        },
    });
    exe.install();

    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

I am running zig 0.5.0+d18b5f8b5 on macOS 10.15.

Activity

  1. prazzb commented on Nov 11, 2019

    @prazzb
    Contributor

    last I checked avr-lld is in very bad shape so I will be very surprised if there is an avr elf output..... however, avr-llvm is pretty good and there should've been proper .o files when used with build-obj command line option

  2. schroffl commented on Nov 11, 2019

    @schroffl
    ContributorAuthor

    So I tried to only build the object file with zig, but running zig build-obj -target avr-freestanding-eabi src/main.zig yields the same error.

  3. added this to the 1.0.0 milestone on Nov 11, 2019
  4. prazzb commented on Nov 13, 2019

    @prazzb
    Contributor

    I tested with 0.5.0 from zig website and doing
    zig build-obj -target avr-freestanding-eabi src/main.zig
    does compile giving .h and .o file

    It seems something else in the interim has broken this

  5. schroffl commented on Nov 14, 2019

    @schroffl
    ContributorAuthor

    Huh, weird. I currently cannot test it myself, but I will try it with a newer zig version as soon as possible.

  6. added a commit that references this issue on Dec 15, 2019
    257cbc9
  7. added a commit that references this issue on Dec 15, 2019
    f1407b4
  8. modified the milestones: 1.0.0, 0.6.0 on Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-avr

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions