From patchwork Wed Jan 18 12:13:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 716612 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 3v3QrJ31K1z9t0q for ; Wed, 18 Jan 2017 23:14:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="PvEgvjlE"; 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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=VStZp3Sm4H08pE4APn3xrL3R0eRAk6C0lD8e7HpKsu4V8bqnA/ tj3wBcRpyUHyB72PLufZzM1nD0TqeP7G++UxkQWeMeCRcDM+HWKWRAGxbeDlNDKj e0sEMMgHIQMjoJm3ORRHa0hqBILb0SBLfvV12wcsZD1vDsrfm7Aq6rl78= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=IF9G9JpOHE9dQfgjMhvTo4Xh5WM=; b=PvEgvjlEYiqxlfvuCZEA Z/213gexJazySWvKgTRKhHNqY/tJ2Iw9ofeD4abTOMiSowvZkknPFX/fmVxEyK5V qtoLvAdf3UZ+uWguAF8Yay8xg7EwjbF2q6I7N61KG1lAB5sRu/tr5qR2IXuiRLWN kGYtdI3NKqT/8BaLd9hwMlg= Received: (qmail 4117 invoked by alias); 18 Jan 2017 12:14:13 -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 4095 invoked by uid 89); 18 Jan 2017 12:14:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=one's, Moves, interest X-HELO: mail-yb0-f177.google.com Received: from mail-yb0-f177.google.com (HELO mail-yb0-f177.google.com) (209.85.213.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Jan 2017 12:14:01 +0000 Received: by mail-yb0-f177.google.com with SMTP id 123so3288243ybe.3 for ; Wed, 18 Jan 2017 04:14:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=z+F6VeRLgIw2IH0xSSwUBHDufV55vgea+X5og7UuWsM=; b=NBDp4EiQgV8YBc0AyDtYhK0fTXJlgLk4AwzwPjaf5hXspB+GvXB3PIdXpBZuedfpha z+Jme807dVbNhG7ajtyJjZeb20dxV6Me+QzQSWIPTB7nT9ONYzcRGIrwuPDLgtjWjxVe Pg/ey9K4mV1dPm6h3Qh1ME1d8B3RlDw/ZegVuakS7JbKTIi0sbGGg4DYWiau+zj6vEkC ukA371qLxxUKD0mHd5CeVGAPpzIZHMrZJtYP0D1QLx8bhSmLJeONUTppt2ZEGRBS3Z5T vsGb/5Mj2WFH+m6/keekyBsQiNQB2C/sMPlnmLpoBcx6egpKyGab6RCV2dZuTNIvtNq6 r1OA== X-Gm-Message-State: AIkVDXKYekX9sbrp4iDjHFPHqo+3xOKuNsm3yXMp2kBflF1SI6v1NuzwyAXRHbs8Ffd55A== X-Received: by 10.37.174.70 with SMTP id g6mr2056694ybe.169.1484741639329; Wed, 18 Jan 2017 04:13:59 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::9:7c73]) by smtp.googlemail.com with ESMTPSA id b7sm40028ywc.8.2017.01.18.04.13.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jan 2017 04:13:58 -0800 (PST) To: Jan Hubicka Cc: GCC Patches From: Nathan Sidwell Subject: [WPA PATCH] Comdat group splitting Message-ID: <3b5615c7-ec54-7b27-f353-1e898b798677@acm.org> Date: Wed, 18 Jan 2017 07:13:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 honza, this is the fix for the partitioned WPA bug I was tracking down. We have base and complete dtors sharing a comdat group (one's an alias for the other). The linker tells us the complete dtor is PREVAILING_DEF, as it's referenced from some other library. The base dtor is UNKNOWN. We therefore internalize the base dtor, making it PREVAILING_DEF_IRONLY and split the comdat group. But the comdat group splitting also internalizes the complete dtor /and/ it does so inconsistently. The bug manifested at runtime w/o link error as the complete dtor resolved to zero in the final link from wpa partitions that didn't contain its definition. (For extra fun, that was via a call to __cxa_at_exit registering a null function pointer, and getting the subsequent seg fault at program exit.) When we created WPA partitions node->externally_visible was still set, so we thought the now-internalized complete dtor was still externally visible -- but varasm looks at the DECL itself and emits an internal one. Plus the references to it were weak (& now hidden), so resolved to zero, rather than link error. And the external library either had its own definition which then prevailed for it. All rather 'ew'. Anyway, this patch does 3 things 1) Moves the next->unique_name adjustment to before make_decl_local for members of the comdat group -- that matches the behaviour of the decl of interest itself. 2) For LDPR_PREVAILING_DEF members we don't make_decl_local, but instead clear DECL_COMDAT and DECL_WEAK. Thus forcing this decl to be the prevailing decl in the final link 3) For decls we localize, we also clear node->externally_visible and node->force_by_abi. That matches the behavior for the decl of interest too and will clue the wpa partitioning logic into knowing it needs to hidden-externalize the decl. ok? nathan 2017-01-18 Nathan Sidwell * ipa-visibility.c (localize_node): Set comdat's unique name before adjusting resolution. Make PREVAILING_DEF members strongly public. Set visibility to false for localized decls. Index: ipa-visibility.c =================================================================== --- ipa-visibility.c (revision 244546) +++ ipa-visibility.c (working copy) @@ -542,16 +542,32 @@ localize_node (bool whole_program, symta for (symtab_node *next = node->same_comdat_group; next != node; next = next->same_comdat_group) { - next->set_comdat_group (NULL); - if (!next->alias) - next->set_section (NULL); - if (!next->transparent_alias) - next->make_decl_local (); next->unique_name |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) && TREE_PUBLIC (next->decl) && !flag_incremental_link); + + next->set_comdat_group (NULL); + if (!next->alias) + next->set_section (NULL); + if (next->transparent_alias) + /* Do nothing. */; + else if (next->resolution == LDPR_PREVAILING_DEF) + { + /* Make this a strong defn, so the external + users don't mistakenly choose some other + instance. */ + DECL_COMDAT (next->decl) = false; + DECL_WEAK (next->decl) = false; + } + else + { + next->externally_visible = false; + next->forced_by_abi = false; + next->resolution = LDPR_PREVAILING_DEF_IRONLY; + next->make_decl_local (); + } } /* Now everything's localized, the grouping has no meaning, and