Skip to content

soc: nxp: Fix boot header placement when using lld #87929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025

Conversation

kesyog
Copy link
Contributor

@kesyog kesyog commented Mar 31, 2025

As well described in #58315, the GNU ld and LLVM lld linkers treat the location counter (.) differently. lld always inteprets the location counter as an absolute address whereas ld interprets it as an offset from the start of the current object.

The NXP boot header linker script files use . assignment to specify an offset within the rom_start output section, which is fine for ld. However, lld errors out, as it sees the offset as an absolute address, which would require it to move the location counter backwards.

To fix this, re-use the idea from #58315: replace . = FOO_OFFSET with . += FOO_OFFSET - (. - __rom_start_address). Given that __rom_start_address is already set up to be at the very start of the rom_start output section, this sets the location counter in a way that works with both ld and lld.

As well described in a previous PR [1], the GNU ld and LLVM lld linkers
treat the location counter (`.`) differently. lld always inteprets the
location counter as an absolute address whereas ld interprets it as an
offset from the start of the current object.

The NXP boot header linker script files use `.` assignment to specify an
offset within the rom_start region (ld-style). This causes lld to error
out since it interprets this as the location counter moving backwards.

To fix this, re-use the idea from the previous PR [1]:
replace `. = FOO` with `. += FOO - (. - __rom_start_address)`

This sets the location counter in a way that works with both ld and lld.

[1] zephyrproject-rtos#58315

Signed-off-by: Kesavan Yogeswaran <[email protected]>
@kesyog kesyog force-pushed the nxp-boot-header-lld-fix branch from e7a0e41 to 9208a60 Compare April 11, 2025 14:36
@butok butok requested a review from hakehuang April 11, 2025 14:43
@hakehuang hakehuang added the block: HW Test Testing on hardware required before merging label Apr 12, 2025
@hakehuang
Copy link
Collaborator

let me kick a full testing for all NXP platforms with Hello World will feedback once done

Copy link
Collaborator

@hakehuang hakehuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Board testing pass

@hakehuang hakehuang removed the block: HW Test Testing on hardware required before merging label Apr 12, 2025
@decsny
Copy link
Member

decsny commented Apr 14, 2025

also @jacob-wienecke-nxp and @EmilioCBen were working on code relocating a lot lately, one of you two please test the different configurations you were trying to see if this still works

@decsny decsny added the block: HW Test Testing on hardware required before merging label Apr 14, 2025
@kartben kartben merged commit 2882dab into zephyrproject-rtos:main Apr 21, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
block: HW Test Testing on hardware required before merging platform: NXP NXP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants