Skip to content

Commit

Permalink
build_scripts/layout.ld: add a relro section
Browse files Browse the repository at this point in the history
This accomadates situations for example: where global variables are
initialized to a value that requires relocation. Things like globally
stored function pointers, or storing the address of another global
variable. Such items require runtime initialization in the form of
dynamic relocation, and cannot be placed in a RO segment. However,
as it is declared to be a constant (not modified by the program), the
dynamic linker can mark it as RO after the dynamic relocation as been
applied [1].

When GCC sees a variable which is constant but requires dynamic
relocation, it puts it into a section named `.data.rel.ro`, further, a
variable that requires dynamic relocation against a local symbol is put
into a `.data.rel.ro.local` section, this helps group such variables
together so that the dynamic linker may apply the relocations, which
will always be RELATIVE locations [1].

[1] https://www.airs.com/blog/archives/189

Signed-off-by: Wilfred Mallawa <[email protected]>
  • Loading branch information
twilfredo committed Dec 21, 2023
1 parent a67d6b1 commit 483ea13
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build_scripts/libtock_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ SECTIONS {
*(.rodata.*)
} > FLASH

..data.rel.ro.local ALIGN(4) : {
*(.data.rel.ro.local.*)
} > FLASH

/* Sections located in RAM at runtime.
*/

Expand Down

0 comments on commit 483ea13

Please sign in to comment.