From ca1ede88526f0c2f2fb80633bdb5badfde24ed4e Mon Sep 17 00:00:00 2001 From: kazu Date: Tue, 2 May 2006 15:04:52 +0000 Subject: [PATCH] gcc/ PR target/27387 * arm.c (arm_output_mi_thunk): Use pc-relative addressing when -mthumb -fPIC are used. testsuite/ PR target/27387 * gcc.target/arm/arm.exp: New. * gcc.target/arm/pr27387.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113467 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 +++++ gcc/config/arm/arm.c | 33 ++++++++++++++++++++++++++- gcc/testsuite/ChangeLog | 6 +++++ gcc/testsuite/gcc.target/arm/arm.exp | 41 ++++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.target/arm/pr90000.C | 26 +++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/arm/arm.exp create mode 100644 gcc/testsuite/gcc.target/arm/pr90000.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e1e0e22b6e4..f1f4e9f4059 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-05-02 Kazu Hirata + + PR target/27387 + * arm.c (arm_output_mi_thunk): Use pc-relative addressing when + -mthumb -fPIC are used. + 2006-05-02 Joshua Kinard PR target/25871 diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 5a5c7c0e076..9438b7c25ae 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -14701,6 +14701,7 @@ arm_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, { static int thunk_label = 0; char label[256]; + char labelpc[256]; int mi_delta = delta; const char *const mi_op = mi_delta < 0 ? "sub" : "add"; int shift = 0; @@ -14715,6 +14716,23 @@ arm_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, fputs ("\tldr\tr12, ", file); assemble_name (file, label); fputc ('\n', file); + if (flag_pic) + { + /* If we are generating PIC, the ldr instruction below loads + "(target - 7) - .LTHUNKPCn" into r12. The pc reads as + the address of the add + 8, so we have: + + r12 = (target - 7) - .LTHUNKPCn + (.LTHUNKPCn + 8) + = target + 1. + + Note that we have "+ 1" because some versions of GNU ld + don't set the low bit of the result for R_ARM_REL32 + relocations against thumb function symbols. */ + ASM_GENERATE_INTERNAL_LABEL (labelpc, "LTHUNKPC", labelno); + assemble_name (file, labelpc); + fputs (":\n", file); + fputs ("\tadd\tr12, pc, r12\n", file); + } } while (mi_delta != 0) { @@ -14735,7 +14753,20 @@ arm_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, ASM_OUTPUT_ALIGN (file, 2); assemble_name (file, label); fputs (":\n", file); - assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1); + if (flag_pic) + { + /* Output ".word .LTHUNKn-7-.LTHUNKPCn". */ + rtx tem = XEXP (DECL_RTL (function), 0); + tem = gen_rtx_PLUS (GET_MODE (tem), tem, GEN_INT (-7)); + tem = gen_rtx_MINUS (GET_MODE (tem), + tem, + gen_rtx_SYMBOL_REF (Pmode, + ggc_strdup (labelpc))); + assemble_integer (tem, 4, BITS_PER_WORD, 1); + } + else + /* Output ".word .LTHUNKn". */ + assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1); } else { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e71a7f0b343..eb2eab460c5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-05-02 Kazu Hirata + + PR target/27387 + * gcc.target/arm/arm.exp: New. + * gcc.target/arm/pr27387.C: Likewise. + 2006-05-02 Paul Thomas PR fortran/27269 diff --git a/gcc/testsuite/gcc.target/arm/arm.exp b/gcc/testsuite/gcc.target/arm/arm.exp new file mode 100644 index 00000000000..7f4958e92ac --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/arm.exp @@ -0,0 +1,41 @@ +# Copyright (C) 1997, 2004, 2006 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# GCC testsuite that uses the `dg.exp' driver. + +# Exit immediately if this isn't an ARM target. +if ![istarget arm*-*-*] then { + return +} + +# Load support procs. +load_lib gcc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS " -ansi -pedantic-errors" +} + +# Initialize `dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \ + "" $DEFAULT_CFLAGS + +# All done. +dg-finish diff --git a/gcc/testsuite/gcc.target/arm/pr90000.C b/gcc/testsuite/gcc.target/arm/pr90000.C new file mode 100644 index 00000000000..5ffce10ba11 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr90000.C @@ -0,0 +1,26 @@ +/* PR target/90000 + We used to generate a non-PIC thunk on thumb even with -fPIC. + Make sure that won't happen anymore. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target arm32 } */ +/* { dg-options "-mthumb -fPIC" } */ + +struct A { + virtual void f (); +}; + +struct B { + virtual void g (); +}; + +struct C : public A, public B { + virtual void g(); +}; + +void +C::g() +{ +} + +/* { dg-final { scan-assembler "LTHUNKPC" } } */ -- 2.11.0