Skip to content

Commit 02edd27

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 <root@stephanos.io>
1 parent 72118c8 commit 02edd27

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
@@ -19266,45 +19266,50 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset)
1926619266

1926719267
switch (aarch64_cmodel)
1926819268
{
19269-
case AARCH64_CMODEL_TINY_PIC:
1927019269
case AARCH64_CMODEL_TINY:
19271-
/* With -fPIC non-local symbols use the GOT. For orthogonality
19272-
always use the GOT for extern weak symbols. */
19273-
if ((flag_pic || SYMBOL_REF_WEAK (x))
19274-
&& !aarch64_symbol_binds_local_p (x))
19275-
return SYMBOL_TINY_GOT;
19276-
1927719270
/* When we retrieve symbol + offset address, we have to make sure
1927819271
the offset does not cause overflow of the final address. But
1927919272
we have no way of knowing the address of symbol at compile time
1928019273
so we can't accurately say if the distance between the PC and
1928119274
symbol + offset is outside the addressible range of +/-1MB in the
1928219275
TINY code model. So we limit the maximum offset to +/-64KB and
1928319276
assume the offset to the symbol is not larger than +/-(1MB - 64KB).
19284-
If offset_within_block_p is true we allow larger offsets. */
19277+
If offset_within_block_p is true we allow larger offsets.
19278+
Furthermore force to memory if the symbol is a weak reference to
19279+
something that doesn't resolve to a symbol in this module. */
19280+
19281+
if (SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x))
19282+
return SYMBOL_FORCE_TO_MEM;
1928519283
if (!(IN_RANGE (offset, -0x10000, 0x10000)
1928619284
|| offset_within_block_p (x, offset)))
1928719285
return SYMBOL_FORCE_TO_MEM;
1928819286

1928919287
return SYMBOL_TINY_ABSOLUTE;
1929019288

19291-
19292-
case AARCH64_CMODEL_SMALL_SPIC:
19293-
case AARCH64_CMODEL_SMALL_PIC:
1929419289
case AARCH64_CMODEL_SMALL:
19295-
if ((flag_pic || SYMBOL_REF_WEAK (x))
19296-
&& !aarch64_symbol_binds_local_p (x))
19297-
return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC
19298-
? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G;
19299-
1930019290
/* Same reasoning as the tiny code model, but the offset cap here is
1930119291
1MB, allowing +/-3.9GB for the offset to the symbol. */
19292+
19293+
if (SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x))
19294+
return SYMBOL_FORCE_TO_MEM;
1930219295
if (!(IN_RANGE (offset, -0x100000, 0x100000)
1930319296
|| offset_within_block_p (x, offset)))
1930419297
return SYMBOL_FORCE_TO_MEM;
1930519298

1930619299
return SYMBOL_SMALL_ABSOLUTE;
1930719300

19301+
case AARCH64_CMODEL_TINY_PIC:
19302+
if (!aarch64_symbol_binds_local_p (x))
19303+
return SYMBOL_TINY_GOT;
19304+
return SYMBOL_TINY_ABSOLUTE;
19305+
19306+
case AARCH64_CMODEL_SMALL_SPIC:
19307+
case AARCH64_CMODEL_SMALL_PIC:
19308+
if (!aarch64_symbol_binds_local_p (x))
19309+
return (aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC
19310+
? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G);
19311+
return SYMBOL_SMALL_ABSOLUTE;
19312+
1930819313
case AARCH64_CMODEL_LARGE:
1930919314
/* This is alright even in PIC code as the constant
1931019315
pool reference is always PC relative and within

0 commit comments

Comments
 (0)