me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Exercise LLVM 17 and 19 native code generation for Mesa

diviocity committed 5 days ago · 0ea984f3e8f435039dc8079e50bb3fea133ffce2 View patch
Unverified signature 2 files changed +62 -0
tests/x11/README.md +2 -0

@@ -36,3 +36,5 @@ The font test installed `mkfontscale` and both bitmap font packages by name. The

3636The headless server test installed `xvfb`, `xauth`, `xset`, `xrdb` and BusyBox by name. The x86-64 root contained 36 PGP-validated packages, 5,738 owned file and link paths and 68 target ELFs. On the release kernel, `headless.sh` started the packaged Xvfb with TCP disabled, authenticated a client, drew a pixmap and checked the returned pixel. The client also wrote and read back an X resource. A new connection with an empty authority file correctly failed. The 384 MiB, one-vCPU guest transcript and ISO checksum are under `~/.local/state/vinix/ports/musl-busybox-CqkBEA/xorg/worker/guest-xvfb-03`.

3737

3838On the released AArch64 kernel, `modeline-font.sh` ran the source-built `cvt` and `bdftopcf` executables that require 16 KiB page alignment. It computed a 640×480 modeline and regenerated the release PCF cursor from its upstream BDF. The cursor matched SHA-256 `ad72bdd05b8baf48fd988dd08ee64a7b9ab4e04c3c72db3c4bc74ae01b7a6246`. The one-vCPU, 384 MiB guest used seven signed packages containing 559 owned paths and twelve target ELFs. Evidence is under `~/.local/state/vinix/ports/musl-busybox-CqkBEA/xorg/worker/arm16-guest-tools-02`.

39+

40+The LLVM fixture compiles a two-argument integer addition function from LLVM IR, obtains its native address and calls it with positive and negative inputs. Before using it on the candidate runtime, we ran it twice in the build-only Alpine environment, once with `libLLVM-17.so` and once with `libLLVM.so.19.1`. Both returned the expected sums. The per-version `DT_NEEDED` records and transcripts are under `~/.local/state/vinix/ports/musl-busybox-CqkBEA/xorg/worker/llvm-probe-fixture-02`. Runtime acceptance also requires repeating these executions with the source-built Vinix packages on each release kernel.

tests/x11/llvm.v new file +60 -0

@@ -0,0 +1,60 @@

1+// Execute LLVM-generated machine code with the runtime used by software Gallium.

2+module main

3+

4+#include <llvm-c/Core.h>

5+#include <llvm-c/ExecutionEngine.h>

6+#include <llvm-c/IRReader.h>

7+#include <llvm-c/Target.h>

8+

9+fn C.LLVMContextCreate() voidptr

10+fn C.LLVMContextDispose(voidptr)

11+fn C.LLVMCreateMemoryBufferWithMemoryRangeCopy(&char, usize, &char) voidptr

12+fn C.LLVMParseIRInContext(voidptr, voidptr, voidptr, &&char) int

13+fn C.LLVMDisposeMessage(&char)

14+fn C.LLVMLinkInMCJIT()

15+fn C.LLVMInitializeNativeTarget() int

16+fn C.LLVMInitializeNativeAsmPrinter() int

17+fn C.LLVMCreateJITCompilerForModule(voidptr, voidptr, u32, &&char) int

18+fn C.LLVMDisposeExecutionEngine(voidptr)

19+fn C.LLVMGetFunctionAddress(voidptr, &char) u64

20+

21+type Add = fn (i32, i32) i32

22+

23+fn execute() ! {

24+ C.LLVMLinkInMCJIT()

25+ if C.LLVMInitializeNativeTarget() != 0 || C.LLVMInitializeNativeAsmPrinter() != 0 {

26+ return error('LLVM did not initialize the native target and assembly printer')

27+ }

28+ context := C.LLVMContextCreate()

29+ defer { C.LLVMContextDispose(context) }

30+ ir := 'define i32 @add(i32 %a, i32 %b) { %sum = add i32 %a, %b ret i32 %sum }'

31+ buffer := C.LLVMCreateMemoryBufferWithMemoryRangeCopy(ir.str, usize(ir.len), c'vinix-guest')

32+ mut program := voidptr(0)

33+ mut message := &char(unsafe { nil })

34+ if C.LLVMParseIRInContext(context, buffer, voidptr(&program), &message) != 0 {

35+ defer { C.LLVMDisposeMessage(message) }

36+ return error(unsafe { cstring_to_vstring(message) })

37+ }

38+ mut engine := voidptr(0)

39+ if C.LLVMCreateJITCompilerForModule(voidptr(&engine), program, 1, &message) != 0 {

40+ defer { C.LLVMDisposeMessage(message) }

41+ return error(unsafe { cstring_to_vstring(message) })

42+ }

43+ defer { C.LLVMDisposeExecutionEngine(engine) }

44+ address := C.LLVMGetFunctionAddress(engine, c'add')

45+ if address == 0 {

46+ return error('LLVM did not emit the add function')

47+ }

48+ add := unsafe { Add(usize(address)) }

49+ if add(19, 23) != 42 || add(-5, 2) != -3 {

50+ return error('generated code returned incorrect sums')

51+ }

52+ println('LLVM generated and executed native addition for both argument pairs.')

53+}

54+

55+fn main() {

56+ execute() or {

57+ eprintln(err)

58+ exit(1)

59+ }

60+}