generate_linker_script: align .data LMA to 4-byte boundary#831
Merged
Grazfather merged 1 commit intomainfrom Jan 4, 2026
Merged
generate_linker_script: align .data LMA to 4-byte boundary#831Grazfather merged 1 commit intomainfrom
Grazfather merged 1 commit intomainfrom
Conversation
tact1m4n3
reviewed
Jan 4, 2026
tact1m4n3
reviewed
Jan 4, 2026
Collaborator
|
Should we add the same for bss? |
d9b6618 to
f0d113c
Compare
The startup code uses word-aligned loads (lw instruction) to copy .data from flash to RAM. When .text section ended at an unaligned address, .data's flash location (LMA) became misaligned, causing hardware faults during startup before main() was even reached. This was triggered by certain code combinations that caused .text to end at addresses like 0x1bc1 instead of 0x1bc4. The unaligned load would fault before any user code executed. Fix: Add `. = ALIGN(4);` at the end of .text section to ensure the next section's load address in flash is properly aligned for word loads.
f0d113c to
32f1055
Compare
tact1m4n3
approved these changes
Jan 4, 2026
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.
The startup code for riscv uses word-aligned loads (The
lwinstruction) to copy.datafrom flash to RAM. When the.textsection ended at an unaligned address,.data's flash location (LMA) became misaligned, causing hardware faults during startup when copying the.datasection into RAM.This was triggered by certain code combinations that caused
.textto end at addresses like 0x1bc1 instead of 0x1bc4. The unaligned load would fault before any user code executed.Fixed by adding
. = ALIGN(4);at the end of .text section to ensure the next section's load address in flash is properly aligned for word loads.