]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR target/37216 ([cygming] Invalid alignment for SSE store to .comm data generated...
authorDave Korn <dave.korn.cygwin@gmail.com>
Thu, 28 May 2009 10:48:35 +0000 (10:48 +0000)
committerDave Korn <davek@gcc.gnu.org>
Thu, 28 May 2009 10:48:35 +0000 (10:48 +0000)
gcc/ChangeLog:

2009-05-28  Dave Korn  <dave.korn.cygwin@gmail.com>

PR target/37216

* configure.ac (HAVE_GAS_ALIGNED_COMM):  Add autoconf test and
macro definition for support of three-operand format aligned
.comm directive in assembler on cygwin/pe/mingw target OS.
* configure:  Regenerate.
* config.in:  Regenerate.

* config/i386/winnt.c (i386_pe_asm_output_aligned_decl_common):  Use
aligned form of .comm directive if -mpe-aligned-commons is in effect.
* config/i386/cygming.opt (-mpe-aligned-commons):  Add new option.

* doc/invoke.texi (-mpe-aligned-commons):  Document new target option.
* doc/tm.texi (ASM_OUTPUT_COMMON):  Document zero size commons.

gcc/testsuite/ChangeLog:

2009-05-28  Dave Korn  <dave.korn.cygwin@gmail.com>
            Uros Bizjak  <ubizjak@gmail.com>
            Danny Smith  <dansmister@gmail.com>

PR target/37216

* lib/target-supports.exp (check_effective_target_pe_aligned_commons):
New function.
* gcc.target/i386/pr37216.c:  New test source file.
* gcc.dg/compat/struct-layout-1_generate.c (dg_options[]):  No longer
use -fno-common for testing Cygwin and MinGW targets.

Co-Authored-By: Danny Smith <dansmister@gmail.com>
Co-Authored-By: Uros Bizjak <ubizjak@gmail.com>
From-SVN: r147950

12 files changed:
gcc/ChangeLog
gcc/config.in
gcc/config/i386/cygming.opt
gcc/config/i386/winnt.c
gcc/configure
gcc/configure.ac
gcc/doc/invoke.texi
gcc/doc/tm.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/compat/struct-layout-1_generate.c
gcc/testsuite/gcc.target/i386/pr37216.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp

index b0c880386f4aca681bd07f4793b40c7abaf35213..cbbeee49a33080c6d9e915abb60f728407ba40d7 100644 (file)
@@ -1,3 +1,20 @@
+2009-05-28  Dave Korn  <dave.korn.cygwin@gmail.com>
+
+       PR target/37216
+
+       * configure.ac (HAVE_GAS_ALIGNED_COMM):  Add autoconf test and
+       macro definition for support of three-operand format aligned
+       .comm directive in assembler on cygwin/pe/mingw target OS.
+       * configure:  Regenerate.
+       * config.h:  Regenerate.
+
+       * config/i386/winnt.c (i386_pe_asm_output_aligned_decl_common):  Use
+       aligned form of .comm directive if -mpe-aligned-commons is in effect.
+       * config/i386/cygming.opt (-mpe-aligned-commons):  Add new option.
+
+       * doc/invoke.texi (-mpe-aligned-commons):  Document new target option.
+       * doc/tm.texi (ASM_OUTPUT_COMMON):  Document zero size commons.
+
 2009-05-28  Ira Rosen  <irar@il.ibm.com>
 
        PR tree-optimization/40254
index 76a7810f3d42b06d7bae49008f5b294d5f2e2bf3..9f53173e7c9d83622d62735b46937a7d1e339746 100644 (file)
 #endif
 
 
+/* Define if your assembler supports specifying the alignment of objects
+   allocated using the GAS .comm command. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GAS_ALIGNED_COMM
+#endif
+
+
 /* Define if your assembler supports .balign and .p2align. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_GAS_BALIGN_AND_P2ALIGN
index 7c29eb89b9f0187083ce34aecd3c43f2bbbcb4e1..e845a0d58276abb22d35066ca3991022a9f0fa53 100644 (file)
@@ -45,3 +45,7 @@ Set Windows defines
 mwindows
 Target
 Create GUI application
+
+mpe-aligned-commons
+Target Var(use_pe_aligned_common) Init(HAVE_GAS_ALIGNED_COMM)
+Use the GNU extension to the PE format for aligned common data
index 3d88517c234ff82b4c667c840f176370149b49c4..812cf798f7671465c01229168cd47e3cf2f96039 100644 (file)
@@ -499,8 +499,11 @@ i386_pe_asm_output_aligned_decl_common (FILE *stream, tree decl,
 {
   HOST_WIDE_INT rounded;
 
-  /* Compute as in assemble_noswitch_variable, since we don't actually
-     support aligned common.  */
+  /* Compute as in assemble_noswitch_variable, since we don't have
+     support for aligned common on older binutils.  We must also
+     avoid emitting a common symbol of size zero, as this is the
+     overloaded representation that indicates an undefined external
+     symbol in the PE object file format.  */
   rounded = size ? size : 1;
   rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
   rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
@@ -510,9 +513,13 @@ i386_pe_asm_output_aligned_decl_common (FILE *stream, tree decl,
 
   fprintf (stream, "\t.comm\t");
   assemble_name (stream, name);
-  fprintf (stream, ", " HOST_WIDE_INT_PRINT_DEC "\t" ASM_COMMENT_START
-          " " HOST_WIDE_INT_PRINT_DEC "\n",
-          rounded, size);
+  if (use_pe_aligned_common)
+    fprintf (stream, ", " HOST_WIDE_INT_PRINT_DEC ", %d\n",
+          size ? size : (HOST_WIDE_INT) 1,
+          exact_log2 (align) - exact_log2 (CHAR_BIT));
+  else
+    fprintf (stream, ", " HOST_WIDE_INT_PRINT_DEC "\t" ASM_COMMENT_START
+          " " HOST_WIDE_INT_PRINT_DEC "\n", rounded, size);
 }
 \f
 /* The Microsoft linker requires that every function be marked as
index 4bab41d4a5e05c35663d81e76f8ae536a3a9891a..8a4f2c91d786621f0c6c962a404b735aa9af9120 100755 (executable)
   i[34567]86-*-* | x86_64-*-*)
     case $target_os in
       cygwin* | pe | mingw32*)
+       # Recent binutils allows the three-operand form of ".comm" on PE.  This
+       # definition is used unconditionally to initialise the default state of
+       # the target option variable that governs usage of the feature.
+       echo "$as_me:$LINENO: checking assembler for .comm with alignment" >&5
+echo $ECHO_N "checking assembler for .comm with alignment... $ECHO_C" >&6
+if test "${gcc_cv_as_comm_has_align+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  gcc_cv_as_comm_has_align=no
+    if test $in_tree_gas = yes; then
+    if test $gcc_cv_gas_vers -ge `expr \( \( 2 \* 1000 \) + 19 \) \* 1000 + 52`
+  then gcc_cv_as_comm_has_align=yes
+fi
+  elif test x$gcc_cv_as != x; then
+    echo '.comm foo,1,32' > conftest.s
+    if { ac_try='$gcc_cv_as  -o conftest.o conftest.s >&5'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }
+    then
+       gcc_cv_as_comm_has_align=yes
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
+fi
+echo "$as_me:$LINENO: result: $gcc_cv_as_comm_has_align" >&5
+echo "${ECHO_T}$gcc_cv_as_comm_has_align" >&6
+
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_GAS_ALIGNED_COMM `if test $gcc_cv_as_comm_has_align = yes; then echo 1; else echo 0; fi`
+_ACEOF
+
        # Used for DWARF 2 in PE
        echo "$as_me:$LINENO: checking assembler for .secrel32 relocs" >&5
 echo $ECHO_N "checking assembler for .secrel32 relocs... $ECHO_C" >&6
index 80f942268cdbbae45314e96e01ccc34583afc8c8..b5a1f7e75321115c0d61d40c7ee2622748dfe688 100644 (file)
@@ -2954,6 +2954,15 @@ changequote(,)dnl
 changequote([,])dnl
     case $target_os in
       cygwin* | pe | mingw32*)
+       # Recent binutils allows the three-operand form of ".comm" on PE.  This
+       # definition is used unconditionally to initialise the default state of
+       # the target option variable that governs usage of the feature.
+       gcc_GAS_CHECK_FEATURE([.comm with alignment], gcc_cv_as_comm_has_align,
+        [2,19,52],,[.comm foo,1,32])
+       AC_DEFINE_UNQUOTED(HAVE_GAS_ALIGNED_COMM,
+         [`if test $gcc_cv_as_comm_has_align = yes; then echo 1; else echo 0; fi`],
+         [Define if your assembler supports specifying the alignment
+          of objects allocated using the GAS .comm command.])
        # Used for DWARF 2 in PE
        gcc_GAS_CHECK_FEATURE([.secrel32 relocs],
          gcc_cv_as_ix86_pe_secrel32,
index db9df63fb02bb975af10a05d9e4b2ee4848dee9a..6a79566b336c076f5878461bf13a290cda4c6e9d 100644 (file)
@@ -15678,6 +15678,15 @@ This option is available for Cygwin and MinGW targets.  It
 specifies that a GUI application is to be generated by
 instructing the linker to set the PE header subsystem type
 appropriately.
+
+@item -mpe-aligned-commons
+@opindex mpe-aligned-commons
+This option is available for Cygwin and MinGW targets.  It
+specifies that the GNU extension to the PE file format that 
+permits the correct alignment of COMMON variables should be
+used when generating code.  It will be enabled by default if
+GCC detects that the target assembler found during configuration
+supports the feature.
 @end table
 
 See also under @ref{i386 and x86-64 Options} for standard options.
index 552d5c9ef8a686ba6a7a4c3b77eac2c0e1728d92..bc15583bfb09900353e04d1852c71031a69181a4 100644 (file)
@@ -7384,7 +7384,14 @@ outputting a single uninitialized variable.
 A C statement (sans semicolon) to output to the stdio stream
 @var{stream} the assembler definition of a common-label named
 @var{name} whose size is @var{size} bytes.  The variable @var{rounded}
-is the size rounded up to whatever alignment the caller wants.
+is the size rounded up to whatever alignment the caller wants.  It is
+possible that @var{size} may be zero, for instance if a struct with no
+other member than a zero-length array is defined.  In this case, the
+backend must output a symbol definition that allocates at least one
+byte, both so that the address of the resulting object does not compare
+equal to any other, and because some object formats cannot even express
+the concept of a zero-sized common symbol, as that is how they represent
+an ordinary undefined external.
 
 Use the expression @code{assemble_name (@var{stream}, @var{name})} to
 output the name itself; before and after that, output the additional
index 3e3c18e19edf71bda9cbd8730c4a3f4c7a0b648d..3446982ab9981026690db81100043ab488e7614b 100644 (file)
@@ -1,3 +1,15 @@
+2009-05-28  Dave Korn  <dave.korn.cygwin@gmail.com>
+            Uros Bizjak  <ubizjak@gmail.com>
+            Danny Smith  <dansmister@gmail.com>
+
+       PR target/37216
+
+       * lib/target-supports.exp (check_effective_target_pe_aligned_commons):
+       New function.
+       * gcc.target/i386/pr37216.c:  New test source file.
+       * gcc.dg/compat/struct-layout-1_generate.c (dg_options[]):  No longer
+       use -fno-common for testing Cygwin and MinGW targets.
+
 2009-05-28  Kai Tietz  <kai.tietz@onevision.com>
 
        *  g++.dg/ext/packed6.C (size_t): Use __extension__ and
index f563c2774bd23f80f4c99f56fcd315662f7ad84e..4f5315df2c22eab56baea2623982eb954ec563d6 100644 (file)
@@ -46,7 +46,7 @@ const char *dg_options[] = {
 "/* { dg-options \"%s-I%s\" } */\n",
 "/* { dg-options \"%s-I%s -Wno-abi\" } */\n",
 "/* { dg-options \"%s-I%s -mno-mmx -Wno-abi\" { target i?86-*-* x86_64-*-* } } */\n",
-"/* { dg-options \"%s-I%s -fno-common\" { target hppa*-*-hpux* powerpc*-*-darwin* *-*-mingw32* *-*-cygwin* } } */\n",
+"/* { dg-options \"%s-I%s -fno-common\" { target hppa*-*-hpux* powerpc*-*-darwin* } } */\n",
 "/* { dg-options \"%s-I%s -mno-mmx -fno-common -Wno-abi\" { target i?86-*-darwin* x86_64-*-darwin* } } */\n",
 "/* { dg-options \"%s-I%s -mno-base-addresses\" { target mmix-*-* } } */\n",
 "/* { dg-options \"%s-I%s -mlongcalls -mtext-section-literals\" { target xtensa*-*-* } } */\n"
diff --git a/gcc/testsuite/gcc.target/i386/pr37216.c b/gcc/testsuite/gcc.target/i386/pr37216.c
new file mode 100644 (file)
index 0000000..5c847a7
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-options "-O3 -msse2" } */
+/* { dg-options "-O3 -msse2 -mpe-aligned-commons" { target pe_aligned_commons } } */
+
+#include "sse2-check.h"
+
+int iarr[64];
+int iint = 0;
+
+void
+sse2_test (void)
+{
+  int i;
+
+  for (i = 0; i < 64; i++)
+    iarr[i] = -2;
+}
index f726e6f05d00f16048699ea191e9f9bdb2a22a92..e2d24c8c156c2f2bdc1afb1249b8a6e2a3e0d8d8 100644 (file)
@@ -611,6 +611,18 @@ proc check_effective_target_pthread {} {
     } "-pthread"]
 }
 
+# Return 1 if compilation with -mpe-aligned-commons is error-free
+# for trivial code, 0 otherwise.
+
+proc check_effective_target_pe_aligned_commons {} {
+    if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
+       return [check_no_compiler_messages pe_aligned_commons object {
+           int foo;
+       } "-mpe-aligned-commons"]
+    }
+    return 0
+}
+
 # Return 1 if the target supports -fstack-protector
 proc check_effective_target_fstack_protector {} {
     return [check_runtime fstack_protector {