public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR85678: Change default to -fno-common
@ 2019-10-25 16:00 Wilco Dijkstra
  2019-10-25 19:11 ` Georg-Johann Lay
                   ` (5 more replies)
  0 siblings, 6 replies; 46+ messages in thread
From: Wilco Dijkstra @ 2019-10-25 16:00 UTC (permalink / raw)
  To: GCC Patches; +Cc: nd

GCC currently defaults to -fcommon.  As discussed in the PR, this is an ancient
C feature which is not conforming with the latest C standards.  On many targets
this means global variable accesses have a codesize and performance penalty.
This applies to C code only, C++ code is not affected by -fcommon.  It is about
time to change the default.

OK for commit?

ChangeLog
2019-10-25  Wilco Dijkstra  <wdijkstr@arm.com>

	PR85678
	* common.opt (fcommon): Change init to 1.

doc/
	* invoke.texi (-fcommon): Update documentation.
---

diff --git a/gcc/common.opt b/gcc/common.opt
index 0195b0cb85a06dd043fd0412b42dfffddfa2495b..b0840f41a5e480f4428bd62724b0dc3d54c68c0b 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1131,7 +1131,7 @@ Common Report Var(flag_combine_stack_adjustments) Optimization
 Looks for opportunities to reduce stack adjustments and stack references.
 
 fcommon
-Common Report Var(flag_no_common,0)
+Common Report Var(flag_no_common,0) Init(1)
 Put uninitialized globals in the common section.
 
 fcompare-debug
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 857d9692729e503657d0d0f44f1f6252ec90d49a..5b4ff66015f5f94a5bd89e4dc3d2d53553cc091e 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -568,7 +568,7 @@ Objective-C and Objective-C++ Dialects}.
 -fnon-call-exceptions  -fdelete-dead-exceptions  -funwind-tables @gol
 -fasynchronous-unwind-tables @gol
 -fno-gnu-unique @gol
--finhibit-size-directive  -fno-common  -fno-ident @gol
+-finhibit-size-directive  -fcommon  -fno-ident @gol
 -fpcc-struct-return  -fpic  -fPIC  -fpie  -fPIE  -fno-plt @gol
 -fno-jump-tables @gol
 -frecord-gcc-switches @gol
@@ -14050,35 +14050,27 @@ useful for building programs to run under WINE@.
 code that is not binary compatible with code generated without that switch.
 Use it to conform to a non-default application binary interface.
 
-@item -fno-common
-@opindex fno-common
+@item -fcommon
 @opindex fcommon
+@opindex fno-common
 @cindex tentative definitions
-In C code, this option controls the placement of global variables 
-defined without an initializer, known as @dfn{tentative definitions} 
-in the C standard.  Tentative definitions are distinct from declarations 
+In C code, this option controls the placement of global variables
+defined without an initializer, known as @dfn{tentative definitions}
+in the C standard.  Tentative definitions are distinct from declarations
 of a variable with the @code{extern} keyword, which do not allocate storage.
 
-Unix C compilers have traditionally allocated storage for
-uninitialized global variables in a common block.  This allows the
-linker to resolve all tentative definitions of the same variable
+The default is @option{-fno-common}, which specifies that the compiler places
+uninitialized global variables in the BSS section of the object file.
+This inhibits the merging of tentative definitions by the linker so you get a
+multiple-definition error if the same variable is accidentally defined in more
+than one compilation unit.
+
+The @option{-fcommon} places uninitialized global variables in a common block.
+This allows the linker to resolve all tentative definitions of the same variable
 in different compilation units to the same object, or to a non-tentative
-definition.  
-This is the behavior specified by @option{-fcommon}, and is the default for 
-GCC on most targets.  
-On the other hand, this behavior is not required by ISO
-C, and on some targets may carry a speed or code size penalty on
-variable references.
-
-The @option{-fno-common} option specifies that the compiler should instead
-place uninitialized global variables in the BSS section of the object file.
-This inhibits the merging of tentative definitions by the linker so
-you get a multiple-definition error if the same 
-variable is defined in more than one compilation unit.
-Compiling with @option{-fno-common} is useful on targets for which
-it provides better performance, or if you wish to verify that the
-program will work on other systems that always treat uninitialized
-variable definitions this way.
+definition.  This behavior does not conform to ISO C, is inconsistent with C++,
+and on many targets implies a speed and code size penalty on global variable
+references.  It is mainly useful to enable legacy code to link without errors.
 
 @item -fno-ident
 @opindex fno-ident

^ permalink raw reply	[flat|nested] 46+ messages in thread
* Re: [PATCH] PR85678: Change default to -fno-common
@ 2019-10-28 19:04 David Edelsohn
  2019-10-28 19:46 ` Richard Biener
  0 siblings, 1 reply; 46+ messages in thread
From: David Edelsohn @ 2019-10-28 19:04 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: Jeff Law, GCC Patches, nd

>> Has this been bootstrapped and regression tested?
>
> Yes, it bootstraps OK of course. I ran regression over the weekend, there
> are a few minor regressions in lto due to relying on tentative definitions
> and a few latent bugs. I'd expect there will be a few similar failures on
> other targets but nothing major since few testcases rely on -fcommon.

This almost certainly will break AIX.

- David

^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2019-12-05 16:49 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25 16:00 [PATCH] PR85678: Change default to -fno-common Wilco Dijkstra
2019-10-25 19:11 ` Georg-Johann Lay
2019-10-26 12:45   ` Iain Sandoe
2019-10-26 13:27     ` Segher Boessenkool
2019-10-25 22:44 ` Segher Boessenkool
2019-10-26 18:21 ` Jeff Law
2019-10-28 16:15   ` Wilco Dijkstra
2019-10-28 18:44     ` Segher Boessenkool
2019-10-27  5:58 ` Harald van Dijk
2019-10-29 13:06 ` [PATCH v2] " Wilco Dijkstra
2019-10-30 14:10   ` Richard Biener
2019-10-30 14:33     ` Wilco Dijkstra
2019-11-04 13:39       ` Richard Biener
2019-11-04 14:39         ` Wilco Dijkstra
2019-11-05 12:25           ` Richard Biener
2019-11-05 17:17             ` [PATCH v3] " Wilco Dijkstra
2019-11-17 23:35               ` Jeff Law
2019-11-21  0:41               ` [PATCH] Fix libgo build (was Re: [PATCH v3] PR85678: Change default to -fno-common) Jakub Jelinek
2019-11-21  0:46                 ` Rainer Orth
2019-11-21  1:04                   ` Jakub Jelinek
2019-11-21 11:40                     ` Rainer Orth
2019-11-21 11:40                       ` Jakub Jelinek
2019-11-21 11:54                       ` Wilco Dijkstra
2019-11-21 11:58                         ` Jakub Jelinek
2019-11-21  1:11                 ` Ian Lance Taylor
2019-11-29 13:17 ` [PATCH] PR85678: Change default to -fno-common Martin Liška
2019-11-29 14:46   ` Wilco Dijkstra
2019-11-29 15:09     ` Martin Liška
2019-12-01  4:17   ` Jeff Law
2019-12-04 15:26     ` Wilco Dijkstra
2019-12-04 17:27       ` Jeff Law
2019-12-04 21:03         ` Joseph Myers
2019-12-04 21:14           ` Jeff Law
2019-12-05  9:16         ` Martin Liška
2019-12-05 10:01           ` Tobias Burnus
2019-12-05 13:18             ` Wilco Dijkstra
2019-12-05 16:49               ` Jeff Law
2019-12-05 15:40           ` Jeff Law
2019-10-28 19:04 David Edelsohn
2019-10-28 19:46 ` Richard Biener
2019-10-28 20:06   ` Jeff Law
2019-10-28 20:29     ` Wilco Dijkstra
2019-10-28 21:52       ` Iain Sandoe
2019-10-29  8:42         ` Richard Biener
2019-10-29 12:15         ` Wilco Dijkstra
2019-10-29 12:27           ` Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).