From patchwork Mon Oct 18 07:55:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 46320 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B3A63858426 for ; Mon, 18 Oct 2021 07:55:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B3A63858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634543747; bh=TFNvAB5oVkogYk/FH4PXGW7hPwCkgQmjOdjDflR8Xoo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=joZ0yqWruOSKioJNt6TKAwKrTtA2u70NMlV7zH8iqELCMjNstcG2CiXPPJ7BVRDbn 9ZOnW0oRwzEUYWrsxaML9xZBjqpknLzggvkvr/eaCo42qvYiMQcJJ1oBRMsy8jK9Vn lEornULsra0RifWAjUyF+HRoIgeKFbkGeiZOwBjo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smarthost3.atos.net (smtppost.atos.net [193.56.114.176]) by sourceware.org (Postfix) with ESMTPS id B44893858C39 for ; Mon, 18 Oct 2021 07:55:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B44893858C39 X-IronPort-AV: E=Sophos;i="5.85,381,1624312800"; d="scan'208,223";a="270411115" X-MGA-submission: MDFd3xafkdWph9nwvp9az1X4nkVwrjmlNciK4uCCEbZAqE4x5hZ6A0W1Ti1vgK9lFhqzbYh/I5a9lF84gclXQjYSvqXbjTvYF5rPLHgijLdQyjsebYijYzy/aomYZ9vhBzmvIqriKz1df27JY1Y1lJQY Received: from mail.sis.atos.net (HELO GITEXCPRDMB13.ww931.my-it-solutions.net) ([10.89.28.143]) by smarthost3.atos.net with ESMTP/TLS/AES256-GCM-SHA384; 18 Oct 2021 09:55:12 +0200 Received: from GITEXCPRDMB14.ww931.my-it-solutions.net (10.89.28.144) by GITEXCPRDMB13.ww931.my-it-solutions.net (10.89.28.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Mon, 18 Oct 2021 09:55:11 +0200 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (172.16.214.172) by GITEXCPRDMB14.ww931.my-it-solutions.net (10.89.28.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14 via Frontend Transport; Mon, 18 Oct 2021 09:55:11 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iYxCYbDlRN3fL+QgNoBuwCNP3lmMLbdf0y3LpZTu3p19RZWErXYDGMmA5sQUIEIihZliztRgHrIzjhFqXt9zSYkXXqyyNS6NAPlfOM7nTAcRgZyZqTavrd16WYrHWqfgUo35XuWbcZnRYQYsNTZhPP/1SXa3r+nCAtlsB4fJqtsexGMCEvroS6Wmaj+anUG5FWs4yiAYlzVUg6brZXswUn4GtPdsfLKQptNn9Bv4Mc/PHZuzw/Lo6+WwOuZ3r9403Z9J4dVQzw4Z7pstGkEU+clHsMdE5Q9jSi4x7hK711axv4P9RjFghmln4Du3AprpPyq01AfDi3iDQ99dqr66iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TFNvAB5oVkogYk/FH4PXGW7hPwCkgQmjOdjDflR8Xoo=; b=RNhlhba8oXx/eJR32y+QUbChtLnh6gMx3QSX/oWF/SIVP4sE62g0t5PWHOsCLVuCbjWYEGmEZc6XUAdDxwJFIBbUe1dkG0EFxZrV0uuXV5s9mVaG43W4qVrHVR+8eSBU8919nkB8rLdVdDSRApZlED9RvVokJABmrGHucEk99dvg2r1LEd+b5lOh+XN7ThsbgcxI6DZvBJicx3VwelHoGEui0TqchuilxnqcJInL2ES7CaB2R/k0Re/SNw1NJlLfoCovomfvn0ZlKkSXetUIGR7FGaQroZZweZ5FwSjYHYgfQQaFmSdPlPoLdkj9Nm+EZYOBANvlmeAidOJ+MgGJSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=atos.net; dmarc=pass action=none header.from=atos.net; dkim=pass header.d=atos.net; arc=none Received: from PA4PR02MB6686.eurprd02.prod.outlook.com (2603:10a6:102:ff::14) by PA4PR02MB6765.eurprd02.prod.outlook.com (2603:10a6:102:d3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Mon, 18 Oct 2021 07:55:10 +0000 Received: from PA4PR02MB6686.eurprd02.prod.outlook.com ([fe80::d85f:8147:a57e:92cb]) by PA4PR02MB6686.eurprd02.prod.outlook.com ([fe80::d85f:8147:a57e:92cb%5]) with mapi id 15.20.4608.018; Mon, 18 Oct 2021 07:55:10 +0000 To: "gcc-patches@gcc.gnu.org" Subject: [PATCH] gcc: implement AIX-style constructors Thread-Topic: [PATCH] gcc: implement AIX-style constructors Thread-Index: AQHXw/UayPzaxZrHSUWl8igmK/p7lQ== Date: Mon, 18 Oct 2021 07:55:10 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: msip_labels: MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_Enabled=True; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_SiteId=33440fc6-b7c7-412c-bb73-0e70b0198d5a; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_SetDate=2021-10-18T07:56:45.362Z; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_Name=Atos For Internal Use - All Employees; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_ContentBits=0; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_Method=Standard; suggested_attachment_session_id: f0e7a3f7-3327-7051-bd01-b0e75061b8a6 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0712265f-abf0-485e-bbbc-08d9920c9c36 x-ms-traffictypediagnostic: PA4PR02MB6765: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 01SsSpOQNtpgiw7P2qe8AGgkwupZdPr6cKOCvvQyKLR01KhnZh2EsAO+jVEJq8ZHt/MywbmrK5sUxhWt5ES5m/MD68P1xDMNfOrPFF2/Dnge2C1GXEZvZVTpfvV2g1r4OELS3HTkbDWCl88hqJXJRuRnIXIchHwI+mWCva5qlxuC7T6MWAHfjff42xgG0SNmSoxe335faylMAt8GDEChdyMQ0GzE7rhXD/Fhi9JpG4KCeqI3KTTKp03KQsMEJqs4f9xVGIFsqBLCxzrkxAxYQvJvhHk/so79y7m+hUTSiaTDTbKpXg4jKEGNyUdI/SwXNCytIvI0Kkp3QgQ5d5D/iRo2uLoAlGs4jVN+ueK09eHPsw0EEUS36dQdAmbySA23UBEsYtqFI9O3H7FSze1LZmuVnsNkLG5oe3Jq9dE4u0KzSxLAKnCDIQdeEguIgbOtbSUwdyvchKsWRLwBBLGUmLaJXBzLR/JgJ91yhFnxqIR6DkQAi/7kNkj6il7M5n1B5AVjzVzcktZa4loeqY+8jF5v0Ci3iCeJ7cLmHtkY/yX7/6pE6C2ZRtSwFME7vSstasYIwJlOW7ouj0oRUBR0ymzsudoCOmsay/f/JuDNnCQU3wqqMWUafx5XSjb+tevEY20R9dW70cIaLe7XSFrSafWfDgy+2Nh6HLhKoOSXhkADy3KODWVgaN73l7xJVF8/WI+SoFPY3EXqEtUiV/Gxly8pk2LQ9DiFnUbJkUm5NGWJgvx4LcOqi/fISbrL5p1m x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR02MB6686.eurprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(9686003)(71200400001)(5660300002)(55016002)(2906002)(38070700005)(7696005)(26005)(55236004)(82960400001)(186003)(66574015)(6506007)(6916009)(64756008)(91956017)(66446008)(66476007)(66556008)(52536014)(66946007)(99936003)(83380400001)(8676002)(508600001)(316002)(86362001)(38100700002)(122000001)(33656002)(76116006)(4326008); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?D7OYeqAZiJb1P8YShXBoB06?= =?iso-8859-1?q?IXugnuEUuG2kariWs0lKY1Kq0cFv41IoseQj9W7z6OVWWdoykGbKmyechVnF?= =?iso-8859-1?q?uSn1B1tzS6l3HE+WA76wIu6NJnRvd2k6rT7XpLdbFSjx5NWjdezVti8n38Uq?= =?iso-8859-1?q?yh6ScPe6B7OXR5EOwpkms9zZSF7nlSEwMXkikUeJBwM3Lg58iWBAI3nuYO+R?= =?iso-8859-1?q?tsdvh351sZzEtcvbvQd47/Rl96QS3vpJKBgr5Kh9ne/syRp0gHGKdShDgR/I?= =?iso-8859-1?q?qHvTYsT0sCREufKPzSw7NkWmorG/ou31noBG92gsNEadmsgmYvGnJH8frzm/?= =?iso-8859-1?q?kixjqjAu6eT/1Xu/jF80kXX3ozEAqztCu88gEFU7t5lJgi2PlOHoFpgsajeV?= =?iso-8859-1?q?2CZhlqacnY90UCkKoqoXU0a0oi8KMBQhIY0FNspBGfRA9/bcF+EH8OZzC/Bv?= =?iso-8859-1?q?6AQXHLTDOtV0KF7FPeh16EPeraY52/S84nsa8GSnRutW7O5f3K6FjlLXXQUK?= =?iso-8859-1?q?cZklyyCRHikQ01cupMuBm3PuxLU0j0uyasaqctgKHyyaBnjp6y040jwXh0B5?= =?iso-8859-1?q?GKuXIq/UU4nyP6NDqJCnxE24GuAbw5X+h2msW7OJSGQroebNe447/k8W9FBl?= =?iso-8859-1?q?BTXpds82hzE+cAOrI5tVRnUJbmHze4wyI5xEGZ5Qfsa3/doePFS748LIM+ub?= =?iso-8859-1?q?2zQ4/b3YQMUG/88gHrfaBX8/RfNhkoyKhLyH/kJyrzDtK5JKXQ5R4+f6jfDw?= =?iso-8859-1?q?0e3A+ycYAqBb9EbXak8CUkBFKeFC6I4iNw034YUt9LcvwhqMPdlA28/K3y6k?= =?iso-8859-1?q?ZEpErT19MXqzZVdhY6rfUm2WuGJTsZ3cXKNJzqZLBjK2hwsvC/tsHX0D1JOs?= =?iso-8859-1?q?ECkH3nDXKIaW/aLlKNvwh0wTD7rkcYkT6b6AUNydchi5zFCzHcbxnzb/jp4d?= =?iso-8859-1?q?Pdl3V4uhtGRtziJqWdlV45212lILF8nQqnazjDzvspsFBvegVDaw4634OmqU?= =?iso-8859-1?q?EqFRNaGe3KaianlkmWrie0FOzg4rQKfyTf3g3CX0K3c3r6QqntaSQiqi8HNc?= =?iso-8859-1?q?0IS6eJ+0Z8Xyri20dnoexlXAvTB4L/JxUzrqopbJPrwB1GBAO9v+i0+l1+vy?= =?iso-8859-1?q?ouRCIz0opUn7neyu0AOYtH8STi3FVjEDurswjyki4nFr2ZWQgUBIsAS8B64K?= =?iso-8859-1?q?/rryf4sXDWNUFLXu4HWeVMbNMia6THcmJDKh7tAGsNgr5hdC4AyNQ742O3+s?= =?iso-8859-1?q?KgGc5HDjGC2w7zpmbV/l12hpqRTA4sLwuS1Qn2lPrWfCPctCQ2iERZRNtcd0?= =?iso-8859-1?q?wx7IuQ3iWxXAl++anWLA6BI0YYdBjoULAcG7tIlo=3D?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR02MB6686.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0712265f-abf0-485e-bbbc-08d9920c9c36 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Oct 2021 07:55:10.6775 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 33440fc6-b7c7-412c-bb73-0e70b0198d5a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: nXnutnbkFkIwsTnpa+ZF2bns62jtWtOFzRTMo32d1ELFnJ4Ge+V/BfQrEDIUCrSugCXep+KjuWXbPNMJ0f4UGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR02MB6765 X-OriginatorOrg: atos.net X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: "CHIGOT, CLEMENT via Gcc-patches" From: "Li, Pan2 via Gcc-patches" Reply-To: "CHIGOT, CLEMENT" Cc: David Edelsohn Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" AIX linker now supports constructors and destructors detection. For such functions to be detected, their name must starts with __sinit or __sterm. and -bcdtors must be passed to linker calls. It will create "_cdtors" symbol which can be used to launch the initialization. This patch creates a new RS6000 flag "-mcdtors=". With "-mcdtors=aix", gcc will generate these new constructors/destructors. With "-mcdtors=gcc", which is currently the default, gcc will continue to generate "gcc" format for constructors (ie _GLOBAL__I and _GLOBAL__D symbols). Ideally, it would have been better to enable the AIX format by default instead of using collect2. However, the compatibility between the previously-built binaries and the new ones is too complex to be done. gcc/ChangeLog: 2021-10-04  Clément Chigot           * collect2.c (aixbcdtors_flags): New variable.         (main): Use it to detect -bcdtors and remove -binitfini flag.         (write_c_file_stat): Adapt to new AIX format.         * config/rs6000/aix.h (FILE_SINIT_FORMAT): New define.         (FILE_STERM_FORMAT): New define.         (TARGET_FILE_FUNCTION_FORMAT): New define.         * config/rs6000/aix64.opt: Add -mcdtors flag.         * config/rs6000/aix71.h (LINK_SPEC_COMMON): Pass -bcdtors when           -mcdtors=aix is passed.         * config/rs6000/aix72.h (LINK_SPEC_COMMON): Likewise.         * config/rs6000/aix73.h (LINK_SPEC_COMMON): Likewise.         * config/rs6000/rs6000-opts.h (enum rs6000_cdtors): New enum.         * tree.c (get_file_function_name): Add           TARGET_FILE_FUNCTION_FORMAT support. gcc/testsuite/ChangeLog: 2021-10-04  Clément Chigot           * gcc.target/powerpc/constructor-aix.c: New test. From e1297880a2abe53db6422bcf25dcd883a2658260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Date: Mon, 4 Oct 2021 09:24:43 +0200 Subject: [PATCH] gcc: implement AIX-style constructors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AIX linker now supports constructors and destructors detection. For such functions to be detected, their name must starts with __sinit or __sterm. and -bcdtors must be passed to linker calls. It will create "_cdtors" symbol which can be used to launch the initialization. This patch creates a new RS6000 flag "-mcdtors=". With "-mcdtors=aix", gcc will generate these new constructors/destructors. With "-mcdtors=gcc", which is currently the default, gcc will continue to generate "gcc" format for constructors (ie _GLOBAL__I and _GLOBAL__D symbols). Ideally, it would have been better to enable the AIX format by default instead of using collect2. However, the compatibility between the previously-built binaries and the new ones is too complex to be done. gcc/ChangeLog: 2021-10-04 Clément Chigot * collect2.c (aixbcdtors_flags): New variable. (main): Use it to detect -bcdtors and remove -binitfini flag. (write_c_file_stat): Adapt to new AIX format. * config/rs6000/aix.h (FILE_SINIT_FORMAT): New define. (FILE_STERM_FORMAT): New define. (TARGET_FILE_FUNCTION_FORMAT): New define. * config/rs6000/aix64.opt: Add -mcdtors flag. * config/rs6000/aix71.h (LINK_SPEC_COMMON): Pass -bcdtors when -mcdtors=aix is passed. * config/rs6000/aix72.h (LINK_SPEC_COMMON): Likewise. * config/rs6000/aix73.h (LINK_SPEC_COMMON): Likewise. * config/rs6000/rs6000-opts.h (enum rs6000_cdtors): New enum. * tree.c (get_file_function_name): Add TARGET_FILE_FUNCTION_FORMAT support. gcc/testsuite/ChangeLog: 2021-10-04 Clément Chigot * gcc.target/powerpc/constructor-aix.c: New test. --- gcc/collect2.c | 91 +++++++++++++++++-- gcc/config/rs6000/aix.h | 56 ++++++++++++ gcc/config/rs6000/aix64.opt | 17 ++++ gcc/config/rs6000/aix71.h | 2 +- gcc/config/rs6000/aix72.h | 2 +- gcc/config/rs6000/aix73.h | 2 +- gcc/config/rs6000/rs6000-opts.h | 8 ++ .../gcc.target/powerpc/constructor-aix.c | 12 +++ gcc/tree.c | 5 + 9 files changed, 184 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/constructor-aix.c diff --git a/gcc/collect2.c b/gcc/collect2.c index 6f913041f26..59658cbadb7 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -186,6 +186,7 @@ static int aix64_flag; /* true if -b64 */ static int aixrtl_flag; /* true if -brtl */ static int aixlazy_flag; /* true if -blazy */ static int visibility_flag; /* true if -fvisibility */ +static int aixbcdtors_flag; /* True if -bcdtors */ #endif enum lto_mode_d { @@ -984,6 +985,8 @@ main (int argc, char **argv) aixrtl_flag = 0; else if (strcmp (argv[i], "-blazy") == 0) aixlazy_flag = 1; + else if (strcmp (argv[i], "-bcdtors") == 0) + aixbcdtors_flag = 1; #endif } @@ -1731,7 +1734,9 @@ main (int argc, char **argv) /* Tell the linker that we have initializer and finalizer functions. */ #ifdef LD_INIT_SWITCH #ifdef COLLECT_EXPORT_LIST - *ld2++ = concat (LD_INIT_SWITCH, ":", initname, ":", fininame, NULL); + /* Do not emit -binitfini when -bcdtors is enabled. */ + if (!aixbcdtors_flag) + *ld2++ = concat (LD_INIT_SWITCH, ":", initname, ":", fininame, NULL); #else *ld2++ = LD_INIT_SWITCH; *ld2++ = initname; @@ -2020,6 +2025,7 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) { const char *p, *q; char *prefix, *r; + char *regframe_name, *deregframe_name; int frames = (frame_tables.number > 0); /* Figure out name of output_file, stripping off .so version. */ @@ -2062,6 +2068,22 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) aix_shared_fininame = concat ("_GLOBAL__AIXD_", prefix, NULL); #endif + regframe_name = concat ("reg_frame", NULL, NULL); + deregframe_name = concat ("dereg_frame", NULL, NULL); +#ifdef COLLECT_EXPORT_LIST + /* In order to be detected by the linker, sinit/sterm symbols + must be external. Thus, reg_frame and dereg_frame can't + be static anymore and their name needs to be unique. + In order to ensure that frames are initialized before any + constructors, their constructor must have the highest priority + 0. */ + if (aixbcdtors_flag) + { + regframe_name = concat ("__sinit0_reg_frame_", prefix, NULL); + deregframe_name = concat ("__sterm0_dereg_frame_", prefix, NULL); + } +#endif + free (prefix); /* Write the tables as C code. */ @@ -2073,9 +2095,44 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) mechanisms GCC uses to order constructors across different dependent shared libraries (see config/rs6000/aix.h). */ - fprintf (stream, "static int count;\n"); - fprintf (stream, "typedef void entry_pt();\n"); - write_list_with_asm (stream, "extern entry_pt ", constructors.first); +#ifdef COLLECT_EXPORT_LIST + if (!aixbcdtors_flag) + { +#endif + fprintf (stream, "static int count;\n"); + fprintf (stream, "typedef void entry_pt();\n"); + write_list_with_asm (stream, "extern entry_pt ", constructors.first); +#ifdef COLLECT_EXPORT_LIST + } +#endif + +#ifdef COLLECT_EXPORT_LIST + if (aixbcdtors_flag && !shared_obj) + { + /* Use __C_runtime_pstartup to run ctors and register dtors. + This whole part should normally be in libgcc but as + AIX cdtors format is currently not the default, managed + that in collect2. */ + fprintf (stream, "extern void (* _cdtors[]) (void);\n"); + fprintf (stream, "extern void __run_initial_ctors (void (**) (void));\n"); + fprintf (stream, "extern void __run_final_dtors (void);\n"); + fprintf (stream, "void _AIX_init(void)\n"); + fprintf (stream, "{\n"); + fprintf (stream, " __run_initial_ctors(&_cdtors[0]);\n"); + fprintf (stream, " __run_final_dtors();\n"); + fprintf (stream, "}\n"); + fprintf (stream, "void (*__C_runtime_pstartup) (void) = _AIX_init;\n"); + fprintf (stream, "\n"); + + /* crtcxa is compiled without -mcdtors=aix flag thus we must + manually ensure that __init_aix_libgcc_cxa_atexit is called + with AIX format. */ + fprintf (stream, "void __sterm65535_0__init_aix_libgcc_cxa_atexit (void)\n"); + fprintf (stream, "{\n"); + fprintf (stream, " __init_aix_libgcc_cxa_atexit ();\n"); + fprintf (stream, "}\n"); + } +#endif if (frames) { @@ -2102,7 +2159,12 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) fprintf (stream, "extern void *__gcc_unwind_dbase;\n"); #endif - fprintf (stream, "static void reg_frame () {\n"); +#ifdef COLLECT_EXPORT_LIST + if (aixbcdtors_flag) + fprintf (stream, "void %s () {\n", regframe_name); + else +#endif + fprintf (stream, "static void reg_frame () {\n"); fprintf (stream, "\tstatic struct object ob;\n"); #ifdef TARGET_AIX_VERSION /* Use __gcc_unwind_dbase as the base address for data on AIX. @@ -2114,11 +2176,24 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) #endif fprintf (stream, "\t}\n"); - fprintf (stream, "static void dereg_frame () {\n"); +#ifdef COLLECT_EXPORT_LIST + if (aixbcdtors_flag) + fprintf (stream, "void %s () {\n", deregframe_name); + else +#endif + fprintf (stream, "static void dereg_frame () {\n"); fprintf (stream, "\t__deregister_frame_info (frame_table);\n"); fprintf (stream, "\t}\n"); } +#ifdef COLLECT_EXPORT_LIST + /* Files built with the new AIX cdtors format don't need to + explicitly call them. + NOTE: This breaks compatibility with previously-built files. */ + if (aixbcdtors_flag) + return; +#endif + #ifdef COLLECT_EXPORT_LIST /* Set visibility of initializers to default. */ if (visibility_flag) @@ -2130,7 +2205,7 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) fprintf (stream, "\tstatic entry_pt *ctors[] = {\n"); write_list (stream, "\t\t", constructors.first); if (frames) - fprintf (stream, "\treg_frame,\n"); + fprintf (stream, "\t%s,\n", regframe_name); fprintf (stream, "\t};\n"); fprintf (stream, "\tentry_pt **p;\n"); fprintf (stream, "\tif (count++ != 0) return;\n"); @@ -2147,7 +2222,7 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) fprintf (stream, "\tstatic entry_pt *dtors[] = {\n"); write_list (stream, "\t\t", destructors.first); if (frames) - fprintf (stream, "\tdereg_frame,\n"); + fprintf (stream, "\t%s,\n", deregframe_name); fprintf (stream, "\t};\n"); fprintf (stream, "\tentry_pt **p;\n"); fprintf (stream, "\tif (--count != 0) return;\n"); diff --git a/gcc/config/rs6000/aix.h b/gcc/config/rs6000/aix.h index 0f4d8cb2dc8..d9ed88cb459 100644 --- a/gcc/config/rs6000/aix.h +++ b/gcc/config/rs6000/aix.h @@ -284,3 +284,59 @@ #define SUBTARGET_DRIVER_SELF_SPECS \ "%{m64:-maix64} %