public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Gerald Pfeifer <gerald@pfeifer.com>,
	       Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cc: Sandra Loosemore <sandra@codesourcery.com>,
	       Jonathan Wakely <jwakely@redhat.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>,
	       Joseph Myers <joseph@codesourcery.com>
Subject: [wwwdocs] Mention common attribute in gcc-10/porting_to.html
Date: Thu, 06 Feb 2020 20:07:00 -0000	[thread overview]
Message-ID: <20200206200724.GP17695@tucnak> (raw)
In-Reply-To: <AM5PR0801MB2035090868D382FB72A2B028833F0@AM5PR0801MB2035.eurprd08.prod.outlook.com>

Hi!

On Tue, Jan 07, 2020 at 03:15:05PM +0000, Wilco Dijkstra wrote:
> --- a/htdocs/gcc-10/porting_to.html
> +++ b/htdocs/gcc-10/porting_to.html
> @@ -29,9 +29,25 @@ and provide solutions. Let us know if you have suggestions for improvements!
>  <h2 id="cpp">Preprocessor issues</h2>
>  -->
>  
> -<!--
>  <h2 id="c">C language issues</h2>
> --->
> +
> +<h3 id="common">Default to <code>-fno-common</code></h3>
> +
> +<p>
> +  A common mistake in C is omitting <code>extern</code> when declaring a global
> +  variable in a header file.  If the header is included by several files it
> +  results in multiple definitions of the same variable.  In previous GCC
> +  versions this error is ignored.  GCC 10 defaults to <code>-fno-common</code>,
> +  which means a linker error will now be reported.
> +  To fix this, use <code>extern</code> in header files when declaring global
> +  variables, and ensure each global is defined in exactly one C file.
> +  As a workaround, legacy C code can be compiled with <code>-fcommon</code>.
> +</p>
> +  <pre><code>
> +      int x;  // tentative definition - avoid in header files
> +
> +      extern int y;  // correct declaration in a header file
> +  </code></pre>
>  
>  <h2 id="fortran">Fortran language issues</h2>

IMHO we should mention also the common attribute, in some cases the common
behavior is intentional decision and there is no problem supporting it,
just the code should mark it explicitly.

Ok for wwwdocs?

diff --git a/htdocs/gcc-10/porting_to.html b/htdocs/gcc-10/porting_to.html
index 980d3af1..c5d7eb82 100644
--- a/htdocs/gcc-10/porting_to.html
+++ b/htdocs/gcc-10/porting_to.html
@@ -41,7 +41,12 @@ and provide solutions. Let us know if you have suggestions for improvements!
   which means a linker error will now be reported.
   To fix this, use <code>extern</code> in header files when declaring global
   variables, and ensure each global is defined in exactly one C file.
-  As a workaround, legacy C code can be compiled with <code>-fcommon</code>.
+  If tentative definitions of particular variable or variables need to be
+  placed in a common block, <code>__attribute__((__common__))</code> can be
+  used to force that behavior for those even in code compiled without
+  <code>-fcommon</code>.
+  As a workaround, legacy C code where all tentative definitions should
+  be placed into a common block can be compiled with <code>-fcommon</code>.
 </p>
   <pre><code>
       int x;  // tentative definition - avoid in header files


	Jakub

  parent reply	other threads:[~2020-02-06 20:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05 13:14 [wwwdocs] Document -fcommon default change Wilco Dijkstra
2020-01-06 14:10 ` Jonathan Wakely
2020-01-06 16:25   ` Sandra Loosemore
2020-01-07 15:15     ` Wilco Dijkstra
2020-01-11 10:27       ` Gerald Pfeifer
2020-02-06 20:07       ` Jakub Jelinek [this message]
2020-02-06 22:18         ` [wwwdocs] Mention common attribute in gcc-10/porting_to.html Gerald Pfeifer
2020-02-07  1:34           ` Sandra Loosemore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200206200724.GP17695@tucnak \
    --to=jakub@redhat.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gerald@pfeifer.com \
    --cc=joseph@codesourcery.com \
    --cc=jwakely@redhat.com \
    --cc=sandra@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).