aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazu Hirata <kazu@codesourcery.com>2006-05-02 15:04:52 +0000
committerKazu Hirata <kazu@gcc.gnu.org>2006-05-02 15:04:52 +0000
commit54b9e939534d857498abbbfc2d1bea8bf308b404 (patch)
treef3e6209af7c13308785d0c6fc4658a40b20a763e
parent613e2ac8d3dc830f03c00b165ffcf85b96717240 (diff)
downloadgcc-54b9e939534d857498abbbfc2d1bea8bf308b404.zip
gcc-54b9e939534d857498abbbfc2d1bea8bf308b404.tar.gz
gcc-54b9e939534d857498abbbfc2d1bea8bf308b404.tar.bz2
re PR target/27387 (Thumb thunk is not PIC)
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. From-SVN: r113467
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/config/arm/arm.c33
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.target/arm/arm.exp41
-rw-r--r--gcc/testsuite/gcc.target/arm/pr90000.C26
5 files changed, 111 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e1e0e22..f1f4e9f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2006-05-02 Kazu Hirata <kazu@codesourcery.com>
+
+ PR target/27387
+ * arm.c (arm_output_mi_thunk): Use pc-relative addressing when
+ -mthumb -fPIC are used.
+
2006-05-02 Joshua Kinard <kumba@gentoo.org>
PR target/25871
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 5a5c7c0..9438b7c 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 e71a7f0..eb2eab4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2006-05-02 Kazu Hirata <kazu@codesourcery.com>
+
+ PR target/27387
+ * gcc.target/arm/arm.exp: New.
+ * gcc.target/arm/pr27387.C: Likewise.
+
2006-05-02 Paul Thomas <pault@gcc.gnu.org>
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 0000000..7f4958e
--- /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 0000000..5ffce10
--- /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" } } */