Skip to content

Commit 563d764

Browse files
committed
Revert "AArch64: Cleanup aarch64_classify_symbol"
This reverts the commit fb0746f because it causes the "GOT indirections," which require the final image to include the Global Offset Table (GOT), to be emitted for weak symbol references even when not building position-independent code or position-independent executable (i.e. when `-fno-pic` and `-fno-pie` parameters are specified). Before reverting this commit (GCC 12.1): adrp x0, :got:pm_state_exit_post_ops ldr x0, [x0, :got_lo12:pm_state_exit_post_ops] After reverting this commit (before GCC 12.1): adrp x0, .LC0 ldr x0, [x0, #:lo12:.LC0] ... .LC0: .xword pm_state_exit_post_ops Although the linker populates the Global Offset Table with the symbol addresses at the default linking address, which should be valid without any relocations in case of Zephyr because the Zephyr image is always loaded at a fixed address, this is far from ideal because the purpose of the Global Offset Table is to facilitate relocations and it comes with some overheads resulting in a minor footprint increase. For more details, refer to the following GitHub issue: zephyrproject-rtos/sdk-ng#547. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 8453e39 commit 563d764

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

gcc/config/aarch64/aarch64.cc

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20936,45 +20936,50 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset)
2093620936

2093720937
switch (aarch64_cmodel)
2093820938
{
20939-
case AARCH64_CMODEL_TINY_PIC:
2094020939
case AARCH64_CMODEL_TINY:
20941-
/* With -fPIC non-local symbols use the GOT. For orthogonality
20942-
always use the GOT for extern weak symbols. */
20943-
if ((flag_pic || SYMBOL_REF_WEAK (x))
20944-
&& !aarch64_symbol_binds_local_p (x))
20945-
return SYMBOL_TINY_GOT;
20946-
2094720940
/* When we retrieve symbol + offset address, we have to make sure
2094820941
the offset does not cause overflow of the final address. But
2094920942
we have no way of knowing the address of symbol at compile time
2095020943
so we can't accurately say if the distance between the PC and
2095120944
symbol + offset is outside the addressible range of +/-1MB in the
2095220945
TINY code model. So we limit the maximum offset to +/-64KB and
2095320946
assume the offset to the symbol is not larger than +/-(1MB - 64KB).
20954-
If offset_within_block_p is true we allow larger offsets. */
20947+
If offset_within_block_p is true we allow larger offsets.
20948+
Furthermore force to memory if the symbol is a weak reference to
20949+
something that doesn't resolve to a symbol in this module. */
20950+
20951+
if (SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x))
20952+
return SYMBOL_FORCE_TO_MEM;
2095520953
if (!(IN_RANGE (offset, -0x10000, 0x10000)
2095620954
|| offset_within_block_p (x, offset)))
2095720955
return SYMBOL_FORCE_TO_MEM;
2095820956

2095920957
return SYMBOL_TINY_ABSOLUTE;
2096020958

20961-
20962-
case AARCH64_CMODEL_SMALL_SPIC:
20963-
case AARCH64_CMODEL_SMALL_PIC:
2096420959
case AARCH64_CMODEL_SMALL:
20965-
if ((flag_pic || SYMBOL_REF_WEAK (x))
20966-
&& !aarch64_symbol_binds_local_p (x))
20967-
return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC
20968-
? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G;
20969-
2097020960
/* Same reasoning as the tiny code model, but the offset cap here is
2097120961
1MB, allowing +/-3.9GB for the offset to the symbol. */
20962+
20963+
if (SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x))
20964+
return SYMBOL_FORCE_TO_MEM;
2097220965
if (!(IN_RANGE (offset, -0x100000, 0x100000)
2097320966
|| offset_within_block_p (x, offset)))
2097420967
return SYMBOL_FORCE_TO_MEM;
2097520968

2097620969
return SYMBOL_SMALL_ABSOLUTE;
2097720970

20971+
case AARCH64_CMODEL_TINY_PIC:
20972+
if (!aarch64_symbol_binds_local_p (x))
20973+
return SYMBOL_TINY_GOT;
20974+
return SYMBOL_TINY_ABSOLUTE;
20975+
20976+
case AARCH64_CMODEL_SMALL_SPIC:
20977+
case AARCH64_CMODEL_SMALL_PIC:
20978+
if (!aarch64_symbol_binds_local_p (x))
20979+
return (aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC
20980+
? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G);
20981+
return SYMBOL_SMALL_ABSOLUTE;
20982+
2097820983
case AARCH64_CMODEL_LARGE:
2097920984
/* This is alright even in PIC code as the constant
2098020985
pool reference is always PC relative and within

0 commit comments

Comments
 (0)