From patchwork Tue Apr 25 10:47:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 754719 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 3wC0KW6c73z9s8G for ; Tue, 25 Apr 2017 20:47:43 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="E4hn6KY8"; 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:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=kJRGJzjytVyX2Xx1QupcHumGkhvUzZTS6G63H2TluIF4az796F lInuHkifB54oEMybJ4ndp/2amwMBF+mIKlYWo5wMP5UzRLH3iNnRXKfYsraOpn7U K3TgRyNjJ/joJNFwmJPevDjLEui31P6anyLg34q7MhF8aXMxyfyCZE+cY= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=kMS7sslU9/AdHTPKuKe6fIkseqw=; b=E4hn6KY8zU65fcGZpfLc CLvt1Y8D04o6B03ohYxHR6yXNZ1lOx1W99sd8/7KEbqo6JFEMLW1olIHgIOisuHE 1p7NurgyC6TlJTAYIJBBS6YoaaSQqbfdo3qYPmLsBm4P6DUPpIYLZSNg3JE+pyq3 3gTCnoc97QzVJ+G1s+fOYlU= Received: (qmail 11846 invoked by alias); 25 Apr 2017 10:47:21 -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 11753 invoked by uid 89); 25 Apr 2017 10:47:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, LIKELY_SPAM_BODY, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=ali, nevertheless, olivier, Olivier X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 10:47:18 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 3D4B335E1; Tue, 25 Apr 2017 06:47:19 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id bYkvxhTuRcu7; Tue, 25 Apr 2017 06:47:19 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 2AE4935CD; Tue, 25 Apr 2017 06:47:19 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 27E2E3F0; Tue, 25 Apr 2017 06:47:19 -0400 (EDT) Date: Tue, 25 Apr 2017 06:47:19 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Olivier Hainque Subject: [Ada] Fix elab counter handling when preserving control flow Message-ID: <20170425104719.GA53786@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) When control flow preservation is requested, we want to be explicit about the units elaboration order in a partition, and we want to have in the executable an object file for all the units involved in the partition. This requires special processing for units which wouldn't produce any object code in normal circumstances, e.g. lone specs only defining simple types and marked with a No_Elaboration_Code pragma. Our scheme involves two parts: 1) make sure that all the units compiled with -fpreserve-control-flow have an elaboration counter, including lone specs with pragma No_Elaboration_Code. 2) arrange to have that elaboration counter updated by the binder generated code, even though there's no elab subprogram called. This materializes the unit elaboration explicitly and introduces a variable reference which will drag the unit object file in the link closure. So far, we were building an elaboration counter entity but were not advertising it in the ALI information and were not referencing it from the binder generated code. This change fixes this. For this set of sources: In subdir mylib/ library project mylib is for Languages use ("Ada"); for Source_Dirs use ("."); for Library_Name use Project'Name; for Library_Dir use "lib"; for Library_Kind use "static"; end mylib; package Types is type R is range 1 .. 500; end; And one level up: with "mylib/mylib.gpr"; project p is end p; with Types; procedure P is V : Types.R; pragma Volatile (V); begin null; end; Out of this build command: gprbuild -f -g -p -Pp.gpr p.adb -cargs -fpreserve-control-flow We expect b__p.adb to feature something like: E04 : Short_Integer; pragma Import (Ada, E04, "types_E"); procedure adainit ... E04 := E04 + 1; end adainit; and the final executable to include types.o. Tested on x86_64-pc-linux-gnu, committed on trunk 2017-04-25 Olivier Hainque * bindgen.adb (Gen_Elab_Calls): Also update counter of lone specs without elaboration code that have an elaboration counter nevertheless, e.g. when compiled with -fpreserve-control-flow. * sem_ch10.adb (Analyze_Compilation_Unit): Set_Elaboration_Entity_Required when requested to preserve control flow, to ensure the unit elaboration is materialized at bind time, resulting in the inclusion of the unit object file in the executable closure at link time. Index: sem_ch10.adb =================================================================== --- sem_ch10.adb (revision 247177) +++ sem_ch10.adb (working copy) @@ -1204,32 +1204,38 @@ -- where the elaboration routine might otherwise be called more -- than once. - -- Case of units which do not require elaboration checks + -- They are also needed to ensure explicit visibility from the + -- binder generated code of all the units involved in a partition + -- when control-flow preservation is requested. - if - -- Pure units do not need checks + -- Case of units which do not require an elaboration entity - Is_Pure (Spec_Id) + if not Opt.Suppress_Control_Flow_Optimizations + and then + ( -- Pure units do not need checks - -- Preelaborated units do not need checks + Is_Pure (Spec_Id) - or else Is_Preelaborated (Spec_Id) + -- Preelaborated units do not need checks - -- No checks needed if pragma Elaborate_Body present + or else Is_Preelaborated (Spec_Id) - or else Has_Pragma_Elaborate_Body (Spec_Id) + -- No checks needed if pragma Elaborate_Body present - -- No checks needed if unit does not require a body + or else Has_Pragma_Elaborate_Body (Spec_Id) - or else not Unit_Requires_Body (Spec_Id) + -- No checks needed if unit does not require a body - -- No checks needed for predefined files + or else not Unit_Requires_Body (Spec_Id) - or else Is_Predefined_File_Name (Unit_File_Name (Unum)) + -- No checks needed for predefined files - -- No checks required if no separate spec + or else Is_Predefined_File_Name (Unit_File_Name (Unum)) - or else Acts_As_Spec (N) + -- No checks required if no separate spec + + or else Acts_As_Spec (N) + ) then -- This is a case where we only need the entity for -- checking to prevent multiple elaboration checks. Index: bindgen.adb =================================================================== --- bindgen.adb (revision 247177) +++ bindgen.adb (working copy) @@ -1117,9 +1117,13 @@ then -- In the case of a body with a separate spec, where the -- separate spec has an elaboration entity defined, this is - -- where we increment the elaboration entity if one exists + -- where we increment the elaboration entity if one exists. - if U.Utype = Is_Body + -- Likewise for lone specs with an elaboration entity defined + -- despite No_Elaboration_Code, e.g. when requested to + -- preserve control flow. + + if (U.Utype = Is_Body or else U.Utype = Is_Spec_Only) and then Units.Table (Unum_Spec).Set_Elab_Entity and then not CodePeer_Mode then