From 50c9d049978e096b754415819c521c9d9504173e Mon Sep 17 00:00:00 2001 From: Richard Earnshaw Date: Thu, 22 Dec 2011 14:13:09 +0000 Subject: [PATCH] re PR target/51643 (Incorrect code produced for tail-call of weak function with -O2/-O3 option) PR target/51643 * arm.c (arm_function_ok_for_sibcall): Don't try to tailcall a weak function on bare-metal EABI targets. * gcc.target/arm/sibcall-2.c: New test. From-SVN: r182621 --- gcc/ChangeLog | 6 ++++++ gcc/config/arm/arm.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/arm/sibcall-2.c | 12 ++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gcc.target/arm/sibcall-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a26d8b4f2c67..d1c9a2f62536 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-12-21 Richard Earnshaw + + PR target/51643 + * arm.c (arm_function_ok_for_sibcall): Don't try to tailcall a + weak function on bare-metal EABI targets. + 2011-12-21 Jonathan Wakely Jim Avera diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index b682a9f0d9df..fec43fba9039 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -5250,6 +5250,14 @@ arm_function_ok_for_sibcall (tree decl, tree exp) if (IS_STACKALIGN (func_type)) return false; + /* The AAPCS says that, on bare-metal, calls to unresolved weak + references should become a NOP. Don't convert such calls into + sibling calls. */ + if (TARGET_AAPCS_BASED + && arm_abi == ARM_ABI_AAPCS + && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))) + return false; + /* Everything else is ok. */ return true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 18db669dcb9d..9e58adc714ca 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-12-21 Richard Earnshaw + + PR target/51643 + * gcc.target/arm/sibcall-2.c: New test. + 2011-12-22 Uros Bizjak PR testsuite/51645 diff --git a/gcc/testsuite/gcc.target/arm/sibcall-2.c b/gcc/testsuite/gcc.target/arm/sibcall-2.c new file mode 100644 index 000000000000..921c0f30284b --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/sibcall-2.c @@ -0,0 +1,12 @@ +/* { dg-require-effective-target arm_eabi } */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mabi=aapcs" } */ + + +extern void __attribute__((weak)) wfunc(void); +void main(void) +{ + wfunc(); /* Must not tail-call. */ +} + +/* { dg-final { scan-assembler-not "b\[\\t \]+wfunc" } } */