From patchwork Wed Mar 16 05:04:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 598116 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 3qPzvK3Yzjz9sDH for ; Wed, 16 Mar 2016 16:05:16 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=S87faZ0J; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; q=dns; s= default; b=ecP+g1VprDgphb2qo0FfNGBKpY0Khi6EgDt9G40nu0QKdymr3eiRF X71KmzVHfEgcHABNFlVcK3JQx4k18ocJsqxrkneaIrLxseP+/sdMdfLuiKmTnV4d xWP85KW2YfH3W+kHZxKdEQePjRJ54cONaRoBy3waZ6nQCOfFM2+TbU= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=default; bh=heVMardp6ZBKkK0ouai4qeI8stg=; b=S87faZ0JjLS6OuWTlF7/uIDilnGg 5ppukJKWhhOYTWzgzFCFatTIu4zsyAGIYNFogaIjyowiO1tX8ojA7POkZbSxwtkl VqKEUVG8yRNYRf6/y8HheQ+Ya2jbWPIfjivkQrXg4rSttkQA7657CiOMTDkUJx+T 1lweHxslYdV8Jno= Received: (qmail 29615 invoked by alias); 16 Mar 2016 05:05:06 -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 29516 invoked by uid 89); 16 Mar 2016 05:05:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=20160316, 2016-03-16, link-time, linktime X-HELO: mail-qg0-f50.google.com Received: from mail-qg0-f50.google.com (HELO mail-qg0-f50.google.com) (209.85.192.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 16 Mar 2016 05:04:54 +0000 Received: by mail-qg0-f50.google.com with SMTP id u110so34183464qge.3 for ; Tue, 15 Mar 2016 22:04:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding; bh=DZqu9JKF1AY/OPJi5LUDUU5hE4tkcedPSa5aCIHHtPg=; b=ZSjcGqRpx8NObhZ92GlZGiliaPYYnGBYjInBj9BmelaCuEPQjA2VfiP4mPzqombRmQ n2/V20ra56XAl379ztGltaQ/IFf+fZEAp3dOQ9H5ImWqZ0PTIF86SE1phziC9UD6iutx qwJanXNZmIV1TE8pfjrp4Ldp5FPIqyiwQK/KviB4vpDnz/ahQxFcoz2T3ZM+qBqfOy/w dWHCkuy2cfnO+XNqMh1WFy8iAXIJnWeJ4J7EmnG25drK7ylDcwq8eB3mR/moOXfC8gP1 AZ0gmgULipYeD8X4yB+6ulU+asCtpt6nYB3yjLgCwlKEK5AGY0GVeyUH9zqrPTvQZEpi qvyg== X-Gm-Message-State: AD7BkJLE64dreCdOyI32DwGJSaCrfKW0iJWKo3G1C3W0tayVYlMT2Wp6i18Xb9I86MeWcpIR X-Received: by 10.140.25.161 with SMTP id 30mr2345148qgt.73.1458104692608; Tue, 15 Mar 2016 22:04:52 -0700 (PDT) Received: from [192.168.2.15] (bas1-pembroke52-1279338163.dsl.bell.ca. [76.65.38.179]) by smtp.gmail.com with ESMTPSA id y129sm755525qka.33.2016.03.15.22.04.50 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Mar 2016 22:04:51 -0700 (PDT) Subject: Re: [PATCH] extend.texi: Expand on the perils of using the 'leaf' attribute. To: Sandra Loosemore , gcc-patches@gcc.gnu.org References: <56E705A6.5040108@redhat.com> <56E737EF.6060106@codesourcery.com> Cc: "Joseph S. Myers" , Florian Weimer From: Carlos O'Donell Message-ID: <56E8E971.8050209@redhat.com> Date: Wed, 16 Mar 2016 01:04:49 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <56E737EF.6060106@codesourcery.com> On 03/14/2016 06:15 PM, Sandra Loosemore wrote: > On 03/14/2016 12:40 PM, Carlos O'Donell wrote: >> Using the 'leaf' attribute is difficult in certain use cases, and >> the documentation rightly points out that signals is one such >> problem. >> >> We should additionally document the following caveats: >> >> * Indirect function resolvers (thanks to Florian Weimer for >> catching this). * Indirect function implementations * ELF symbol >> interposition. >> >> [snip] >> >> gcc/ 2016-03-14 Carlos O'Donell >> >> * doc/extend.texi (Common Function Attributes): Describe ifunc >> impact on leaf attribute. >> > > Hmmmm. Both your patch and the original text really need some > copy-editing to fix noun/verb agreement, punctuation, etc. How about > something like the attached patch? I just threw this together and > haven't tested this in any way, but you confirm that it builds and it > looks OK to you, feel free to check it in. PDF looks good. Committed as r234247. 2016-03-16 Carlos O'Donell Sandra Loosemore * doc/extend.texi (Common Function Attributes): Describe ifunc impact on leaf attribute. Mention ELF interposition problems. Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 234236) +++ gcc/doc/extend.texi (revision 234247) @@ -2772,30 +2772,41 @@ @item leaf @cindex @code{leaf} function attribute -Calls to external functions with this attribute must return to the current -compilation unit only by return or by exception handling. In particular, leaf -functions are not allowed to call callback function passed to it from the current -compilation unit or directly call functions exported by the unit or longjmp -into the unit. Leaf function might still call functions from other compilation -units and thus they are not necessarily leaf in the sense that they contain no -function calls at all. +Calls to external functions with this attribute must return to the +current compilation unit only by return or by exception handling. In +particular, a leaf function is not allowed to invoke callback functions +passed to it from the current compilation unit, directly call functions +exported by the unit, or @code{longjmp} into the unit. Leaf functions +might still call functions from other compilation units and thus they +are not necessarily leaf in the sense that they contain no function +calls at all. -The attribute is intended for library functions to improve dataflow analysis. -The compiler takes the hint that any data not escaping the current compilation unit can -not be used or modified by the leaf function. For example, the @code{sin} function -is a leaf function, but @code{qsort} is not. +The attribute is intended for library functions to improve dataflow +analysis. The compiler takes the hint that any data not escaping the +current compilation unit cannot be used or modified by the leaf +function. For example, the @code{sin} function is a leaf function, but +@code{qsort} is not. -Note that leaf functions might invoke signals and signal handlers might be -defined in the current compilation unit and use static variables. The only -compliant way to write such a signal handler is to declare such variables -@code{volatile}. +Note that leaf functions might indirectly run a signal handler defined +in the current compilation unit that uses static variables. Similarly, +when lazy symbol resolution is in effect, leaf functions might invoke +indirect functions whose resolver function or implementation function is +defined in the current compilation unit and uses static variables. There +is no standard-compliant way to write such a signal handler, resolver +function, or implementation function, and the best that you can do is to +remove the @code{leaf} attribute or mark all such static variables +@code{volatile}. Lastly, for ELF-based systems that support symbol +interposition, care should be taken that functions defined in the +current compilation unit do not unexpectedly interpose other symbols +based on the defined standards mode and defined feature test macros; +otherwise an inadvertent callback would be added. -The attribute has no effect on functions defined within the current compilation -unit. This is to allow easy merging of multiple compilation units into one, -for example, by using the link-time optimization. For this reason the -attribute is not allowed on types to annotate indirect calls. +The attribute has no effect on functions defined within the current +compilation unit. This is to allow easy merging of multiple compilation +units into one, for example, by using the link-time optimization. For +this reason the attribute is not allowed on types to annotate indirect +calls. - @item malloc @cindex @code{malloc} function attribute @cindex functions that behave like malloc