From patchwork Mon Sep 4 11:29:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 137449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1030948vqo; Mon, 4 Sep 2023 04:30:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrd559X/vPJY+FtZEQCCsdKecjX0f1pcVZjPH1HlUvfinncxBT0Zaeu7hvw9tWGVatsMQ2 X-Received: by 2002:a17:907:78d9:b0:9a1:e994:3440 with SMTP id kv25-20020a17090778d900b009a1e9943440mr6521588ejc.4.1693827045001; Mon, 04 Sep 2023 04:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693827044; cv=none; d=google.com; s=arc-20160816; b=A1ajS9pOk43dTDhlLKSFFTtK2Uyq/MpaLjkbnb9d9zseqmW67d7Yb9Zg8w9SR6mbbq qw7Xwnktrd0j8Jt6WGLaVzgBQKQ7A+wfTXeNKL5wsY9hLAl7FKy9fwAQCDd5exqQHTV9 gXmWfohUvkbNxr4/xUIic9dhXtxTy3H0l0v+mWup/joAGpFeYrYLuBPaKRWtLQhqLteg moHKr+PBFKMPBw1V80VJcuaXSjB2T3yFIIKgfxvLCXSH/UmJmUZdO3Lvl6oNrKszSemQ /A1XjhWZQwtZx/wuphWaKpJ/PJuy4IVVVOSXUQZYecLlFK2TJPhq6g/mFsZodKUTsSWa tuDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vU8b5RW+QDyKmdq81/Db4NRWzqOZ1VNd7D2uZb0AXOw=; fh=hKkF4Qm4zMpuuPSvBuLljwLCLYziV8/JqYgl0gS1cUA=; b=GiipPfUBTlBLDB5oGkNS3Kwg1CQiK1xzVqHRgpSKPKs4KKgPEsJjF58fsdofBz8Zdf LamfB/RD9eu7jhuWXoUOkGNZaXt/536pMI2iumU3ufMAVwUxzpJOvrboRMNz+7Arc+B3 OX9yWMXFLBt4gIJpuplRSJrQRUfRJxzIqE6opHADEMChr0FIHga0C4STIwwR8/amyEPa outwjfUlJ1U3QkrWjhCh5LlhHu+Apjo32Yxs3Xa7WpNkGWWacaan/sJXRTHznjKzT4/s UYoYKAcPC0KRvujBRgEY9TRlVy4tO9DqS2rzdHjuaV7AM3RNNIlHxFrhTGQ8UvkEvv2S 2/7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=T6VPMdXt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n11-20020a1709065e0b00b0099bd00f8f73si5809487eju.742.2023.09.04.04.30.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Sep 2023 04:30:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=T6VPMdXt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2988385800C for ; Mon, 4 Sep 2023 11:30:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2988385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693827043; bh=vU8b5RW+QDyKmdq81/Db4NRWzqOZ1VNd7D2uZb0AXOw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=T6VPMdXtK8pda3hcSpHq9nXq4fqyssac9FuKWM2ET/z3ISpVLsKNgprGI6DfyNbBT 4nyjZcPfk+GkjIp9qD+KPqvgjzEPGKC4kiddqI6+eD7k9OO99jDMOR03dIl7ik7VFE YVuUaDx0a9kcZgb8yfIrePayrPvm0tMy9orhYckM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id B5D123858428 for ; Mon, 4 Sep 2023 11:30:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B5D123858428 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-31c5c06e8bbso1148161f8f.1 for ; Mon, 04 Sep 2023 04:30:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693826999; x=1694431799; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vU8b5RW+QDyKmdq81/Db4NRWzqOZ1VNd7D2uZb0AXOw=; b=UYQ4/7P4hFNyHHxT+UBSsMrpt3WpzfRlPB7fAhi9MxYQObytwSDOF1G2ne1zw9E5ip iFM2/8RsicqeDetKtbw7OrNRkmKXSm4Ea5qQP5GGwHB2hinFHUtoBew/fvYWpa+FNlT5 qtD5TcO8QjxWxhk5R5/im86BTLvtd4n+6Y1wVnSbvHhkgK4QN7yRG+8n1CnbS0qPAKTs hH4EuMeLc9hbKxB3k8jXpRF5Gbcdm5f0M/cULYil/Qc4ZcB+4g05iRnkh8hkzpIfIZqF wMcQ0o9GiNGqiSIGcShZ1JHtKLy1dxP65oA1ntiPn4cuveqlHu2S1E4zQMJH/PCzNoLz 3ZJw== X-Gm-Message-State: AOJu0YxH1YcLH/517zl0N/iRCqfC5BnVe/DuJmrC4ihS9VL2VBcJ9a9y 2YqS1549BDx+6C0cF9ES4j4EtpoL+Xw= X-Received: by 2002:a5d:6591:0:b0:317:43de:4c0a with SMTP id q17-20020a5d6591000000b0031743de4c0amr6815726wru.20.1693826999260; Mon, 04 Sep 2023 04:29:59 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id p6-20020adfce06000000b0031ad2f9269dsm14397838wrn.40.2023.09.04.04.29.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 04 Sep 2023 04:29:58 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] Darwin: Place global inits in the correct section. Date: Mon, 4 Sep 2023 12:29:57 +0100 Message-Id: <20230904112957.8713-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776106387709209298 X-GMAIL-MSGID: 1776106387709209298 Tested on x86_64-darwin21, i686-darwin9, aarch64-darwin21 and powerpc-darwin9, pushed to trunk, thanks Iain --- 8< --- This handles placement of global initializers into __TEXT,__StaticInit as used by other platform toolchains. Signed-off-by: Iain Sandoe gcc/ChangeLog: * config/darwin-sections.def (static_init_section): Add the __TEXT,__StaticInit section. * config/darwin.cc (darwin_function_section): Use the static init section for global initializers, to match other platform toolchains. --- gcc/config/darwin-sections.def | 2 ++ gcc/config/darwin.cc | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def index de2334f4a7a..7e1b4710bd6 100644 --- a/gcc/config/darwin-sections.def +++ b/gcc/config/darwin-sections.def @@ -98,6 +98,8 @@ DEF_SECTION (mod_init_section, 0, ".mod_init_func", 0) DEF_SECTION (mod_term_section, 0, ".mod_term_func", 0) DEF_SECTION (constructor_section, 0, ".constructor", 0) DEF_SECTION (destructor_section, 0, ".destructor", 0) +DEF_SECTION (static_init_section, SECTION_CODE, + ".section\t__TEXT,__StaticInit,regular,pure_instructions", 0) /* Objective-C ABI=0 (Original version) sections. */ DEF_SECTION (objc_class_section, 0, ".objc_class", 1) diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc index b435bb2b80a..95d6194cf22 100644 --- a/gcc/config/darwin.cc +++ b/gcc/config/darwin.cc @@ -3893,6 +3893,14 @@ darwin_function_section (tree decl, enum node_frequency freq, if (decl && DECL_SECTION_NAME (decl) != NULL) return get_named_section (decl, NULL, 0); + /* Intercept functions in global init; these are placed in separate sections. + FIXME: there should be some neater way to do this. */ + if (DECL_NAME (decl) + && (startswith (IDENTIFIER_POINTER (DECL_NAME (decl)), "_GLOBAL__sub_I") + || startswith (IDENTIFIER_POINTER (DECL_NAME (decl)), + "__static_initialization_and_destruction"))) + return darwin_sections[static_init_section]; + /* We always put unlikely executed stuff in the cold section. */ if (freq == NODE_FREQUENCY_UNLIKELY_EXECUTED) return (use_coal) ? darwin_sections[text_cold_coal_section]