Skip to content

0.3.5 — the forwarder for an optional interface must not demand it - #8

Merged
Sunrisepeak merged 1 commit into
mainfrom
fix/optional-interface-weak-reference
Aug 25, 2026
Merged

0.3.5 — the forwarder for an optional interface must not demand it#8
Sunrisepeak merged 1 commit into
mainfrom
fix/optional-interface-weak-reference

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

A strong reference to kal_random_fill in the syscall dispatcher made an optional interface mandatory: every freestanding program failed to link, whether or not it wanted a random byte.

The weak reference is on the other side of the layer from clause 6.1 — this file implements Linux's syscall ABI, where ENOSYS is the defined answer for a call the kernel does not have.

Proved by removing it again: strong → the link error, weak → text 2490664.

`openkal.random` is optional, and clause 6.1 expresses an implementation
that does not provide it as the absence of a link-time definition. This
dispatcher is linked into every program, so a strong reference to
`kal_random_fill` turned that absence into a failure for programs that
never ask for a random byte:

    ld.lld: error: undefined symbol: kal_random_fill
    >>> referenced by okm_syscall.c:409
    >>>               obj/…/okm_syscall.o:(__okm_syscall)

measured on a bare-metal program over openkal-opensbi, which provides
eight interfaces and not this one. A whole class of programs — every
freestanding one — could not link because one optional interface was
referenced unconditionally.

⚠️ THE WEAK REFERENCE IS NOT THE RUN-TIME REFUSAL CLAUSE 6.1 FORBIDS.
That clause governs an implementation of openkal: one shall not offer an
interface whose operations report a lack of support while running. This
is on the other side of the layer — the file implements Linux's system
call ABI, where `ENOSYS` is that ABI's answer for a call the kernel does
not have, and musl's own `getrandom` is written against that answer.

Both the idiom and the convention were already here and neither was
reached for: `okm_phdr.c` declares `__ehdr_start` weak, and this file's
opening comment says calls that can be told they do not exist return
`-ENOSYS`.

Proved by removing it again rather than by reasoning:

    weak     examples/same-source --target riscv64-none-elf → text 2490664
    strong   the same build                                 → the error above
@Sunrisepeak
Sunrisepeak merged commit cdf550a into main Aug 25, 2026
6 checks passed
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