From patchwork Thu Oct 1 18:45:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 525269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D1FD6140D16 for ; Fri, 2 Oct 2015 04:46:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=fDpBWlqw; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=Yojsb2n/WYS7dCRVb2NR4KTvVc7xCGsXS/HM8/fDJBUhf8 i6Ovdtm9V8x8gT0dg0KDxDJ+/aZukWU8U3hGll4/+JgXsVR99mZikKSzOjy3miVV 0q7Xq8cfyUzPcPHp0NcquRm7hZh71/i8ztziXaFisK8S7sFqeU6Lw7UXOGDFQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=9nogJuoMITroWu336bbneo210dQ=; b=fDpBWlqwyDfqDQocX8iW 1eV5HF2FCPp0Kqs1dABzgdsWqhPIDu0WFFzyU/rgUHoPqYk8Qg5yIA4UEGo4w7hx DZRauS9fLNyxvVrz+ruxvao2niRoCDj+wovb7wXySznMN7PDDI2G38qB7DYgIBF5 Y1RstKUVq0+d22vmfGckyjI= Received: (qmail 18485 invoked by alias); 1 Oct 2015 18:46:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 18475 invoked by uid 89); 1 Oct 2015 18:46:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wi0-f182.google.com Received: from mail-wi0-f182.google.com (HELO mail-wi0-f182.google.com) (209.85.212.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 01 Oct 2015 18:46:02 +0000 Received: by wicgb1 with SMTP id gb1so2261690wic.1 for ; Thu, 01 Oct 2015 11:45:59 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.180.86.39 with SMTP id m7mr263668wiz.91.1443725159234; Thu, 01 Oct 2015 11:45:59 -0700 (PDT) Received: by 10.27.212.71 with HTTP; Thu, 1 Oct 2015 11:45:59 -0700 (PDT) Date: Thu, 1 Oct 2015 20:45:59 +0200 Message-ID: Subject: [patch mingw]: Fix PR/51726 - LTO and attribute 'selectany' From: Kai Tietz To: GCC Patches X-IsSubscribed: yes 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 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 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.