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
This commit is contained in:
Kazu Hirata 2006-05-02 15:04:52 +00:00 committed by Kazu Hirata
parent 613e2ac8d3
commit 54b9e93953
5 changed files with 111 additions and 1 deletions

View File

@ -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

View File

@ -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
{

View File

@ -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

View File

@ -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

View File

@ -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" } } */