Conversation
klaudiagrz
approved these changes
Mar 8, 2026
content/asm_6.md
Outdated
| ``` | ||
|
|
||
| The definition of the `.text` section starts from referencing the external functions: `strtod` and `printf`. As mentioned above, these functions are part of the C standard library, and we will use them to simplify our program. After defining the entry point, we immediately jump to the `_read_first_float_vector` label. This is where our code starts. | ||
| The definition of the `.text` section starts from referencing the external functions: `strtod` and `printf`. As mentioned above, these functions are part of the C standard library, and we will use them to simplify our program. After defining the entry point, we align the stack to 16 bytes boundary how System V AMD64 ABI requires before calling C functions and immediately jump to the `_read_first_float_vector` label. This is where our code starts. |
Collaborator
There was a problem hiding this comment.
Suggested change
| The definition of the `.text` section starts from referencing the external functions: `strtod` and `printf`. As mentioned above, these functions are part of the C standard library, and we will use them to simplify our program. After defining the entry point, we align the stack to 16 bytes boundary how System V AMD64 ABI requires before calling C functions and immediately jump to the `_read_first_float_vector` label. This is where our code starts. | |
| The definition of the `.text` section starts from referencing the external functions: `strtod` and `printf`. As mentioned above, these functions are part of the C standard library, and we will use them to simplify our program. After defining the entry point, we align the stack to 16 bytes boundary (as System V AMD64 ABI requires before calling C functions) and immediately jump to the `_read_first_float_vector` label. This is where our code starts. |
The System V AMD64 ABI requires the stack to be 16-byte aligned before calling any C library function. Without proper alignment, C functions like strtod() and printf() can segfault on systems that strictly enforce ABI requirements (e.g., AMD EPYC processors). This fix adds a single instruction at _start to force stack alignment. This ensures RSP % 16 == 0 before any call instruction, which after pushing the 8-byte return address results in RSP % 16 == 8 inside the called function - exactly what the ABI specifies. Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.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.
Description
The System V AMD64 ABI requires the stack to be 16-byte aligned before calling any C library function. Without proper alignment, C functions like strtod() and printf() can segfault on systems that strictly enforce ABI requirements (e.g., AMD EPYC processors).
This fix adds a single instruction at _start to force stack alignment. This ensures RSP % 16 == 0 before any call instruction, which after pushing the 8-byte return address results in RSP % 16 == 8 inside the called function - exactly what the ABI specifies.
Related issues
Related issue - #64