gettext: fix build with gcc-14; enhance test environment
[oi-userland.git] / components / developer / gcc-13 / patches / 0005-Implement-fstrict-calling-conventions.patch
blob17efd3b571b3464a8df2363225e45be354b30035
1 From a84b9e8a795b2892fd839b6cdfe4123d1d5e26e0 Mon Sep 17 00:00:00 2001
2 From: Richard Lowe <richlowe@richlowe.net>
3 Date: Sat, 27 Oct 2012 02:44:09 +0100
4 Subject: Implement -fstrict-calling-conventions
6 Stock GCC is overly willing to violate the ABI when calling local functions,
7 such that it passes arguments in registers on i386. This hampers debugging
8 with anything other than a fully-aware DWARF debugger, and is generally not
9 something we desire.
11 Implement a flag which disables this behaviour, enabled by default. The flag is
12 global, though only effective on i386, to more easily allow its globalization
13 later which, given the odds, is likely to be necessary.
14 ---
15 gcc/common.opt | 4 ++++
16 gcc/config/i386/i386.cc | 2 ++
17 gcc/doc/invoke.texi | 6 ++++++
18 gcc/testsuite/gcc.target/i386/local.c | 3 ++-
19 gcc/testsuite/gcc.target/i386/strict-cc.c | 24 +++++++++++++++++++++++
20 5 files changed, 38 insertions(+), 1 deletion(-)
21 create mode 100644 gcc/testsuite/gcc.target/i386/strict-cc.c
23 diff --git a/gcc/common.opt b/gcc/common.opt
24 index 862c474d3c8f..73560e307c7a 100644
25 --- a/gcc/common.opt
26 +++ b/gcc/common.opt
27 @@ -2806,6 +2806,10 @@ fstrict-aliasing
28 Common Var(flag_strict_aliasing) Optimization
29 Assume strict aliasing rules apply.
31 +fstrict-calling-conventions
32 +Common Var(flag_strict_calling_conventions) Init(1)
33 +Use strict ABI calling conventions even for static functions
35 fstrict-overflow
36 Common
37 Treat signed overflow as undefined. Negated as -fwrapv -fwrapv-pointer.
38 diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
39 index a551b8b9d9b3..e51b4fa1c0ed 100644
40 --- a/gcc/config/i386/i386.cc
41 +++ b/gcc/config/i386/i386.cc
42 @@ -1158,6 +1158,7 @@ ix86_function_regparm (const_tree type, const_tree decl)
43 and callee not, or vice versa. Instead look at whether the callee
44 is optimized or not. */
45 if (target && opt_for_fn (target->decl, optimize)
46 + && !flag_strict_calling_conventions
47 && !(profile_flag && !flag_fentry))
49 if (target->local && target->can_change_signature)
50 @@ -1254,6 +1255,7 @@ ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
51 /* TARGET_SSE_MATH */
52 && (target_opts_for_fn (target->decl)->x_ix86_fpmath & FPMATH_SSE)
53 && opt_for_fn (target->decl, optimize)
54 + && !flag_strict_calling_conventions
55 && !(profile_flag && !flag_fentry))
57 if (target->local && target->can_change_signature)
58 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
59 index de40f62e219c..8bd0a8357d12 100644
60 --- a/gcc/doc/invoke.texi
61 +++ b/gcc/doc/invoke.texi
62 @@ -7651,6 +7651,12 @@ with multiple statement cases using flow-sensitive points-to information.
63 Only warns when the converted pointer is dereferenced.
64 Does not warn about incomplete types.
66 +@opindex fstrict-calling-conventions
67 +@item -fstrict-calling-conventions
68 +Use strict ABI calling conventions even with local functions.
69 +This disable certain optimizations that may cause GCC to call local
70 +functions in a manner other than that described by the ABI.
72 @opindex Wstrict-overflow
73 @opindex Wno-strict-overflow
74 @item -Wstrict-overflow
75 diff --git a/gcc/testsuite/gcc.target/i386/local.c b/gcc/testsuite/gcc.target/i386/local.c
76 index f4444951e123..3a487583d81f 100644
77 --- a/gcc/testsuite/gcc.target/i386/local.c
78 +++ b/gcc/testsuite/gcc.target/i386/local.c
79 @@ -1,5 +1,6 @@
80 /* { dg-do compile } */
81 -/* { dg-options "-O2 -funit-at-a-time" } */
82 +/* { dg-options "-O2 -funit-at-a-time -fno-strict-calling-conventions" { target ia32 } } */
83 +/* { dg-options "-O2 -funit-at-a-time" { target lp64 } } */
84 /* { dg-final { scan-assembler "magic\[^\\n\]*eax" { target ia32 } } } */
85 /* { dg-final { scan-assembler "magic\[^\\n\]*(edi|ecx)" { target { ! ia32 } } } } */
87 diff --git a/gcc/testsuite/gcc.target/i386/strict-cc.c b/gcc/testsuite/gcc.target/i386/strict-cc.c
88 new file mode 100644
89 index 000000000000..fa0543e52ff6
90 --- /dev/null
91 +++ b/gcc/testsuite/gcc.target/i386/strict-cc.c
92 @@ -0,0 +1,24 @@
93 +/* { dg-do compile { target { ilp32 } } } */
94 +/* { dg-options "-O2 -funit-at-a-time -fstrict-calling-conventions" } */
95 +/* { dg-final { scan-assembler "pushl.*\\\$1" } } */
96 +/* { dg-final { scan-assembler "pushl.*\\\$2" } } */
97 +/* { dg-final { scan-assembler "pushl.*\\\$3" } } */
98 +/* { dg-final { scan-assembler "pushl.*\\\$4" } } */
99 +/* { dg-final { scan-assembler "pushl.*\\\$5" } } */
101 +#include <stdio.h>
103 +/* Verify that local calling convention is not used if strict conventions. */
104 +static int t(int, int, int, int, int) __attribute__ ((noinline));
106 +int
107 +m()
109 + t(1, 2, 3, 4, 5);
112 +static int
113 +t(int a, int b, int c, int d, int e)
115 + printf("%d\n", a, b, c, d, e);