Skip to content
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

Getting Zig example fully working #18

Merged
merged 18 commits into from
Nov 13, 2023
Merged

Getting Zig example fully working #18

merged 18 commits into from
Nov 13, 2023

Conversation

Ivan-Velickovic
Copy link
Collaborator

@Ivan-Velickovic Ivan-Velickovic commented Sep 26, 2023

This PR involves fixes to get the Zig example into a more usable and working state.

Current status is that building with -Doptimize=ReleaseFast and -Doptimize=ReleaseSafe works now.

Building with -DReleaseSmall leads to this error:

examples/zig [zig_example●] ❯ zig build -Dsdk=../../microkit-sdk-1.2.6 qemu -Doptimize=ReleaseSmall
steps [5/10] install vmm.elf... Traceback (most recent call last):
  File "runpy", line 196, in _run_module_as_main
  File "runpy", line 86, in _run_code
  File "microkit.__main__", line 2113, in <module>
  File "microkit.__main__", line 1961, in main
  File "microkit.__main__", line 667, in build_system
  File "microkit.__main__", line 668, in <dictcomp>
  File "microkit.elf", line 327, in from_path
AssertionError
run ../../microkit-sdk-1.2.6/bin/microkit: error: the following command exited with error code 1:
../../microkit-sdk-1.2.6/bin/microkit zig_vmm.system --search-path zig-out/bin --board qemu_arm_virt --config debug -o zig-out/bin/loader.img -r zig-out/report.txt
Build Summary: 6/10 steps succeeded; 1 failed (disable with --summary none)
qemu transitive failure
└─ run qemu-system-aarch64 transitive failure
   └─ microkit transitive failure
      └─ run ../../microkit-sdk-1.2.6/bin/microkit failure
error: the following build command failed with exit code 1:
/Users/ivanv/ts/libvmm/examples/zig/zig-cache/o/7eda09792623d8e930a4e0146e12052a/build /Users/ivanv/zigs/zig-macos-x86_64-0.12.0-dev.494+a8d2ed806/zig /Users/ivanv/ts/libvmm/examples/zig /Users/ivanv/ts/libvmm/examples/zig/zig-cache /Users/ivanv/.cache/zig -Dsdk=../../microkit-sdk-1.2.6 qemu -Doptimize=ReleaseSmall

Either Zig is producing an invalid ELF and the Microkit tool can't handle or there is a bug in the Microkit tool.

Building with -Doptimize=Debug leads to this error:

[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] Root IRQ handler: gic_handle_irq
MON|ERROR: received message 0x00000006  badge: 0x0000000000000001  tcb cap: 0x800000000000240d
MON|ERROR: faulting PD: VMM
Registers:
pc : 0x0000000000222d7c
spsr : 0x0000000040000040
x0 : 0x0000000000000003
x1 : 0x0000000000000000
x2 : 0x0000000000000000
x3 : 0x0000000000000026
x4 : 0x00000000024e6e40
x5 : 0xffff80000a2c0000
x6 : 0x0000000000000000
x7 : 0xffffffffffffffff
MON|ERROR: VMFault: ip=0x0000000000222d7c  fault_addr=0x00000000024e5ff0  fsr=0x0000000093c8804f  (data fault)
MON|ERROR:    ec: 0x00000024  Data Abort from a lower Exception level   il: 1   iss: 0x01c8804f
MON|ERROR:    dfsc = permission fault, level 3 (0x0000000f) -- write not read
<<seL4(CPU 0) [receiveIPC/142 T0x80bffe7400 "rootserver" @8a000310]: Reply object already has unexecuted reply!>>

Other than fixing these issues, the following needs to be done:

  • Clean up build.zig.
  • Fixup README
  • Explain libmicrokit.zig?
  • images dir should not be inside src/
  • Heavily comment both build.zig and vmm.zig for people to understand what's going on.
  • Add all optimisation modes to CI, Debug, ReleaseSmall, ReleaseFast, and ReleaseSafe.
  • Fix weird issue with standard library debug printing with VMM, leading to things like this:
VMM|INFO: starting "{s}"

VMM"

@Ivan-Velickovic
Copy link
Collaborator Author

Ah okay so ReleaseSmall strips the symbol table from the ELF, which makes sense and is perfectly reasonable. This means that Microkit code needs to be changed to expect the symbol table to not exist.

Debug turns on LLVM's UBSAN, turning it off means everything is fine. I guess this means we likely have some UB that needs to be found and removed.

@Ivan-Velickovic
Copy link
Collaborator Author

Actually, having the symbol table is necessary for things setting the PD's IPC buffer. We can just tell Zig to not strip debugging symbols, they won't be loaded at run-time anyways so having debugging symbols in the ELF only increases the on-disk space, which is an acceptable trade-off.

0.12.0-dev.1533+b2ed2c4d4 was used.
It's unclear whether we actually do have UB somewhere in the C code. For
now we turn off UBSAN in order to have the example work in debug mode.
The build system was confusing and I couldn't get this working and gave
up. Now with some new build system documentation I could figure it out.
Having 'src/images/' was done before-hand since I wasn't familiar with
how to include files from 'images' in the VMM if they were outside the
'src' directory.
@Ivan-Velickovic Ivan-Velickovic merged commit 678388b into main Nov 13, 2023
5 checks passed
@Ivan-Velickovic
Copy link
Collaborator Author

Ivan-Velickovic commented Nov 13, 2023

I'll leave the explanation of how libmicrokit.zig is created for another time...

@Ivan-Velickovic Ivan-Velickovic deleted the zig_example branch November 13, 2023 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant