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 <wilfred.mallawa@wdc.com>
  • Loading branch information
twilfredo committed Jan 3, 2024
1 parent a67d6b1 commit c6abe2a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build_scripts/libtock_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ SECTIONS {
/* Read-only data section. Contains strings and other global constants. */
.rodata ALIGN(4) : {
*(.rodata.*)

/* Generated by GCC in libraries for variables that still have relocations but are constant
* at runtime. See https://www.airs.com/blog/archives/189 for background.
*/
*(.data.rel.ro.*)
} > FLASH

/* Sections located in RAM at runtime.
Expand Down

0 comments on commit c6abe2a

Please sign in to comment.