Skip to content

AVR cross-compilation leads to invalid bitcast #3645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
schroffl opened this issue Nov 10, 2019 · 4 comments · Fixed by #3911
Closed

AVR cross-compilation leads to invalid bitcast #3645

schroffl opened this issue Nov 10, 2019 · 4 comments · Fixed by #3911
Labels
arch-avr 8-bit AVR
Milestone

Comments

@schroffl
Copy link
Contributor

schroffl commented Nov 10, 2019

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.

@prazzb
Copy link
Contributor

prazzb commented Nov 11, 2019

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

@schroffl
Copy link
Contributor Author

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.

@andrewrk andrewrk added this to the 1.0.0 milestone Nov 11, 2019
@prazzb
Copy link
Contributor

prazzb commented Nov 13, 2019

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

@schroffl
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-avr 8-bit AVR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants