===================================================================
@@ -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" } } */
===================================================================
@@ -5250,6 +5250,14 @@ arm_function_ok_for_sibcall (tree decl,
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;
}