Hi Richard,
> Please investigate those - C++ has -fno-common already so it might be a mix
> of C/C++ required here. Note that secondary files can use dg-options
> with the same behavior as dg-additional-options (they append to
> dg-lto-options),
> so here in _1.c add { dg-options "-fcommon" }
The odr-6 test mixes C and C++ using .C/.c extensions. But like you suggest,
dg-options
works on the 2nd file, and with that odr-6 and pr88077 tests pass without
needing changes
in lto.exp. I needed to change one of the types since default object alignment
is different
between -fcommon and -fno-common and that causes linker failures when linking
objects
built with different -fcommon settings. I also checked regress on x64, there
was one minor
failure because of the alignment change, which is easily fixed.
So here is v3:
[PATCH v3] PR85678: Change default to -fno-common
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.
Passes bootstrap and regress on AArch64 and x64. OK for commit?
ChangeLog
2019-11-05 Wilco Dijkstra <[email protected]>
PR85678
* common.opt (fcommon): Change init to 1.
doc/
* invoke.texi (-fcommon): Update documentation.
testsuite/
* g++.dg/lto/odr-6_1.c: Add -fcommon.
* gcc.dg/alias-15.c: Likewise.
* gcc.dg/fdata-sections-1.c: Likewise.
* gcc.dg/ipa/pr77653.c: Likewise.
* gcc.dg/lto/20090729_0.c: Likewise.
* gcc.dg/lto/20111207-1_0.c: Likewise.
* gcc.dg/lto/c-compatible-types-1_0.c: Likewise.
* gcc.dg/lto/pr55525_0.c: Likewise.
* gcc.dg/lto/pr88077_0.c: Use long to avoid alignment warning.
* gcc.dg/lto/pr88077_1.c: Add -fcommon.
* gcc.target/aarch64/sve/peel_ind_1.c: Allow ANCHOR0.
* gcc.target/aarch64/sve/peel_ind_2.c: Likewise.
* gcc.target/aarch64/sve/peel_ind_3.c: Likewise.
* gcc.target/i386/volatile-bitfields-2.c: Allow movl or movq.
diff --git a/gcc/common.opt b/gcc/common.opt
index
f74b10aafc223e4961915b009c092f4876eddba4..798b6aeff3536e21c95752b5dd085f8ffef04643
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
92fb316a368a4a36218fac6de2744c7ab6446ef5..18cfd07d4bbb4b866808db0701faf88bddbd9a94
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
@@ -14049,35 +14049,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
diff --git a/gcc/testsuite/g++.dg/lto/odr-6_1.c
b/gcc/testsuite/g++.dg/lto/odr-6_1.c
index
ee4bff44659d9ff22cdb92ca0031cfe86877ef15..8328bf59a4cb60173b86ea4153520d11d15a1b1f
100644
--- a/gcc/testsuite/g++.dg/lto/odr-6_1.c
+++ b/gcc/testsuite/g++.dg/lto/odr-6_1.c
@@ -1,3 +1,4 @@
+/* { dg-options {-fcommon} } */
struct {} admbaserest_; // { dg-lto-message "type of " 2 }
diff --git a/gcc/testsuite/gcc.dg/alias-15.c b/gcc/testsuite/gcc.dg/alias-15.c
index
0a8e69b61eceef95e61f16d7874b5a4204e0594f..304ad1fbaeb7fe68ef26efd31c2ee545db6a0ffc
100644
--- a/gcc/testsuite/gcc.dg/alias-15.c
+++ b/gcc/testsuite/gcc.dg/alias-15.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-additional-options "-O2 -fdump-ipa-cgraph" } */
+/* { dg-additional-options "-O2 -fcommon -fdump-ipa-cgraph" } */
/* RTL-level CSE shouldn't introduce LCO (for the string) into varpool */
char *p;
diff --git a/gcc/testsuite/gcc.dg/fdata-sections-1.c
b/gcc/testsuite/gcc.dg/fdata-sections-1.c
index
e8a6639f32e38fdb539232288c92000f000ca79e..de5ddfc0179a588ce1bdb3d5f39a14438823c071
100644
--- a/gcc/testsuite/gcc.dg/fdata-sections-1.c
+++ b/gcc/testsuite/gcc.dg/fdata-sections-1.c
@@ -2,7 +2,7 @@
/* Origin: Jonathan Larmour <[email protected]> */
/* { dg-do compile { target *-*-linux* *-*-gnu* *-*-uclinux* } } */
-/* { dg-options "-fdata-sections" } */
+/* { dg-options "-fcommon -fdata-sections" } */
int x;
diff --git a/gcc/testsuite/gcc.dg/ipa/pr77653.c
b/gcc/testsuite/gcc.dg/ipa/pr77653.c
index
f0b2b224091583bcf51d8d7444033c2042de3b7b..2fddb7eab548690a7a9d2edb3172c2b17ff9ea63
100644
--- a/gcc/testsuite/gcc.dg/ipa/pr77653.c
+++ b/gcc/testsuite/gcc.dg/ipa/pr77653.c
@@ -1,5 +1,5 @@
/* { dg-require-alias "" } */
-/* { dg-options "-O2 -fdump-ipa-icf-details" } */
+/* { dg-options "-O2 -fcommon -fdump-ipa-icf-details" } */
int a, b, c, d, e, h, i, j, k, l;
const int f;
diff --git a/gcc/testsuite/gcc.dg/lto/20090729_0.c
b/gcc/testsuite/gcc.dg/lto/20090729_0.c
index
05ae74f872e28c417a8032688b3c75cd38eb6f6f..13fe62b5923b7c868373d8ca269730aa588d4992
100644
--- a/gcc/testsuite/gcc.dg/lto/20090729_0.c
+++ b/gcc/testsuite/gcc.dg/lto/20090729_0.c
@@ -1,4 +1,4 @@
-/* { dg-lto-options "-w" } */
+/* { dg-lto-options { {-fcommon -w} {-fcommon} } } */
double i;
int j;
diff --git a/gcc/testsuite/gcc.dg/lto/20111207-1_0.c
b/gcc/testsuite/gcc.dg/lto/20111207-1_0.c
index
486264066f6fcab4a248fd6293af2b6cae65caf5..5f11264af17a5a50c6d27e6eb8667bbdfce131f1
100644
--- a/gcc/testsuite/gcc.dg/lto/20111207-1_0.c
+++ b/gcc/testsuite/gcc.dg/lto/20111207-1_0.c
@@ -1,4 +1,4 @@
/* { dg-lto-do run } */
-/* { dg-lto-options { { -flto } } } */
+/* { dg-lto-options { { -flto -fcommon } {-fcommon} {-fcommon} {-fcommon} } }
*/
/* { dg-require-linker-plugin "" } */
/* { dg-extra-ld-options "-fuse-linker-plugin" } */
diff --git a/gcc/testsuite/gcc.dg/lto/c-compatible-types-1_0.c
b/gcc/testsuite/gcc.dg/lto/c-compatible-types-1_0.c
index
376da00599d04a738b8b5d6c6d3625d915cae83b..45b03735a6befd47b5b24cab5c62ecc8792aed4c
100644
--- a/gcc/testsuite/gcc.dg/lto/c-compatible-types-1_0.c
+++ b/gcc/testsuite/gcc.dg/lto/c-compatible-types-1_0.c
@@ -1,5 +1,5 @@
/* { dg-lto-do run } */
-/* { dg-lto-options "-O3" } */
+/* { dg-lto-options { {-O3 -fcommon} {-fcommon} } } */
/* By C standard Each enumerated type shall be compatible with char, a signed
integer, type, or an unsigned integer type. The choice of type is
diff --git a/gcc/testsuite/gcc.dg/lto/pr55525_0.c
b/gcc/testsuite/gcc.dg/lto/pr55525_0.c
index
7faaf806a75836be4eb9a3ede7559dd4d4151185..d8d16d11d32d3918bc47f4b41c7e7dabe255fd39
100644
--- a/gcc/testsuite/gcc.dg/lto/pr55525_0.c
+++ b/gcc/testsuite/gcc.dg/lto/pr55525_0.c
@@ -1,5 +1,5 @@
/* { dg-lto-do link } */
-/* { dg-lto-options { { -flto -w } } } */
+/* { dg-lto-options { { -fcommon -flto -w } } } */
char s[sizeof (char *)];
int main(void)
diff --git a/gcc/testsuite/gcc.dg/lto/pr88077_0.c
b/gcc/testsuite/gcc.dg/lto/pr88077_0.c
index
9e464b6ad4a246d8b5b813626a4b858629db299a..924fe9fc3f01f64c2712480c5507693e66e7b5f8
100644
--- a/gcc/testsuite/gcc.dg/lto/pr88077_0.c
+++ b/gcc/testsuite/gcc.dg/lto/pr88077_0.c
@@ -1,3 +1,3 @@
/* { dg-lto-do link } */
-int HeaderStr;
+long HeaderStr;
diff --git a/gcc/testsuite/gcc.dg/lto/pr88077_1.c
b/gcc/testsuite/gcc.dg/lto/pr88077_1.c
index
fd3de3e77a6215e4ab263cc277b408998fe6e505..43d783f2cc7dd4ad1cb34a8ea314bb062410539d
100644
--- a/gcc/testsuite/gcc.dg/lto/pr88077_1.c
+++ b/gcc/testsuite/gcc.dg/lto/pr88077_1.c
@@ -1,3 +1,5 @@
+/* { dg-options {-fcommon} } */
+
char HeaderStr[1];
int main()
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_1.c
b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_1.c
index
156d04ae5ca222ddea3e12a3b785050c6113a548..e9afc2047e49e4382fd2cc5b150de51be89e2e3d
100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_1.c
@@ -21,7 +21,7 @@ foo (void)
}
/* We should operate on aligned vectors. */
-/* { dg-final { scan-assembler {\t(adrp|adr)\tx[0-9]+, x\n} } } */
+/* { dg-final { scan-assembler {\t(adrp|adr)\tx[0-9]+, (x|\.LANCHOR0)\n} } } */
/* We should use an induction that starts at -5, with only the last
7 elements of the first iteration being active. */
/* { dg-final { scan-assembler {\tindex\tz[0-9]+\.s, #-5, #5\n} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_2.c
b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_2.c
index
e792cdf2cad297e7044fdecd576343c9ac212078..6bd7fc73fb03d339b17c62d1ad818c9bdb351e1b
100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_2.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_2.c
@@ -17,7 +17,7 @@ foo (void)
}
/* We should operate on aligned vectors. */
-/* { dg-final { scan-assembler {\t(adrp|adr)\tx[0-9]+, x\n} } } */
+/* { dg-final { scan-assembler {\t(adrp|adr)\tx[0-9]+, (x|\.LANCHOR0)\n} } } */
/* We should unroll the loop three times. */
/* { dg-final { scan-assembler-times "\tst1w\t" 3 } } */
/* { dg-final { scan-assembler {\tptrue\t(p[0-9]+)\.s,
vl7\n.*\teor\tp[0-7]\.b, (p[0-7])/z, (\1\.b, \2\.b|\2\.b, \1\.b)\n} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_3.c
b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_3.c
index
441589eef600df0d1b264780774a9bdc4deb975e..3adddf3f4049a73bae99ab3468f83c535ef55170
100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_3.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_3.c
@@ -17,5 +17,5 @@ foo (int start)
}
/* We should operate on aligned vectors. */
-/* { dg-final { scan-assembler {\t(adrp|adr)\tx[0-9]+, x\n} } } */
+/* { dg-final { scan-assembler {\t(adrp|adr)\tx[0-9]+, (x|\.LANCHOR0)\n} } } */
/* { dg-final { scan-assembler {\tubfx\t} } } */
diff --git a/gcc/testsuite/gcc.target/i386/volatile-bitfields-2.c
b/gcc/testsuite/gcc.target/i386/volatile-bitfields-2.c
index
302625a199b5b79d950592dcc869895753bf4884..d84363315a85131f8d6b2df6527e4b2ef6ffc478
100644
--- a/gcc/testsuite/gcc.target/i386/volatile-bitfields-2.c
+++ b/gcc/testsuite/gcc.target/i386/volatile-bitfields-2.c
@@ -14,4 +14,4 @@ int foo ()
return bits.b;
}
-/* { dg-final { scan-assembler "movl.*bits" } } */
+/* { dg-final { scan-assembler "mov(q|l).*bits" } } */