#Return type of container level assembly

1 messages · Page 1 of 1 (latest)

unique viper
#

I am trying to initialize vector_table for AVR. For that purpose the next code is used:

export const vector_table linksection(".vectors") = blk: {
  // do some checks
  var asm_str: []const u8 = "jmp _start\n";
  // do some more stuff
  asm_str = asm_str ++ new_insn ++ "\n";
  break blk: asm (asm_str);
}

Zig infers the type of break expression to void. Compilation fails with:

src/start.zig:7:1: error: unable to export type 'void'

So how it should be done it the right way?

#

it seems that it is impossible to export container scoped assembly

#

as return type of asm () container level expression is void

#

Ok, as I have taken this code from github, it seems that it is outdated and I should use @export instead

#

So, it seems that avr is quite broken, as compilation fails due to internal error

#
/usr/lib/zig/lib/std/builtin.zig:861:9: error: expected type 'fn([]const u8, ?*builtin.StackTrace, ?usize) noreturn', found 'fn([]const u8, ?*builtin.StackTrace) noreturn'
#

zig version: 0.11.0-dev.3312+ab37ab33c

ebon trellis
#

is that the complete error? To me that looks like you're setting the panic function to something with the wrong type

unique viper
#

full output

zig build-exe avr-arduino-zig Debug native: error: the following command failed with 1 compilation errors:
/usr/lib/zig/zig build-exe /home/username/programming/projects/remote/avr-arduino-zig/src/start.zig -femit-asm --cache-dir /home/username/programming/projects/remote/avr-arduino-zig/zig-cache --global-cache-dir /home/username/.cache/zig --name avr-arduino-zig -fno-compiler-rt -target avr-freestanding-none -mcpu atmega328p --script /home/username/programming/projects/remote/avr-arduino-zig/src/linker.ld --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with -fno-summary)
install transitive failure
├─ install avr-arduino-zig transitive failure
│  └─ zig build-exe avr-arduino-zig Debug native 1 errors
└─ zig build-exe avr-arduino-zig Debug native (reused)
/usr/lib/zig/lib/std/builtin.zig:861:9: error: expected type 'fn([]const u8, ?*builtin.StackTrace, ?usize) noreturn', found 'fn([]const u8, ?*builtin.StackTrace) noreturn'
    root.panic
    ~~~~^~~~~~
/usr/lib/zig/lib/std/builtin.zig:861:9: note: function with 2 parameters cannot cast into a function with 3 parameters
referenced by:
    addFeature: /usr/lib/zig/lib/std/target.zig:719:21
    featureSet: /usr/lib/zig/lib/std/target.zig:781:30
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
#

ok, so for some strange reason error message hasn't mentioned where exactly error came from, but I guess I have figured it out

#

So, I have solved the problem with panic

#

the issue with asm is still relevant though

#

how can I see the vervose output of build command. option verbose does not seems to work as I expect (it prints only command executed, not their error output)

unique viper
#

it seems that zig build crashes itself

#

Perhaps I need to compile zig from source code in debug mode to see more verbose error message

hoary citrus
#

this isn't container scoped, you're just trying to return void from a comptime block it looks like

#

wrap the block in asm like asm(blk: { <your code> break :blk code; }) and I don't see why it wouldn't work?

#

what your code is trying to do is evaluate the assembly at comptime which doesn't make any sense

unique viper
#

here the code

#

I have applied your advise, but unfortunatly it does not work 😦

unique viper
#

the original code is not mine, and I haven't understood it fully yet

unique viper
#

ok, I have updated the compiler to most recent commit and it seems to report error messages correctly now

#

though still requires more investigation

unique viper
#

it seems to compile correctly now

#

one more question, is how to disable memcpy and other std functions being emmited into assembly

#

here the deploy happens to bare metal, so there are no such functions present

#

in C there is a flag -fno-builtin which disables these functions

#

zig does not udnerstand it

#

although freestanding is set in build.zig, this still does not help much