1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
From: Richard Lowe <richlowe@richlowe.net>
Date: Sat, 27 Oct 2012 02:44:09 +0100
Subject: [PATCH] Implement -fstrict-calling-conventions
Stock GCC is overly willing to violate the ABI when calling local functions,
such that it passes arguments in registers on i386. This hampers debugging
with anything other than a fully-aware DWARF debugger, and is generally not
something we desire.
Implement a flag which disables this behaviour, enabled by default. The flag is
global, though only effective on i386, to more easily allow its globalization
later which, given the odds, is likely to be necessary.
See http://wiki.illumos.org/display/illumos/GCC+Modifications
Index: gcc-6.git/src/gcc/common.opt
===================================================================
--- gcc-6.git.orig/src/gcc/common.opt
+++ gcc-6.git/src/gcc/common.opt
@@ -2236,6 +2236,10 @@ fstrict-aliasing
Common Report Var(flag_strict_aliasing) Optimization
Assume strict aliasing rules apply.
+fstrict-calling-conventions
+Common Report Var(flag_strict_calling_conventions) Init(1)
+Use strict ABI calling conventions even for static functions
+
fstrict-overflow
Common Report Var(flag_strict_overflow) Optimization
Treat signed overflow as undefined.
Index: gcc-6.git/src/gcc/config/i386/i386.c
===================================================================
--- gcc-6.git.orig/src/gcc/config/i386/i386.c
+++ gcc-6.git/src/gcc/config/i386/i386.c
@@ -7076,6 +7076,7 @@ ix86_function_regparm (const_tree type,
/* Use register calling convention for local functions when possible. */
if (decl
+ && (TARGET_64BIT || !flag_strict_calling_conventions)
&& TREE_CODE (decl) == FUNCTION_DECL)
{
cgraph_node *target = cgraph_node::get (decl);
@@ -7179,6 +7180,7 @@ ix86_function_sseregparm (const_tree typ
/* TARGET_SSE_MATH */
&& (target_opts_for_fn (target->decl)->x_ix86_fpmath & FPMATH_SSE)
&& opt_for_fn (target->decl, optimize)
+ && (TARGET_64BIT || !flag_strict_calling_conventions)
&& !(profile_flag && !flag_fentry))
{
cgraph_local_info *i = &target->local;
Index: gcc-6.git/src/gcc/doc/invoke.texi
===================================================================
--- gcc-6.git.orig/src/gcc/doc/invoke.texi
+++ gcc-6.git/src/gcc/doc/invoke.texi
@@ -7770,6 +7770,12 @@ int f() @{
The @option{-fstrict-aliasing} option is enabled at levels
@option{-O2}, @option{-O3}, @option{-Os}.
+@item -fstrict-calling-conventions
+@opindex fstrict-calling-conventions
+Use strict ABI calling conventions even with local functions.
+This disable certain optimizations that may cause GCC to call local
+functions in a manner other than that described by the ABI.
+
@item -fstrict-overflow
@opindex fstrict-overflow
Allow the compiler to assume strict signed overflow rules, depending
Index: gcc-6.git/src/gcc/testsuite/gcc.target/i386/local.c
===================================================================
--- gcc-6.git.orig/src/gcc/testsuite/gcc.target/i386/local.c
+++ gcc-6.git/src/gcc/testsuite/gcc.target/i386/local.c
@@ -1,5 +1,6 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -funit-at-a-time" } */
+/* { dg-options "-O2 -funit-at-a-time -fno-strict-calling-conventions" { target ilp32 } } */
+/* { dg-options "-O2 -funit-at-a-time" { target lp64 } } */
/* { dg-final { scan-assembler "magic\[^\\n\]*eax" { target ia32 } } } */
/* { dg-final { scan-assembler "magic\[^\\n\]*(edi|ecx)" { target { ! ia32 } } } } */
Index: gcc-6.git/src/gcc/testsuite/gcc.target/i386/strict-cc.c
===================================================================
--- /dev/null
+++ gcc-6.git/src/gcc/testsuite/gcc.target/i386/strict-cc.c
@@ -0,0 +1,22 @@
+/* { dg-do compile { target { ilp32 } } } */
+/* { dg-options "-O2 -funit-at-a-time -fstrict-calling-conventions" } */
+/* { dg-final { scan-assembler "pushl.*\\\$1" } } */
+/* { dg-final { scan-assembler "pushl.*\\\$2" } } */
+/* { dg-final { scan-assembler "pushl.*\\\$3" } } */
+/* { dg-final { scan-assembler "pushl.*\\\$4" } } */
+/* { dg-final { scan-assembler "pushl.*\\\$5" } } */
+
+#include <stdio.h>
+
+/* Verify that local calling convention is not used if strict conventions. */
+static t(int, int, int, int, int) __attribute__ ((noinline));
+
+m()
+{
+ t(1, 2, 3, 4, 5);
+}
+
+static t(int a, int b, int c, int d, int e)
+{
+ printf("%d\n", a, b, c, d, e);
+}
|