Repository navigation
Conversation
The m68k genmodule stubs load the library base into %a0, which GCC uses for the struct-return pointer: ldiv/div/complex functions (and cexp, which GCC emits for sin+cos of one value) lose their result and corrupt the library base. ApolloOS.R10 issue #6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
A new OS pitfall,
os/pitfalls/stackcall-struct-return-a0.md.On m68k, ApolloOS's genmodule link-library stubs load the library base into
%a0:GCC passes the hidden result pointer of a struct-returning function in
%a0too. So these lose their result and write it over the start of the library base:ldiv,div,lldiv,imaxdiv;double complexfunction;cexp(), which GCC emits by itself forsin(x)+cos(x)of onex.The caller reads garbage, and the program crashes a few seconds later.
The ApolloOS fix is tracked as ApolloTeam-dev/ApolloOS.R10#6. A pitfall even though AKB §5 asks for an issue: ApolloOS releases up to R9.6 ship the bug, and the pitfall gives the workarounds for code built against them.
Verified workaround:
-fno-builtin-sin -fno-builtin-cosmakes GCC 6.5 emitsin/cosinstead ofcexp. Checked withnmon the compiled Zune clock source.Found during
The ApolloOS R10 port. Zune's clock in Prefs/Time and Utilities/Clock crashed the V4 (Software Failure, PC 0x26, supervisor mode). A test that only calls
ldiv(17,5)andcexp(0)printed nothing and exited with RC 16688456. After the fix (base in%a1,%a0kept) it prints3 rem 2and1 + 0i, and the clocks run without a failure.Knowledge base files relied on
os/pitfalls/library-globals-shared-between-tasks.md(format, related)CONTRIBUTING.md(folder, frontmatter, evidence table)Local checks:
check_frontmatter,check_linksandcheck_saga_addressespass.🤖 Generated with Claude Code