Skip to content

GCC emits GOT indirections for weak symbol references on AArch64 #547

@stephanosio

Description

@stephanosio

Since the GCC 12.1 release (Zephyr SDK 0.15.0), GCC emits the "GOT indirections" for weak symbol references on AArch64, even when compiling with -fno-pic and -fno-pie.

Building the following code:

	extern __weak void
		pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id);

	if (pm_state_exit_post_ops != NULL) {

The pm_state_exit_post_ops, a weak symbol, is referenced as follows:

GCC 10.3 (Zephyr SDK 0.14.2)

	adrp	x0, .LC0
	ldr	x0, [x0, #:lo12:.LC0]
	...
.LC0:
	.xword	pm_state_exit_post_ops

GCC 12.1 (Zephyr SDK 0.15.0)

	adrp	x0, :got:pm_state_exit_post_ops
	ldr	x0, [x0, :got_lo12:pm_state_exit_post_ops]

Note that the code emitted by GCC 12.1 makes use of :got:, which references the Global Offset Table (GOT). This effectively requires the .got section to be included in the final image (these are currently discarded by the AArch64 linker script).

The Global Offset Table (GOT) should not be used when not compiling position independent code (PIC).

This issue was introduced by the GCC commit gcc-mirror/gcc@fb0746f.

p.s. when the weak symbol is actually defined, the linker does populate the corresponding GOT entry with the address of the symbol at the default linking address (though, the "default" linking address does not really apply to the static executables ...).

Raw listing output: https://gist.github.com/stephanosio/a7fa3cbbf285794b4b1f3520c9376e7b

Metadata

Metadata

Assignees

Labels

area: GCCIssues related to GCC (GNU Compiler Collection)known issue

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions