1 From 320d4032664e6267a9d2d6df1a3898bf75712035 Mon Sep 17 00:00:00 2001
2 From: Richard Lowe <richlowe@richlowe.net>
3 Date: Sun, 30 Sep 2012 16:44:14 -0400
4 Subject: allow the global disabling of function cloning
6 Optimizations which clone functions to create call-specific implementations
7 which may be better optimized also dissociate these functions from their
8 symbol names in ways harmful to tracing and debugging (since there are now
9 several implementations of a single source symbol, quite possibly none of them
10 having the actual source symbol name).
12 This allows any function cloning to be disabled, and makes any such
13 optimization ineffective, and our source safe for debuggers everywhere.
15 gcc/attribs.cc | 9 +++++++++
16 gcc/common.opt | 5 +++++
17 gcc/doc/invoke.texi | 10 ++++++++++
18 3 files changed, 24 insertions(+)
20 diff --git a/gcc/attribs.cc b/gcc/attribs.cc
21 index 12ffc5f170a1..75d1e43eb0c3 100644
24 @@ -709,6 +709,15 @@ decl_attributes (tree *node, tree attributes, int flags,
25 attributes = tree_cons (get_identifier ("no_icf"), NULL, attributes);
28 + /* If the user passed -fno-clone-functions, all functions should be treated
30 + if (TREE_CODE (*node) == FUNCTION_DECL
31 + && !flag_clone_functions)
33 + if (lookup_attribute ("noclone", attributes) == NULL)
34 + attributes = tree_cons (get_identifier ("noclone"), NULL, attributes);
37 targetm.insert_attributes (*node, &attributes);
39 /* Note that attributes on the same declaration are not necessarily
40 diff --git a/gcc/common.opt b/gcc/common.opt
41 index a4a04b0aa81d..3998e9c427f5 100644
44 @@ -1231,6 +1231,11 @@ fcode-hoisting
45 Common Var(flag_code_hoisting) Optimization
49 +Common Var(flag_clone_functions) Init(1)
50 +Allow the compiler to clone functions to facilitate certain optimizations.
53 fcombine-stack-adjustments
54 Common Var(flag_combine_stack_adjustments) Optimization
55 Looks for opportunities to reduce stack adjustments and stack references.
56 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
57 index e28412fb4488..cb53a55501c3 100644
58 --- a/gcc/doc/invoke.texi
59 +++ b/gcc/doc/invoke.texi
60 @@ -552,6 +552,7 @@ Objective-C and Objective-C++ Dialects}.
61 -fassociative-math -fauto-profile -fauto-profile[=@var{path}]
62 -fauto-inc-dec -fbranch-probabilities
65 -fcombine-stack-adjustments -fconserve-stack
67 -fcompare-elim -fcprop-registers -fcrossjumping
68 @@ -13421,6 +13422,15 @@ and then tries to find ways to combine them.
70 Enabled by default at @option{-O1} and higher.
72 +@opindex fno-clone-functions
73 +@item -fno-clone-functions
74 +Forbid the implicit cloning of functions implicit in certain
75 +optimizations. This also effectively will disable any optimization
76 +which wishes to clone functions, equivalent to each function having
77 +the ``noclone'' attribute. This allows the prevention of the
78 +dissociation of a piece of text from an intelligible and expected
79 +symbol name, which may hamper debugging and tracing.
83 Use caller save registers for allocation if those registers are not used by