Skip to content

Commit c62ec7a

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 73b1260 commit c62ec7a

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

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

1929319291
return SYMBOL_TINY_ABSOLUTE;
1929419292

19295-
19296-
case AARCH64_CMODEL_SMALL_SPIC:
19297-
case AARCH64_CMODEL_SMALL_PIC:
1929819293
case AARCH64_CMODEL_SMALL:
19299-
if ((flag_pic || SYMBOL_REF_WEAK (x))
19300-
&& !aarch64_symbol_binds_local_p (x))
19301-
return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC
19302-
? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G;
19303-
1930419294
/* Same reasoning as the tiny code model, but the offset cap here is
1930519295
1MB, allowing +/-3.9GB for the offset to the symbol. */
19296+
19297+
if (SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x))
19298+
return SYMBOL_FORCE_TO_MEM;
1930619299
if (!(IN_RANGE (offset, -0x100000, 0x100000)
1930719300
|| offset_within_block_p (x, offset)))
1930819301
return SYMBOL_FORCE_TO_MEM;
1930919302

1931019303
return SYMBOL_SMALL_ABSOLUTE;
1931119304

19305+
case AARCH64_CMODEL_TINY_PIC:
19306+
if (!aarch64_symbol_binds_local_p (x))
19307+
return SYMBOL_TINY_GOT;
19308+
return SYMBOL_TINY_ABSOLUTE;
19309+
19310+
case AARCH64_CMODEL_SMALL_SPIC:
19311+
case AARCH64_CMODEL_SMALL_PIC:
19312+
if (!aarch64_symbol_binds_local_p (x))
19313+
return (aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC
19314+
? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G);
19315+
return SYMBOL_SMALL_ABSOLUTE;
19316+
1931219317
case AARCH64_CMODEL_LARGE:
1931319318
/* This is alright even in PIC code as the constant
1931419319
pool reference is always PC relative and within

0 commit comments

Comments
 (0)