Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/bridge/cuda/EXTENSION-PROPOSAL.md # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / bridge / cuda / EXTENSION-PROPOSAL.md` 118 lines · 6915 bytes Raw Blame History Rendered 1 # Extension proposal: omc emits a C-ABI shared library 2 3 CUDApp's `compat/nvml/libnvidia-ml.c` is C generated by the omega-bridge cabi-1 emitter from the 4 Omega unit already in this tree, `gpu/nvidia/native/nvml/api.om` (with `nvml.om`, `query.om`, 5 `step.om`, `errstr.om`). The C exists for one reason: `seed/out/omc` cannot write a shared library 6 that a C program loads with `dlopen` or links with `-lnvidia-ml`. This file records what omc emits 7 today, the smallest program that shows the gap, and the extension that closes it. Until that 8 extension exists the generated C stays in CUDApp and is not copied here. 9 10 ## What the in-tree omc emits today 11 12 Compiler: `seed/out/omc`, sha256 ``26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991`` 13 (omega-mv ``2ee0a70d``). Measured 2026-11-14 on an aarch64 Linux host. 14 15 Program mode (a unit with `fn main`): a static AArch64 executable. 16 17 ``` 18 $ printf 'fn main to int\nret 0\nend\n' | seed/out/omc > p.bin; readelf -h p.bin | grep -E 'Type|Machine' 19 Type: EXEC (Executable file) 20 Machine: AArch64 21 $ readelf -lW p.bin | grep -E 'LOAD|DYNAMIC|INTERP' 22 LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x0000d4 0x0000d4 R E 0x1000 23 LOAD 0x000000 0x0000000010000000 0x0000000010000000 0x000000 0x800000 RW 0x1000 24 $ readelf -SW p.bin 25 There are no sections in this file. 26 ``` 27 28 `ET_EXEC`, two `PT_LOAD`, no `PT_INTERP`, no `PT_DYNAMIC`, no sections, no symbols. 29 30 Function mode (no `fn main`; `export fn` in OM-2): raw machine words, no file header. The words 31 start with one branch per `export fn`, in source order, to that function's body; the host must 32 know the offsets. 33 34 ``` 35 $ cat nvml_shutdown.om 36 om2 37 note smallest shared-library request: one C-ABI export the NVML subset needs 38 export fn nvmlShutdown to int 39 ret 0 40 end 41 $ seed/out/omc < nvml_shutdown.om > out.bin; echo rc=$?; wc -c < out.bin; od -An -tx1 out.bin 42 rc=0 43 12 44 01 00 00 14 00 00 80 d2 c0 03 5f d6 45 $ readelf -h out.bin 46 readelf: Error: out.bin: Failed to read file header 47 ``` 48 49 (`b +4; mov x0, #0; ret`. With two exports the output starts `02 00 00 14 03 00 00 14`.) 50 sha256: `nvml_shutdown.om` ``3908d946`…`a84a48a58``, `out.bin` ``323a7cc8`…`a586839``. 51 52 Calling a C function the unit does not define is refused: 53 54 ``` 55 $ printf 'om2\nexport fn nvmlShutdown to int\nret omega2_nvrm_close_file 3\nend\n' | seed/out/omc > imp.bin 56 omc: line 3: error 3 57 ``` 58 59 And the export count is capped: 32 `export fn` compile, the 33rd is `omc: line 98: error 14`. 60 61 ## What it cannot emit, against what `libnvidia-ml.so.1` needs 62 63 | Needed by the NVML library | omc today | 64 |---|---| 65 | `ET_DYN` file, position independent, loadable by `ld.so` | no: `ET_EXEC` at fixed addresses, or headerless words | 66 | `PT_DYNAMIC` with `DT_SONAME libnvidia-ml.so.1`, `DT_SYMTAB`, `DT_STRTAB`, `DT_HASH`/`DT_GNU_HASH` | no dynamic segment at all | 67 | The named exports of `libnvidia-ml.map` (`nvmlInit_v2` … `nvmlDeviceGetComputeRunningProcesses_v3`), and nothing else exported (the `.map`'s `local: *;`) | exports are unnamed branch slots, of a number fixed by omc | 68 | AAPCS64 calls in: arguments in x0..x7, pointers into the caller's memory, `int32` status returns | the slot calling convention is omc's own; not checked against AAPCS64 | 69 | Imports resolved at load: `omega2_nvrm_open_file`, `omega2_nvrm_close_file`, `omega2_nvrm_ioctl` (from the loading process) | a name the unit does not define is error 3 | 70 | Process-wide lock around shared state (`note cabi lock NvLock process mutex`; the C uses `pthread_mutex_*`) and per-thread trap recovery (the C uses `_Thread_local` and `setjmp`) | `x = atomic`, `cas`, `futex`, `thread`, `lock`, `syscall` are each `error 3` (unknown name); `seed/omc/omc.om:8129`: "No raw address or arbitrary syscall is exposed to an Omega program." | 71 | Writable process state (the globals `NvS`, `NvB`, `NvR`, `NvT`, `NvO` of `api.om`, sized there) relocated with the library | program mode puts writable data in a `PT_LOAD` at the fixed address `0x10000000` (above); function mode output carries no data segment or relocations | 72 73 ## The extension 74 75 A third output mode of omc, selected by a unit-level line (proposed spelling, to be checked against 76 the keyword table before it is added): 77 78 ``` 79 library libnvidia-ml.so.1 80 import fn omega2_nvrm_ioctl fd int nr uint hl view uchar * pl view uchar * to int 81 export fn nvmlShutdown to int 82 ... 83 ``` 84 85 1. `library NAME` makes the output an AArch64 `ET_DYN` ELF with `DT_SONAME NAME`, one `PT_LOAD` 86 for code, one for data and `PT_DYNAMIC`; all code position independent (`adrp`/`add` for 87 globals), globals in the library's own writable segment with `R_AARCH64_RELATIVE` where needed. 88 2. Each `export fn` becomes a `.dynsym` entry `STB_GLOBAL STT_FUNC` with its name; every other 89 function is local, which is what the version script did. The export count is sized from the 90 unit (no limit of 32; per the no-hard-caps rule an alarm test replaces it). 91 3. Each `import fn` adds an undefined `.dynsym` entry, a PLT stub and an 92 `R_AARCH64_JUMP_SLOT` relocation; `import fn … from LIB` adds `DT_NEEDED LIB`. Without `from`, 93 the symbol is resolved from the loading process, as `api.om`'s transport imports are. 94 4. Exports and imports follow AAPCS64: integer and pointer arguments in x0..x7, result in x0, 95 x19..x28 and sp preserved. `view T *` maps to one pointer argument plus a length argument, as 96 cabi-1's `span` does. 97 5. A `lock NAME` word in library mode lowers to a futex-based mutex (`svc` with `__NR_futex`), 98 so no libc import is needed; trap recovery uses a per-thread slot reached through `tpidr_el0`. 99 100 The dynamic-section layout is not new work: `bridge/cuda/fixture.om` already writes an `ET_DYN` 101 library from Omega (the link-only `libcuda.so.1` stub: `.dynstr`, `.dynsym`, `.hash`, `.dynamic` 102 with `DT_SONAME`, symbols in GNU `ld`'s own order). The `bridge-cuda` gate's oracle tier (run with 103 `BRIDGE_CUDA_CUDAPP` and `BRIDGE_CUDA_OLDOMC` set) shows gcc links against it to the 104 byte-identical executables of the frozen profiles; a default run does not run gcc and does not 105 show this. The compiler change adds code, relocations and imports to that layout. 106 107 ## How it would be accepted 108 109 - `api.om` compiled by the new omc gives a library for which `readelf -d` shows 110 `SONAME libnvidia-ml.so.1`, `nm -D --defined-only` lists exactly the exports of 111 `libnvidia-ml.map`, and `nm -D --undefined-only` lists exactly the three transport imports. 112 - CUDApp's existing NVML caller test (`tests/nvml/nvml_test.c` over the fake resource manager) 113 passes against it as it does against the cabi-1 C build. 114 - A mutant `api.om` with one export renamed is refused by that comparison. 115 - Then `compat/nvml/` is deleted from CUDApp, and the C emitter is no longer on this path. 116 117 Status: PROPOSED. Nothing above is implemented; the measurements in the first section are 118 EXERCISED with the commands shown.