feat(libbboeos): Phase 4 — clang programs link against stub thunks#451
Merged
Conversation
Adds tools/generate_libbboeos_stubs.py that walks kernel/include/constants.asm for every FUNCTION_<NAME>_PTR entry without a matching FUNCTION_<NAME> legacy counterpart and emits a .S file with one 6-byte `jmp [absolute]` thunk per export. The Makefile compiles it to libbboeos_stubs.o, which is now linked before libbboeos.a in ports/doom/build.py and the test_libbboeos_qemu hello.c link. Because ld is single-pass left-to-right and only pulls archive members for unresolved symbols, the stubs satisfy every libbboeos export first, so the corresponding archive member (string.o + its bodies + rodata) is never pulled into the program. Bin/hello drops from 12,682 to 10,922 bytes; bin/doom drops from 659,942 to 658,182. Win scales as more libbboeos sources go behind the FUNCTION_<NAME>_PTR table. Also fixes the stale `[bboeos libc]` regex patterns in test_libbboeos_qemu.py (the marker was renamed to `[libbboeos]` in the libbboeos rename but the test wasn't updated since it's not in CI). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2f821de to
5f8a872
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tools/generate_libbboeos_stubs.py— walksFUNCTION_<NAME>_PTRentries inkernel/include/constants.asmand emits a one-jmp [absolute]-per-export.Sfile. Skips the legacy 13-entry block (those have bothFUNCTION_DIEandFUNCTION_DIE_PTRand aren't libbboeos C exports).libbboeos_stubs.o(default target nowall, which builds bothlibbboeos.aand the stubs).ports/doom/build.pyandtests/test_libbboeos_qemu.pylinklibbboeos_stubs.obeforelibbboeos.a. ld's archive pull rule (single-pass, satisfy-unresolved-only) means once the stubs define each libbboeos export, the correspondingstring.oarchive member is never pulled into the program.sizeof(string.o)per binary, and scales as more libbboeos C sources land behind the pointer table.[bboeos libc]regex patterns intest_libbboeos_qemu.py(marker was renamed to[libbboeos]in an earlier phase but the test wasn't updated since it's not in CI).Test plan
./make_os.shcleantests/test_asm.py(42/42)tests/test_programs.py(89/89)tests/test_bboefs.py(6/6)tests/test_archive.py(12/12)tests/test_kernel_archive.py(12/12)tests/test_cc_compatibility.py(57/57)python3 -m pytest tests/unit/(458/458)tests/test_libbboeos_qemu.py(manual; passes with stubs)python3 ports/doom/build.pysucceeds, binary 658,182 bytes🤖 Generated with Claude Code