From: Kai Tietz <ktietz70@googlemail.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [patch mingw]: Fix PR/51726 - LTO and attribute 'selectany'
Date: Thu, 01 Oct 2015 18:46:00 -0000 [thread overview]
Message-ID: <CAEwic4aLzveiVwqyitFfMQXVBFYekDjg-UycAecCK1eZTrYhUA@mail.gmail.com> (raw)
Hello,
This patch fixes the reported LTO issue, which is caused by not
implemented case of uniinitialized variables with selectany-attribute
(as common), as such variables couldn't be placed into
linkonce-section for pe-coff.
I adjusted existing testcase to reflect now supported case of
selectany-attribute on uninitialized variables, too.
ChangeLog
2015-10-01 Kai Tietz <ktietz70@googlemail.com>
PR target/51726
* config/i386/winnt.c (ix86_handle_selectany_attribute): Handle
selectany within this function without need to keep attribute.
(i386_pe_encode_section_info): Remove selectany-code.
I regression-tested this patch for i686 and x86_64 mingw &
cygwin-targets. will apply this patch tomorrow, if there are no
objections.
Kai
Index: winnt.c
===================================================================
--- winnt.c (Revision 228280)
+++ winnt.c (Arbeitskopie)
@@ -89,17 +89,23 @@ tree
ix86_handle_selectany_attribute (tree *node, tree name, tree, int,
bool *no_add_attrs)
{
+ tree decl = *node;
/* The attribute applies only to objects that are initialized and have
external linkage. However, we may not know about initialization
- until the language frontend has processed the decl. We'll check for
- initialization later in encode_section_info. */
- if (TREE_CODE (*node) != VAR_DECL || !TREE_PUBLIC (*node))
- {
- error ("%qE attribute applies only to initialized variables"
- " with external linkage", name);
- *no_add_attrs = true;
+ until the language frontend has processed the decl. Therefore
+ we make sure that variable isn't initialized as common. */
+ if (TREE_CODE (decl) != VAR_DECL || !TREE_PUBLIC (decl))
+ error ("%qE attribute applies only to initialized variables"
+ " with external linkage", name);
+ else
+ {
+ make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
+ /* A variable with attribute selectany never can be common. */
+ DECL_COMMON (decl) = 0;
}
+ /* We don't need to keep attribute itself. */
+ *no_add_attrs = true;
return NULL_TREE;
}
@@ -320,23 +326,7 @@ i386_pe_encode_section_info (tree decl, rtx rtl, i
switch (TREE_CODE (decl))
{
case FUNCTION_DECL:
- break;
-
case VAR_DECL:
- if (lookup_attribute ("selectany", DECL_ATTRIBUTES (decl)))
- {
- if (DECL_INITIAL (decl)
- /* If an object is initialized with a ctor, the static
- initialization and destruction code for it is present in
- each unit defining the object. The code that calls the
- ctor is protected by a link-once guard variable, so that
- the object still has link-once semantics, */
- || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
- make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
- else
- error ("%q+D:'selectany' attribute applies only to "
- "initialized objects", decl);
- }
break;
default:
ChangeLog
2015-10-01 Kai Tietz <ktietz70@googlemail.com>
PR target/51726
* g++.dg/ext/sectany2.C: Allow uninitialized variable case.
Index: g++.dg/ext/selectany2.C
===================================================================
--- g++.dg/ext/selectany2.C (Revision 228347)
+++ g++.dg/ext/selectany2.C (Arbeitskopie)
@@ -18,7 +18,7 @@ struct f
};
__declspec (selectany) struct f F= {1}; // OK
-__declspec (selectany) int boo; //{ dg-error "selectany" }
+__declspec (selectany) int boo; // OK
__declspec (selectany) static int bar = 1; // { dg-error "selectany" }
int use_bar = bar; // Avoid defined but not used warning.
reply other threads:[~2015-10-01 18:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=CAEwic4aLzveiVwqyitFfMQXVBFYekDjg-UycAecCK1eZTrYhUA@mail.gmail.com \
--to=ktietz70@googlemail.com \
--cc=gcc-patches@gcc.gnu.org \
/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).