From patchwork Fri Feb 14 22:41:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1238364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519573-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=MfiwdpXX; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=tTVkIZ6m; dkim-atps=neutral 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 48K7dw4wZcz9s29 for ; Sat, 15 Feb 2020 09:41:22 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=dYEmHha6LILEO/3HZTuHSHdbfUrHssjXEiUNpHLdejQB1wQGNwAYC 6mwexJHnCcb9dhmYV1lyL63gQxFev9k8LsnSbGXRqCbv8NelwbLQEk6Pb+YQ6vKV XkO3yUtnHfYuEXK3qthaO9DdHFdvFJw0XcW3ZWWEuI4hogk5w/iIKM= 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:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=yhGqPwmbhdWYAdqaqIt083SoOz8=; b=MfiwdpXXnLKPO78apD/P eglEhwQSlifPEAjtIMi5+OuaTbT6Re1nUaxW8jwiu3V7wnQBU+jZDRTPxLE/bPz1 ncUaSJbjavXJRhc36C+CDK65mCvsVnu4zOpt1/68xHV2lOtXT2Z37IVszYvkCRXn Yqljo0UbNXGbXXSN2vXJnYk= Received: (qmail 73898 invoked by alias); 14 Feb 2020 22:41:15 -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 73890 invoked by uid 89); 14 Feb 2020 22:41:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:attr-we, sk:attrwe X-HELO: mail-qk1-f195.google.com Received: from mail-qk1-f195.google.com (HELO mail-qk1-f195.google.com) (209.85.222.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Feb 2020 22:41:13 +0000 Received: by mail-qk1-f195.google.com with SMTP id c188so10804341qkg.4 for ; Fri, 14 Feb 2020 14:41:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-language; bh=WMcls5fx21mGTSJ80LOwS+mdogs58scl4giKc1pE6UM=; b=tTVkIZ6mERj1162YTHWBA8SKd2oBMpc+oeCf9sUtQTkAmGoCHOjvnFNYfunUAvzba/ 3xUVHvi7apD3W9QKaQAb3kZ+VreziMLEQGH90PfrXWqcyITOj7IelGz6YY31rbHXX70a 5QObe+tVVXU1YaS2UVXWf1V0n1WVbbYM6wca5Z7Gq6ktDuVYckqsMzTcxg5NeRdBq29u NhFkIR4v+N1gRqfCHRo+oH9vQdlk/fHAnD6gOL2Kc0CsHi2a7p+x2CSfKTpIindO8IJ9 O+1r/oAR1YaS3QY1wUJLDa5eFAr+N5r26CQVH2xeH88zbyJdpUQFr3qPm9Z10KwCjO8i 8IJg== Received: from [192.168.0.41] (174-16-112-158.hlrn.qwest.net. [174.16.112.158]) by smtp.gmail.com with ESMTPSA id b35sm4296572qtc.9.2020.02.14.14.41.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Feb 2020 14:41:11 -0800 (PST) From: Martin Sebor Subject: [PATCH] drop weakref attribute on function definitions (PR 92799) To: gcc-patches Message-ID: Date: Fri, 14 Feb 2020 15:41:09 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 X-IsSubscribed: yes Because attribute weakref introduces a kind of a definition, it can only be applied to declarations of symbols that are not defined. GCC normally issues a warning when the attribute is applied to a defined symbol, but PR 92799 shows that it misses some cases on which it then leads to an ICE. The ICE was introduced in GCC 4.5. Prior to then, GCC accepted such invalid definitions and silently dropped the weakref attribute. The attached patch avoids the ICE while again dropping the invalid attribute from the definition, except with the (now) usual warning. Tested on x86_64-linux. I also looked for code bases that make use of attribute weakref to rebuild them as another test but couldn't find any. (There are a couple of instances in the Linux kernel but they look #ifdef'd out). Does anyone know of any that do use it that I could try to build on Linux? Martin PR ipa/92799 - ICE on a weakref function definition followed by a declaration gcc/testsuite/ChangeLog: PR ipa/92799 * gcc.dg/attr-weakref-5.c: New test. gcc/ChangeLog: PR ipa/92799 * cgraphunit.c (process_function_and_variable_attributes): Also complain about weakref function definitions and drop all effects of the attribute. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index a9dd288be57..fd586366bb9 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -861,14 +861,23 @@ process_function_and_variable_attributes (cgraph_node *first, " attribute have effect only on public objects"); } if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) - && (node->definition && !node->alias)) + && node->definition + && (!node->alias || DECL_INITIAL (decl) != error_mark_node)) { - warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, + /* NODE->DEFINITION && NODE->ALIAS is nonzero for valid weakref + function declarations; DECL_INITIAL is non-null for invalid + weakref functions that are also defined. */ + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, "% attribute ignored" " because function is defined"); DECL_WEAK (decl) = 0; DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", DECL_ATTRIBUTES (decl)); + DECL_ATTRIBUTES (decl) = remove_attribute ("alias", + DECL_ATTRIBUTES (decl)); + node->alias = false; + node->weakref = false; + node->transparent_alias = false; } else if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) && node->definition diff --git a/gcc/testsuite/gcc.dg/attr-weakref-5.c b/gcc/testsuite/gcc.dg/attr-weakref-5.c new file mode 100644 index 00000000000..e2f04068230 --- /dev/null +++ b/gcc/testsuite/gcc.dg/attr-weakref-5.c @@ -0,0 +1,31 @@ +/* PR middle-end/92799 - ICE on a weakref function definition followed + by a declaration + { dg-do compile } + { dg-options "-Wall" } */ + +static __attribute__ ((weakref ("bar"))) void f0 (void) { } // { dg-warning "'weakref' attribute ignored because function is defined" } + +extern void f0 (void); + +void* use_f0 (void) { return f0; } + + +static __attribute__ ((weakref ("bar"))) void f1 (void) { } // { dg-warning "'weakref' attribute ignored because function is defined" } + +static void f1 (void); + +void* use_f1 (void) { return f1; } + + +static __attribute__ ((weakref ("bar"))) void f2 (void); + +static void f2 (void) { } // { dg-error "redefinition" } + +void* use_f2 (void) { return f2; } + + +static __attribute__ ((weakref ("bar"))) void f3 (void); + +void f3 (void) { } // { dg-error "redefinition" } + +void* use_f3 (void) { return f3; }