Skip to content

Commit

Permalink
arch: arm64: Include GOT in RODATA
Browse files Browse the repository at this point in the history
GCC 12 and above may emit "GOT indirections" for the weak symbol
references, and this requires the Global Offset Table (GOT) to be
included in the output.

This commit places the `.got` section in the RODATA section so that
the addresses of the weak symbols can be resolved at run-time. Note
that the GOT is populated with the symbol addresses at the default
linking address by the linker.

The `.got.plt` section, although unused, is also placed in the RODATA
section because the linker refuses to allow discarding this section
even when the `.plt` section is discarded.

In case of the GCC releases prior to 12, the weak symbol addresses are
placed in the literal pool and the `.got` section is not created at
all; therefore, this patch will be no-op.

For more details, refer to the following GitHub issue:
zephyrproject-rtos/sdk-ng#547.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
  • Loading branch information
stephanosio committed Aug 24, 2022
1 parent 7b1a8f4 commit 3fc1ccd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/zephyr/arch/arm64/scripts/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ SECTIONS
*(".rodata.*")
*(.gnu.linkonce.r.*)

/*
* The following is a workaround to allow compiling with GCC 12 and
* above, which may emit "GOT indirections" for the weak symbol
* references (see the GitHub issue zephyrproject-rtos/sdk-ng#547).
*/
*(.got)
*(.got.plt)

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
Expand All @@ -186,9 +194,7 @@ SECTIONS
*/
/DISCARD/ :
{
*(.got.plt)
*(.igot.plt)
*(.got)
*(.igot)
}

Expand Down

0 comments on commit 3fc1ccd

Please sign in to comment.