Skip to content

feat(libbboeos): link clang-compiled exports into the shared blob#445

Merged
bboe merged 1 commit into
mainfrom
bboe/libbboeos-phase3-strcmp
May 20, 2026
Merged

feat(libbboeos): link clang-compiled exports into the shared blob#445
bboe merged 1 commit into
mainfrom
bboe/libbboeos-phase3-strcmp

Conversation

@bboe
Copy link
Copy Markdown
Owner

@bboe bboe commented May 20, 2026

Summary

First concrete step toward Phase 3 of the shared-libbboeos design (spec). Wire `user/libbboeos/libbboeos.a` (clang-compiled libc bodies) into the same `build/libbboeos` blob as the asm vDSO helpers, gated by `--gc-sections` + `-ffunction-sections` so unreferenced functions are dropped.

Concretely:

  • `user/libbboeos/Makefile` gains `-ffunction-sections -fdata-sections`.
  • `libbboeos.ld` absorbs `(.text .text.)` / `(.rodata .rodata.)` into the existing output sections; new `EXTERN(strcmp)` forces archive resolution. Pointer table grows by one `LONG(strcmp)` entry at offset 0x34.
  • `make_os.sh` links the .a alongside the nasm-built vdso.o:
    ```
    ld -m elf_i386 -T libbboeos.ld --gc-sections -o libbboeos.elf libbboeos.o libbboeos.a
    ```
  • `constants.asm` exposes `FUNCTION_STRCMP_PTR`.
  • `VDSO_SIGRETURN_OFFSET` moves `0x460` → `0xFE0` so the helper region can grow past 1 KB. Sigreturn now sits near the end of page 0, past the pointer table at `0x800..0x83C`. No ABI break — kernel `signal_dispatch_user` references the constant symbolically.

`build/libbboeos` grows from 2100 → 4068 bytes (still single-page; strcmp body is 0x3D bytes, the rest of the growth is the sigreturn relocation extending the file out to 0xFE4).

What's NOT in this PR

The cc.py-side wiring — the extern-call fallback that emits `call [FUNCTION__PTR]` for unknown names — lands in a follow-up. This commit is purely the build-pipeline plumbing that makes `strcmp` reachable in the blob.

Test plan

  • `./make_os.sh` clean
  • `build/libbboeos.map` shows `strcmp` at `0x10410`, pointer at `0x10834` (= `FUNCTION_STRCMP_PTR`)
  • `tests/test_asm.py` — 42/42 pass
  • `tests/test_programs.py` — 89/89 pass (signal-handling exercise via shell intact post-sigreturn relocation)
  • `tests/test_bboefs.py` — 6/6 pass
  • `tests/test_pipeline_*.py` — 7/7 pass
  • `pytest tests/unit/` — 455/455 pass

🤖 Generated with Claude Code

@bboe bboe force-pushed the bboe/libbboeos-phase3-strcmp branch from e7a7046 to 0c3378b Compare May 20, 2026 08:37
First concrete step toward Phase 3 of the shared-libbboeos design:
wire `user/libbboeos/libbboeos.a` (clang-compiled libc bodies) into
the same `build/libbboeos` blob as the asm vDSO helpers, gated by
`--gc-sections` + `-ffunction-sections` so unreferenced functions
are dropped.

Concretely:

  - Makefile gains `-ffunction-sections -fdata-sections` so ld can
    drop unreachable per-function sections.
  - libbboeos.ld absorbs `*(.text .text.*)` / `*(.rodata .rodata.*)`
    into the existing output sections; new `EXTERN(strcmp)` forces
    archive resolution.  Pointer table grows by one LONG(strcmp)
    entry at offset 0x34.
  - make_os.sh links the .a alongside the nasm-built vdso.o:
        ld -m elf_i386 -T libbboeos.ld --gc-sections \
            -o libbboeos.elf libbboeos.o libbboeos.a
  - constants.asm exposes FUNCTION_STRCMP_PTR.
  - VDSO_SIGRETURN_OFFSET moves 0x460 → 0xFE0 so the helper region
    can grow past 1 KB.  Sigreturn now sits near the end of page 0,
    past the pointer table at 0x800..0x83C.  No ABI break — kernel
    signal_dispatch_user references the constant symbolically.

`build/libbboeos` grows from 2100 → 4068 bytes (still single-page;
strcmp body is 0x3D bytes, the rest of the growth is the sigreturn
relocation extending the file out to 0xFE4).

cc.py-side wiring — the extern-call fallback that emits
`call [FUNCTION_<name>_PTR]` when a name is unknown — lands in a
follow-up PR.  This commit is purely the build-pipeline plumbing
that makes the symbol reachable in the first place.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bboe bboe force-pushed the bboe/libbboeos-phase3-strcmp branch from 0c3378b to aa676c7 Compare May 20, 2026 11:16
@bboe bboe merged commit 5f0bc83 into main May 20, 2026
27 checks passed
@bboe bboe deleted the bboe/libbboeos-phase3-strcmp branch May 20, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant