adafruit / adafruit/Adafruit_nRF52_Arduino

Linker script uses ALIGN oddly

Open
#868 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
699
Forks
570
PR merge metrics
No merged PRs in 30d

Description

The `nrf52_common.ld` linker script oddly uses `ALIGN` when attempting to draw a distinction between the heap and the stack:
https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/fa129c2a1075ca4290ab4b4bdef080a83b1b83c4/cores/nRF5/linker/nrf52_common.ld#L151-L159

While GNU binutils has not required `ALIGN`'s argument to be a power of two [since 2.15](https://sourceware.org/binutils/docs-2.15/ld/Builtin-Functions.html#Builtin%20Functions) (contrast [2.12](https://sourceware.org/binutils/docs-2.12/ld.info/Builtin-Functions.html#Builtin%20Functions)), `lld` still complains (probably because `ALIGN` is almost always used with a small power of two) and, besides and more importantly, `ALIGN`-ment isn't what the linker script is trying to ensure here! It wants `.` to advance to the lowest stack address -- that is, `__StackLimit`, and to place the symbol `__HeapLimit` there.

TL;DR: I think that line should ~~just be `. = __StackLimit;`, without the `ALIGN()`~~ (ah, no, that's a divergence between LLVM and GNU interpretations of linker scripts, siiiigh) be `. = ABSOLUTE(__StackLimit);`.

Does that seem right?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with cores/nRF5/linker/nrf52_common.ld lines 151-159 and compare the current ALIGN usage with the issue's proposed ABSOLUTE(__StackLimit) interpretation. Check the script with both GNU binutils and lld, then confirm that __HeapLimit is placed at the intended stack boundary and both linkers accept it.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.