From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id 35B5A3858D20; Thu, 25 Apr 2024 19:21:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35B5A3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714072878; bh=YAGCPd1tAyqOiBMBRJaRYtz4Z8DbMiQ3q/Wh/joezUY=; h=From:To:Subject:Date:From; b=mSWTVyDsrly/uJeS4UF3Vv0AVw92IOBo1YwAg23bFrxzONuMnvhbBaVQ1yp5QppDk ryuCC8TaJ3APcs549W5ggrrqTlKEEzyB7bGST7eddrhLooigpqYgoNpNFccPe3Gigo c69oj8uQNfYCse9QVBusckFpq92jUOmWYls7ZhTc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-11366] Darwin: Place global inits in the correct section. X-Act-Checkin: gcc X-Git-Author: Iain Sandoe X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 9488ad0d780fae91afa910410cb4e6da8d607fd9 X-Git-Newrev: 084d0c427433d592e29247164b199c1f232f5c68 Message-Id: <20240425192118.35B5A3858D20@sourceware.org> Date: Thu, 25 Apr 2024 19:21:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:084d0c427433d592e29247164b199c1f232f5c68 commit r11-11366-g084d0c427433d592e29247164b199c1f232f5c68 Author: Iain Sandoe Date: Fri Sep 1 09:04:13 2023 +0100 Darwin: Place global inits in the correct section. 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.c (darwin_function_section): Use the static init section for global initializers, to match other platform toolchains. (cherry picked from commit 68dc3e94fd6bd395a8b343533485616dff3fc796) Diff: --- gcc/config/darwin-sections.def | 2 ++ gcc/config/darwin.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def index ed9e058d1d1..dc4d0408a85 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.c b/gcc/config/darwin.c index ddbd3943a1d..a3a7c509e36 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -3848,6 +3848,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) + && (strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "_GLOBAL__sub_I", 14) == 0 + || strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), + "__static_initialization_and_destruction", 39) == 0)) + 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]