From d91480dee934478063fe5945b73ff3c108e40a91 Mon Sep 17 00:00:00 2001 From: Duan bo Date: Wed, 18 Mar 2020 10:18:39 +0000 Subject: [PATCH] aarch64: Fix SYMBOL_TINY_GOT handling for ILP32 [PR94201] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The SYMBOL_TINY_GOT case in aarch64_load_symref_appropriately was missing support for ILP32. This caused an ICE on the testcase. 2020-03-18 Duan bo gcc/ PR target/94201 * config/aarch64/aarch64.md (ldr_got_tiny): Delete. (@ldr_got_tiny_): New pattern. (ldr_got_tiny_sidi): Likewise. * config/aarch64/aarch64.c (aarch64_load_symref_appropriately): Use them to handle SYMBOL_TINY_GOT for ILP32. gcc/testsuite/ PR target/94201 * gcc.target/aarch64/pr94201.c:New test. --- gcc/ChangeLog | 9 +++++++++ gcc/config/aarch64/aarch64.c | 17 +++++++++++++++-- gcc/config/aarch64/aarch64.md | 22 ++++++++++++++++------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/aarch64/pr94201.c | 13 +++++++++++++ 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr94201.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1fa291100d0..5eb23b57037 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2020-03-18 Duan bo + + PR target/94201 + * config/aarch64/aarch64.md (ldr_got_tiny): Delete. + (@ldr_got_tiny_): New pattern. + (ldr_got_tiny_sidi): Likewise. + * config/aarch64/aarch64.c (aarch64_load_symref_appropriately): Use + them to handle SYMBOL_TINY_GOT for ILP32. + 2020-03-18 Richard Sandiford * config/aarch64/aarch64.c (aarch64_sve_abi): Treat p12-p15 as diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 26c00969cc1..c90de65de12 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -2739,8 +2739,21 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, } case SYMBOL_TINY_GOT: - emit_insn (gen_ldr_got_tiny (dest, imm)); - return; + { + rtx insn; + machine_mode mode = GET_MODE (dest); + + if (mode == ptr_mode) + insn = gen_ldr_got_tiny (mode, dest, imm); + else + { + gcc_assert (mode == Pmode); + insn = gen_ldr_got_tiny_sidi (dest, imm); + } + + emit_insn (insn); + return; + } case SYMBOL_TINY_TLSIE: { diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 7ad4e918578..c7c4d1dd519 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -6766,13 +6766,23 @@ [(set_attr "type" "load_4")] ) -(define_insn "ldr_got_tiny" - [(set (match_operand:DI 0 "register_operand" "=r") - (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")] - UNSPEC_GOTTINYPIC))] +(define_insn "@ldr_got_tiny_" + [(set (match_operand:PTR 0 "register_operand" "=r") + (unspec:PTR [(match_operand:PTR 1 "aarch64_valid_symref" "S")] + UNSPEC_GOTTINYPIC))] "" - "ldr\\t%0, %L1" - [(set_attr "type" "load_8")] + "ldr\t%0, %L1" + [(set_attr "type" "load_")] +) + +(define_insn "ldr_got_tiny_sidi" + [(set (match_operand:DI 0 "register_operand" "=r") + (zero_extend:DI + (unspec:SI [(match_operand:DI 1 "aarch64_valid_symref" "S")] + UNSPEC_GOTTINYPIC)))] + "TARGET_ILP32" + "ldr\t%w0, %L1" + [(set_attr "type" "load_4")] ) (define_insn "aarch64_load_tp_hard" diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3c70254fc6c..e8b78df02de 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-18 Duan bo + + PR target/94201 + * gcc.target/aarch64/pr94201.c:New test. + 2020-03-18 Richard Sandiford * gcc.target/aarch64/sve/acle/general/cpy_1.c: Leave gaps for in the diff --git a/gcc/testsuite/gcc.target/aarch64/pr94201.c b/gcc/testsuite/gcc.target/aarch64/pr94201.c new file mode 100644 index 00000000000..69176169186 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr94201.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-mcmodel=tiny -mabi=ilp32 -fPIC" } */ + +extern int bar (void *); +extern long long a; + +int +foo (void) +{ + a = 1; + return bar ((void *)bar); +} + -- 2.30.2