From dbe3aecd70f94ab21ab4de401754b4d01f15a2a0 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Fri, 26 Nov 2021 15:08:42 +0000 Subject: [PATCH] aarch64, Darwin: Constrain page offset values to fit in the relocation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes issue #52. We need to constrain the offsets in the @PAGE/@PAGEOFFS relocations to fit in a 24bit field - +/- 8Mb. Signed-off-by: Iain Sandoe gcc/ * config/aarch64/aarch64.c (aarch64_load_symref_appropriately): If the offset will not fit into the relocation, then rewrite it as an addition. --- gcc/config/aarch64/aarch64.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index a6a88ee601ce..3c4cdb3c0f41 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -3877,7 +3877,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, rtx sym, off; split_const (imm, &sym, &off); /* Negative offsets don't work, whether by intention is TBD. */ - if (INTVAL (off) < 0) + if (INTVAL (off) < 0 || INTVAL (off) > 8 * 1024 * 1024) { emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, sym)); emit_insn (gen_add_losym (dest, tmp_reg, sym)); @@ -3885,7 +3885,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, emit_insn (gen_adddi3 (dest, dest, off)); return; } - /* else positive offset is OK. */ + /* else small enough positive offset is OK. */ } emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, imm)); emit_insn (gen_add_losym (dest, tmp_reg, imm));