Refine generated instructions for staticly linked programs of Arm32#321
Merged
jserv merged 1 commit intosysprog21:masterfrom Mar 29, 2026
Merged
Refine generated instructions for staticly linked programs of Arm32#321jserv merged 1 commit intosysprog21:masterfrom
jserv merged 1 commit intosysprog21:masterfrom
Conversation
jserv
reviewed
Mar 29, 2026
Comment on lines
+672
to
+678
| /* Jump directly to the main preparation and then execute the | ||
| * main function. | ||
| * | ||
| * In static linking mode, when the main function completes its | ||
| * execution, it will invoke the '_exit' syscall to terminate | ||
| * the program. | ||
| */ |
Collaborator
There was a problem hiding this comment.
Consolidate the comments, illustrating with Arm instructions.
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/arm-codegen.c">
<violation number="1" location="src/arm-codegen.c:695">
P2: Dead instruction: `r7` is loaded from `[sp+28]` but immediately overwritten by `mov r7, r0` on the next line. This wastes one instruction (4 bytes in the binary) and reads from a stack slot that has no corresponding argument. Remove this load to match the actual 7-parameter signature of `__syscall`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Previously, for the Arm architecture, the compiler generated the following sequence at the program entry point for staticly linked executables: - a 'bl' instruction to call a global initialization function, and then execute the main function. - a 'b' instruction. - a sequence of instructions to invoke the '_exit' system all. After further investigation, since the main function inherently invokes '_exit' upon completion, the entry sequence can be simplified. We now use a single 'b' instruction to perform an unconditional jump to the global initialization and the main routines. Additionally, the implementation of the '__syscall' function has been corrected. Previously, it modified registers r4-r7 without preserving their original values for the caller. This commit ensures that these callee-saved registers are properly saved and restored. Finally, This refinement improves the efficiency and correctness of the generated instructions for statically linked programs.
34d6a27 to
fc28ca9
Compare
Collaborator
|
Thank @DrXiao for contributing! |
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.
Previously, for the Arm architecture, the compiler generated the following sequence at the program entry point for staticly linked executables:
After further investigation, since the main function inherently invokes '_exit' upon completion, the entry sequence can be simplified. We now use a single 'b' instruction to perform an unconditional jump to the global initialization and the main routines.
Additionally, the implementation of the '__syscall' function has been corrected. Previously, it modified registers r4-r7 without preserving their original values for the caller. This commit ensures that these callee-saved registers are properly saved and restored.
Finally, This refinement improves the efficiency and correctness of the generated instructions for statically linked programs.
Summary by cubic
Simplifies ARM32 static entry by branching directly to global init + main, and fixes
__syscallto preserve callee-saved registers. Fewer startup instructions and correct ABI behavior.Bug Fixes
__syscallnow saves/restores r4–r7 withstmdb/ldm.Refactors
b; removed explicit_exitcode.Written for commit fc28ca9. Summary will update on new commits.