From patchwork Wed Jul 20 11:47:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 650651 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 3rvZsP342Zz9t10 for ; Wed, 20 Jul 2016 21:47:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=FB5zlsB+; 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:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; q=dns; s=default; b=wDd6f6QgA6a5B4dq 8tzJ1md4gBLzl8DEWfkSow8cJOTHrDcic4+yR7Yq5W9IbEbgFUTmfigCc5GWXHr9 4+Rv6gbG92lQFJ9jkmfEDhPgsf45hxSYN7SFmCQhHHZYcUy5p9x5klSHCiJRdVEH PZ5uuf8xxxxe/3BEvnz2g5GiaCY= 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 :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; s=default; bh=Op0cljPFh5vnD1WAAsifxj B5EWQ=; b=FB5zlsB+D2iohZQDPGgeP9uKDUgclLmeE7yjPHNpWIupi2tOrGU55X kIPnhTGra4hw6rRFn0nXTADN7I07n45pQ1yU4zrtTAjyxR/smfTjNKpEWB/VmgXB e25EyFMR6/R7mepDv4hJ4OarzPKGhmR6yzdw9mqBiVLzc8CSFG6eQ= Received: (qmail 67031 invoked by alias); 20 Jul 2016 11:47:26 -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 67008 invoked by uid 89); 20 Jul 2016 11:47:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=!strncmp, HX-HELO:sk:BLU004-, Hx-spam-relays-external:sk:blu004-, H*RU:sk:BLU004- X-HELO: BLU004-OMC1S36.hotmail.com Received: from blu004-omc1s36.hotmail.com (HELO BLU004-OMC1S36.hotmail.com) (65.55.116.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Wed, 20 Jul 2016 11:47:16 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com ([65.55.116.7]) by BLU004-OMC1S36.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Wed, 20 Jul 2016 04:47:14 -0700 Received: from HE1EUR01FT039.eop-EUR01.prod.protection.outlook.com (10.152.0.54) by HE1EUR01HT100.eop-EUR01.prod.protection.outlook.com (10.152.1.101) with Microsoft SMTP Server (TLS) id 15.1.539.16; Wed, 20 Jul 2016 11:47:10 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.0.52) by HE1EUR01FT039.mail.protection.outlook.com (10.152.0.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.5 via Frontend Transport; Wed, 20 Jul 2016 11:47:09 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) by AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) with mapi id 15.01.0544.014; Wed, 20 Jul 2016 11:47:08 +0000 From: Bernd Edlinger To: Richard Biener CC: "jakub@redhat.com" , Jeff Law , "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH] Fix unsafe function attributes for special functions (PR 71876) Date: Wed, 20 Jul 2016 11:47:08 +0000 Message-ID: References: In-Reply-To: authentication-results: spf=softfail (sender IP is 10.152.0.52) smtp.mailfrom=hotmail.de; suse.de; dkim=none (message not signed) header.d=none; suse.de; dmarc=none action=none header.from=hotmail.de; received-spf: SoftFail (protection.outlook.com: domain of transitioning hotmail.de discourages use of 10.152.0.52 as permitted sender) x-ms-exchange-messagesentrepresentingtype: 1 x-eopattributedmessage: 0 x-forefront-antispam-report: CIP:10.152.0.52; IPV:NLI; CTRY:; EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1EUR01HT100; H:AM4PR0701MB2162.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; x-microsoft-exchange-diagnostics: 1; HE1EUR01FT039; 1:UsR5FJ0hU6ND2N3ExIFF2NIpKcbSflgOliaqevUKWQF1KO+6KHzd4QaO8QP6gZDp4D30tJhGpoU+HRm/oVYlJ9btSLTkSWEdLTRJWOpJlkGR28JfxweKTqvVWNsYp4FqJ2QzWqCWOTts/m+Vc+jNDnga/YzIZwW7mBNWQdNWufxs1swjes8v1mk/DDVwvK+fy4I1TGB+e8kpnxLz0v6ZnlMmDMSdcJBgOuXd03jvChj/mieMHiNXtp41h/sW+SMQ8o5jwQCs0v92s8ay/1NTkic9Hio4Js4wGNl/V0dQNinwHy46fD+P4HgwK0GoGGapDf1bMFJAtP26iLdqVIrcsiR+jo6cLJnkcZeJ0wkpHYIIbdgV6tbLSFNhGel30T4Me2v7cdIQXn3WfUJGVxCD+RLLcIt81Zn2SYQuLBujFi+d8KiAzglUxw8FAMHUfRPAYZVb7MBFeALtBWpc0+sQ2g== x-ms-office365-filtering-correlation-id: 0af919b7-86a0-4649-4650-08d3b093937d x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(1601124038)(5061506196)(5061507196)(1603103041)(1601125047); SRVR:HE1EUR01HT100; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(432015012)(102415321)(82015046); SRVR:HE1EUR01HT100; BCL:0; PCL:0; RULEID:; SRVR:HE1EUR01HT100; x-forefront-prvs: 000947967F MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jul 2016 11:47:08.0241 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR01HT100 On 07/20/16 12:46, Richard Biener wrote: > On Wed, 20 Jul 2016, Richard Biener wrote: > >> On Tue, 19 Jul 2016, Bernd Edlinger wrote: >> >>> Hi! >>> >>> As discussed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71876, >>> we have a _very_ old hack in gcc, that recognizes certain functions by >>> name, and inserts in some cases unsafe attributes, that don't work for >>> a freestanding environment. >>> >>> It is unsafe to return ECF_MAY_BE_ALLOCA, ECF_LEAF and ECF_NORETURN >>> from special_function_p, just by the name of the function, especially >>> for less well known functions, like "getcontext" or "savectx", which >>> could easily used for something completely different. >> >> Returning ECF_MAY_BE_ALLOCA is safe. Just wanted to mention this, >> regardless of the followups you already received. > > Oh, and maybe you can factor out the less controversical parts, > namely ignoring the __builtin_ prefix. I don't think that > calling __builtin_setjmp in an environment where setjmp is not a > builtin should beave like setjmp (it will call a function named > '__builtin_setjmp'). I wonder how I manage to dig out such contriversical things ;) But you are right, that would at least be a start. So this patch is what you requested: Remove the handling of the __builtin_ prefix from special_function_p and add the returns_twice attribute to the __builtin_setjmp declaration instead. Is it OK after boot-strap and regression-testing? Thanks Bernd. 2016-07-19 Bernd Edlinger PR middle-end/71876 * builtin-attrs.def (ATTR_RT_NOTHROW_LEAF_LIST): New return twice attribute. * builtins.def (BUILT_IN_SETJMP): Use ATTR_RT_NOTHROW_LEAF_LIST here. * calls.c (special_function_p): Remove the special handling of the "__builtin_" prefix. Index: gcc/builtin-attrs.def =================================================================== --- gcc/builtin-attrs.def (Revision 238382) +++ gcc/builtin-attrs.def (Arbeitskopie) @@ -131,6 +131,8 @@ DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, AT ATTR_NULL, ATTR_NOTHROW_LIST) DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_LIST, ATTR_NORETURN,\ ATTR_NULL, ATTR_NOTHROW_LEAF_LIST) +DEF_ATTR_TREE_LIST (ATTR_RT_NOTHROW_LEAF_LIST, ATTR_RETURNS_TWICE,\ + ATTR_NULL, ATTR_NOTHROW_LEAF_LIST) DEF_ATTR_TREE_LIST (ATTR_COLD_NOTHROW_LEAF_LIST, ATTR_COLD,\ ATTR_NULL, ATTR_NOTHROW_LEAF_LIST) DEF_ATTR_TREE_LIST (ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST, ATTR_COLD,\ Index: gcc/builtins.def =================================================================== --- gcc/builtins.def (Revision 238382) +++ gcc/builtins.def (Arbeitskopie) @@ -837,7 +837,7 @@ DEF_LIB_BUILTIN (BUILT_IN_REALLOC, "realloc DEF_GCC_BUILTIN (BUILT_IN_RETURN, "return", BT_FN_VOID_PTR, ATTR_NORETURN_NOTHROW_LEAF_LIST) DEF_GCC_BUILTIN (BUILT_IN_RETURN_ADDRESS, "return_address", BT_FN_PTR_UINT, ATTR_LEAF_LIST) DEF_GCC_BUILTIN (BUILT_IN_SAVEREGS, "saveregs", BT_FN_PTR_VAR, ATTR_NULL) -DEF_GCC_BUILTIN (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GCC_BUILTIN (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_RT_NOTHROW_LEAF_LIST) DEF_EXT_LIB_BUILTIN (BUILT_IN_STRFMON, "strfmon", BT_FN_SSIZE_STRING_SIZE_CONST_STRING_VAR, ATTR_FORMAT_STRFMON_NOTHROW_3_4) DEF_LIB_BUILTIN (BUILT_IN_STRFTIME, "strftime", BT_FN_SIZE_STRING_SIZE_CONST_STRING_CONST_PTR, ATTR_FORMAT_STRFTIME_NOTHROW_3_0) DEF_GCC_BUILTIN (BUILT_IN_TRAP, "trap", BT_FN_VOID, ATTR_NORETURN_NOTHROW_LEAF_LIST) Index: gcc/calls.c =================================================================== --- gcc/calls.c (Revision 238382) +++ gcc/calls.c (Arbeitskopie) @@ -514,14 +514,10 @@ special_function_p (const_tree fndecl, int flags) && ! strcmp (name, "alloca")) flags |= ECF_MAY_BE_ALLOCA; - /* Disregard prefix _, __, __x or __builtin_. */ + /* Disregard prefix _, __ or __x. */ if (name[0] == '_') { - if (name[1] == '_' - && name[2] == 'b' - && !strncmp (name + 3, "uiltin_", 7)) - tname += 10; - else if (name[1] == '_' && name[2] == 'x') + if (name[1] == '_' && name[2] == 'x') tname += 3; else if (name[1] == '_') tname += 2;