From patchwork Thu Sep 14 08:01:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 813740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-462106-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="iGDubH0j"; 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 3xtB1Q4NNHz9s83 for ; Thu, 14 Sep 2017 18:06:01 +1000 (AEST) 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; q=dns; s=default; b=Uv7+OPu5V8y/ WtOhGUOcy+QlyugkBxu9ylHl7TqSoC9cQWt0pskKnbMflq3bX1MSr9wqMcGsg311 4kQL4aNQzFW8AL+1EkD0T6CcSF1/aKwgCU2tSvcOIETMxxvKwQg2X8v8yp16vhms QtWLf8f/YpqmC8+vit81fGYytSVHCHM= 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; s=default; bh=BmB5S0vQi06vwMgpJB YONBPOd9E=; b=iGDubH0jaw5ybi0FDVDBb14J3dz1zCm5ohb7/t2sUY8wgCjmNS XMK89U+uQGIOwtiaFmkPC+1mxbUpCIELH+BeoKhLlYXvN46JVeECAK/ZqZq7iHXH e/Z8MPOIcRzRTJunYEx/FJZZmYTm8L0YE4A1lO7rnWEX/mUiwdl41LYbc= Received: (qmail 105642 invoked by alias); 14 Sep 2017 08:05:42 -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 105488 invoked by uid 89); 14 Sep 2017 08:05:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=year's, years X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Sep 2017 08:05:16 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id DC2D982421; Thu, 14 Sep 2017 10:05:13 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gEDIeGxbjCji; Thu, 14 Sep 2017 10:05:13 +0200 (CEST) Received: from perdrix.act-europe.fr (perdrix.act-europe.fr [IPv6:2a02:2ab8:224:1:1adb:f2ff:fe3d:1472]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id BA7E2823B2; Thu, 14 Sep 2017 10:05:13 +0200 (CEST) From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org, Nathan Sidwell Cc: Pierre-Marie de Rodat Subject: [PATCH] Add comments to struct cgraph_thunk_info Date: Thu, 14 Sep 2017 10:01:47 +0200 Message-Id: <20170914080147.969-1-derodat@adacore.com> X-IsSubscribed: yes Hello, This commit adds comments to fields in the cgraph_thunk_info structure declaration from cgraph.h. They will hopefully answer questions that people like myself can ask while discovering the thunk machinery. I also made an assertion stricter in cgraph_node::create_thunk. I'm adding Nathan in copy as we discussed this thunk matter at this year's Cauldron. :-) Bootsrapped and regtested on x86_64-linux. Ok to commit? Thank you in advance! gcc/ * cgraph.h (cgraph_thunk_info): Add comments, reorder fields. * cgraph.c (cgraph_node::create_thunk): Adjust comment, make assert for VIRTUAL_* arguments stricter. --- gcc/cgraph.c | 10 +++++++--- gcc/cgraph.h | 36 +++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 69aa6c5bce2..20ab418d410 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -603,7 +603,7 @@ cgraph_node::create_same_body_alias (tree alias, tree decl) /* Add thunk alias into callgraph. The alias declaration is ALIAS and it aliases DECL with an adjustments made into the first parameter. - See comments in thunk_adjust for detail on the parameters. */ + See comments in struct cgraph_thunk_info for detail on the parameters. */ cgraph_node * cgraph_node::create_thunk (tree alias, tree, bool this_adjusting, @@ -619,8 +619,12 @@ cgraph_node::create_thunk (tree alias, tree, bool this_adjusting, node->reset (); else node = cgraph_node::create (alias); - gcc_checking_assert (!virtual_offset - || wi::eq_p (virtual_offset, virtual_value)); + + /* Make sure that if VIRTUAL_OFFSET is in sync with VIRTUAL_VALUE. */ + gcc_checking_assert (virtual_offset + ? wi::eq_p (virtual_offset, virtual_value) + : virtual_value == 0); + node->thunk.fixed_offset = fixed_offset; node->thunk.this_adjusting = this_adjusting; node->thunk.virtual_value = virtual_value; diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 57cdaa45681..372ac9f01aa 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -629,18 +629,40 @@ extern const char * const cgraph_availability_names[]; extern const char * const ld_plugin_symbol_resolution_names[]; extern const char * const tls_model_names[]; -/* Information about thunk, used only for same body aliases. */ +/* Sub-structure of cgraph_node. Holds information about thunk, used only for + same body aliases. + + Thunks are basically wrappers around methods which are introduced in case + of multiple inheritance in order to adjust the value of the "this" pointer + or of the returned value. */ struct GTY(()) cgraph_thunk_info { - /* Information about the thunk. */ - HOST_WIDE_INT fixed_offset; - HOST_WIDE_INT virtual_value; - tree alias; + /* Set to true when alias node (the cgraph_node to which this struct belong) + is a thunk. Access to any other fields is invalid if this is false. */ + bool thunk_p; + + /* Nonzero for a "this" adjusting thunk and zero for a result adjusting + thunk. */ bool this_adjusting; + + /* If true, this thunk is what we call a virtual thunk. In this case, after + the FIXED_OFFSET based adjustment is done, add to the result the offset + found in the vtable at: vptr + VIRTUAL_VALUE. */ bool virtual_offset_p; + + /* ??? True for special kind of thunks, seems related to instrumentation. */ bool add_pointer_bounds_args; - /* Set to true when alias node is thunk. */ - bool thunk_p; + + /* Offset used to adjust "this". */ + HOST_WIDE_INT fixed_offset; + + /* Offset in the virtual table to get the offset to adjust "this". Valid iff + VIRTUAL_OFFSET_P is true. */ + HOST_WIDE_INT virtual_value; + + /* Thunk target, i.e. the method that this thunk wraps. Depending on the + TARGET_USE_LOCAL_THUNK_ALIAS_P macro, this may have to be a new alias. */ + tree alias; }; /* Information about the function collected locally.