From patchwork Sat Mar 21 19:17:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1259537 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48l9Qc3DYGz9sPF for ; Sun, 22 Mar 2020 06:17:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2F733877007; Sat, 21 Mar 2020 19:17:47 +0000 (GMT) X-Original-To: GCC-patches@gcc.gnu.org Delivered-To: GCC-patches@gcc.gnu.org Received: from smtp1.wavenetuk.net (smtp.wavenetuk.net [195.26.36.10]) by sourceware.org (Postfix) with ESMTP id 88094385E830 for ; Sat, 21 Mar 2020 19:17:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 88094385E830 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=iain@sandoe.co.uk Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by smtp1.wavenetuk.net (Postfix) with ESMTPA id D1CA81200AED for ; Sat, 21 Mar 2020 19:17:43 +0000 (GMT) From: Iain Sandoe Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [committed] Darwin: Handle NULL DECL_SIZE_TYPE in machopic_select_section (PR94237). Message-Id: <2D2D234B-6BB3-452A-8628-94800172638C@sandoe.co.uk> Date: Sat, 21 Mar 2020 19:17:41 +0000 To: GCC-patches@gcc.gnu.org X-Mailer: Apple Mail (2.3273) X-Spam-Status: No, score=-35.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, A recent change in the LTO streaming arrangement means that it is now possible for machopic_select_section () to be called with a NULL value for DECL_SIZE_TYPE - corresponding to an incomplete or not-yet- laid out type. When section anchors are present, and we are generating assembler, we normally need to know the object size when choosing the section, since zero-sized objects must be placed in sections that forbid section anchors. In the current circumstance, the objective of the earlier streaming of this data is to allow nm to determine BSS c.f. Data symbols (when used with the LTO plugin). We now detect when the size is unknown and return the 'generic' section for the DECL kind, which will still be correct in determining the BSS c.f. Data case. Since Darwin does not yet make use of the LTO plugin this is a bit of future-proofing (but needed to fix the PR too). tested across the darwin range, applied to master, thanks Iain gcc/ChangeLog: 2020-03-21 Iain Sandoe PR lto/94237 * config/darwin.c (darwin_mergeable_constant_section): Collect section anchor checks into the caller. (machopic_select_section): Collect section anchor checks into the determination of 'effective zero-size' objects. When the size is unknown, assume it is non-zero, and thus return the 'generic' section for the DECL. diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 8131361715b..d3c0af8a4b6 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -1354,9 +1354,7 @@ darwin_mergeable_constant_section (tree exp, machine_mode mode = DECL_MODE (exp); unsigned int modesize = GET_MODE_BITSIZE (mode); - if (DARWIN_SECTION_ANCHORS - && flag_section_anchors - && zsize) + if (zsize) return darwin_sections[zobj_const_section]; if (flag_merge_constants @@ -1586,8 +1584,23 @@ machopic_select_section (tree decl, && DECL_WEAK (decl) && !lookup_attribute ("weak_import", DECL_ATTRIBUTES (decl))); - zsize = (DECL_P (decl) + /* Darwin pads zero-sized objects with at least one byte, so that the ld64 + atom model is preserved (objects must have distinct regions starting with + a unique linker-visible symbol). + In order to support section anchors, we need to move objects with zero + size into sections which are marked as "no section anchors"; the padded + objects, obviously, have real sizes that differ from their DECL sizes. */ + zsize = DARWIN_SECTION_ANCHORS && flag_section_anchors; + + /* In the streaming of LTO symbol data, we might have a situation where the + var is incomplete or layout not finished (DECL_SIZE_UNIT is NULL_TREE). + We cannot tell if it is zero-sized then, but we can get the section + category correct so that nm reports the right kind of section + (e.g. BSS c.f. data). */ + zsize = (zsize + && DECL_P (decl) && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL) + && DECL_SIZE_UNIT (decl) && tree_to_uhwi (DECL_SIZE_UNIT (decl)) == 0); one = DECL_P (decl) @@ -1635,15 +1648,11 @@ machopic_select_section (tree decl, else base_section = darwin_sections[data_coal_section]; } - else if (DARWIN_SECTION_ANCHORS - && flag_section_anchors - && zsize) + else if (zsize) { /* If we're doing section anchors, then punt zero-sized objects into their own sections so that they don't interfere with offset - computation for the remaining vars. This does not need to be done - for stuff in mergeable sections, since these are ineligible for - anchors. */ + computation for the remaining vars. */ if (ro) base_section = darwin_sections[zobj_const_data_section]; else