Closed kulkarniniraj closed 1 year ago
I cannot use Debug mode (some error about zig probe stack not found)
You can use -fcompiler-rt
or -fno-stack-check
to resolve this issue, or use Zig as the linker.
But in zig equivalent I get trap-6 error and program is killed.
Can you share the difference in machine code?
I'm sorry but this is not enough information to confirm the bug. If you're still willing to give this a try, share more information about the generated machine code of Zig and why it is problematic, and I will re-open this.
Sure, I have created C and Zig object files. Can't upload it here. But if you want me to run any command, let me know.
pub fn put_chr(self: Tty, x: u8, y: u8, entry: VgaEntry) void {
_ = y;
_ = x;
self.buffer[0] = entry;
}
works fine.
pub fn put_chr(self: Tty, x: u8, y: u8, entry: VgaEntry) void {
self.buffer[x*y] = entry;
}
error.
run.sh
build=build # build dir
isoname=xfxos.iso # isoname
mkdir -p $build # create build dir
zig build # build with build.zig file
nasm src/boot.s -f elf32 -o build/boot.o # compile multiboot header
ld -m elf_i386 -T linker.ld -o build/isofiles/boot/kernel.bin build/boot.o build/kernel.o # link the kernel
d=build/isofiles/boot/grub
mkdir -p "$d" && cp grub.cfg "$d"
sudo grub-mkrescue -o build/os.iso build/isofiles # create iso
qemu-system-i386 build/os.iso # run with qemu
error:
ld: build/kernel.o: in function `debug.panicExtra__anon_1055':
/home/tengri/.zvm/master/lib/std/debug.zig:358:(.text+0x14b): undefined reference to `__zig_probe_stack'
ld: /home/tengri/.zvm/master/lib/std/debug.zig:363:(.text+0x1bb): undefined reference to `memset'
ld: build/kernel.o: in function `io.writer.Writer(*io.fixed_buffer_stream.FixedBufferStream([]u8),error{NoSpaceLeft},(function 'write')).writeByteNTimes':
/home/tengri/.zvm/master/lib/std/io/writer.zig:37:(.text+0x1442): undefined reference to `memset'
ld: /home/tengri/.zvm/master/lib/std/io/writer.zig:38:(.text+0x1465): undefined reference to `memset'
ld: build/kernel.o: in function `fmt.formatInt__anon_1726':
/home/tengri/.zvm/master/lib/std/fmt.zig:1418:(.text+0x1633): undefined reference to `memset'
ld: build/kernel.o: in function `debug.panicExtra__anon_1812':
/home/tengri/.zvm/master/lib/std/debug.zig:358:(.text+0x1d6b): undefined reference to `__zig_probe_stack'
ld: /home/tengri/.zvm/master/lib/std/debug.zig:363:(.text+0x1ddb): undefined reference to `memset'
ld: build/kernel.o: in function `io.fixed_buffer_stream.FixedBufferStream([]u8).write':
/home/tengri/.zvm/master/lib/std/io/fixed_buffer_stream.zig:70:(.text+0x21b1): undefined reference to `memcpy'
source repo: https://github.com/xfxpositions/xfxos2
i tried
ld -m elf_i386 -fno-stack-check -T linker.ld -o build/isofile
s/boot/kernel.bin build/boot.o build/kernel.o
> ld: -f may not be used without -shared
Zig Version
0.10.0
Steps to Reproduce and Observed Behavior
I am trying to write a simple user mode code in xv6 OS. Following simple C code works perfectly
But in zig equivalent I get trap-6 error and program is killed.
Build commands:
This is especially frustrating since compiler does not give warning and I cannot use Debug mode (some error about zig probe stack not found)
Expected Behavior
Program does not crash