From patchwork Thu Apr 18 21:43:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Karpov X-Patchwork-Id: 88691 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 27120384AB49 for ; Thu, 18 Apr 2024 21:44:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2132.outbound.protection.outlook.com [40.107.13.132]) by sourceware.org (Postfix) with ESMTPS id 805333858D33 for ; Thu, 18 Apr 2024 21:43:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 805333858D33 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=microsoft.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 805333858D33 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.13.132 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713476625; cv=pass; b=Y1eJ3oQEUO0dhE03+GgyzO/mmcf3lr761YMhNJFxivj96fQWTKkZ0eHt5AU2FKmlLoNYmWdftPkF83+HE3+/htSD1CuAiMjOxhJ0BIIYsST3Y2C7p1hf4RfP1/XXE6yWft+3XsxZ9HgsNhTAGu+SBOvYZkf8Iq7ymaV3fSWN0rE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713476625; c=relaxed/simple; bh=MHa1BZYgv9M9KhgbWujVBy9/XLXrfhy17Yn8LrqQIwI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UAJXI4P10IVj6h/41QTUW0gSqnl7vr6j6+H1sbM75dvta/QD/GByGuJpMG4l6/oXwybPajG61u/5Z22abiue0cGXuZ7YvW67LKzFZMF/iGAZHKljZxVsd6tcLf3BcYk9E4UcfldV5Z6pN1ziuLfNt2ZYNdzSNbsLsXczokKX7LU= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZYSRhz9CmzlH21QANeIXvSXyfrQNq+Xz+nCt2BElcTSu+kDEHJSZdbFASlVGdJ2zMRAWaKdaMOFFGTliue3MvjvWjPp4cFOjfgss8Vz5Un3x/U+d6fgptPF+9B9kgfuBFx5ClG5bS2R1+QXuwFG1l8rcE/+mx8O/kUTxHkoMTFK8Sve4/Hda7e5//9qxss2STaw6a1+5HXMSZLCy528Avdx62vdX579HWj07E/svJnZGCsKzFpIC9cAAEDUiaaDl9CLjOyzrxIb5B9yp89CDuN+BMmt38LBMqKWJeEuM3zFvZrM6+Sl445SaspXqQXwIMW7IigQkwhO/awixYCgo0g== 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=w2U2t0GtLfSeT99WIQClUT8VjvqPlG12wpdQIo727kI=; b=JmtSMrchiazCa01h0h8chVLNt2IH+5WZNLSwGeF/Z1i+cNiIDZwJn29LJpBBnKAxJKUcHq0wssRWuCzbkBPKS8w60+NXsiumlH+O+IS8Q7RUQK4oO0qkQUj1t6YrocYhX9z8ySjV7OT6LG4xSN6UTi8EMU6EojOKFwdO+XgymOjpu/WdVWL7erXjmhUd/nNabpwAQOJu33gmplZbQwCu6ZdBgerZ2m3nWumrBvrGVRX+3tk7TSvnbuSsGPr5/alT0Tuf0c49BUEfWSoT3bghAasyd669eF8g2zDGmc2V3LSbbEKhpu3Gm1Su7B+C7qYGHFN9k5oph30ugh9E76T3mA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w2U2t0GtLfSeT99WIQClUT8VjvqPlG12wpdQIo727kI=; b=OKTUF225ECbHxg6Jya3peH+tdGo40O/w2EcZ3rS/39HMh4gABvs8LJMsErLmnFOyXBiKn4jPYlxQoCJVu0uEUvD6djn0TjOg8IPsLRu/uSTPpyzEe4xhYzTPWglv+EEqkZT5yy4i/eNI0kT8F64xolcpMb5B0fmU115UjB1sBZg= Received: from PR3PR83MB0425.EURPRD83.prod.outlook.com (2603:10a6:102:5f::21) by DBBPR83MB0563.EURPRD83.prod.outlook.com (2603:10a6:10:533::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.12; Thu, 18 Apr 2024 21:43:37 +0000 Received: from PR3PR83MB0425.EURPRD83.prod.outlook.com ([fe80::2303:5667:fa24:79c2]) by PR3PR83MB0425.EURPRD83.prod.outlook.com ([fe80::2303:5667:fa24:79c2%7]) with mapi id 15.20.7519.014; Thu, 18 Apr 2024 21:43:37 +0000 From: Evgeny Karpov To: Evgeny Karpov , "gcc-patches@gcc.gnu.org" CC: "richard.sandiford@arm.com" , "Richard Earnshaw (lists)" , Maxim Kuvyrkov , Radek Barton Subject: [PATCH v1 2/6] Extract ix86 dllimport implementation to mingw Thread-Topic: [PATCH v1 2/6] Extract ix86 dllimport implementation to mingw Thread-Index: AQHakdl4yBd50+i1eUKP8VeuXhZlmg== Date: Thu, 18 Apr 2024 21:43:37 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=7edbbdf7-0382-4215-8fdf-996305ff5b5e; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2024-04-18T21:26:39Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PR3PR83MB0425:EE_|DBBPR83MB0563:EE_ x-ms-office365-filtering-correlation-id: 7adad307-a0e6-4d22-c545-08dc5ff09aa9 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|1800799015|376005|366007|38070700009; x-microsoft-antispam-message-info: +HnKQ7yCjEuOKFBwnJLDgPOgsYzxOygP8ZBtAAsZ3/tpQBTyQCOBNkbVJWU2OJzB1XUfscYtkpnbBB/n3zZcUYfsjzl9RaNFveMwoAJWgfSh+f+w+nioXngfhx42iFREmYT3ABFG31ytOfEgrwbT4peASzxvTmND7vca6TEA/asG9lm5tR0TjlVIdDdz4JWpZo16fJ/fsXK/KMapy5N3NsAgxvJw4sc7gbHTMLTJusp1B3zVTK4Uw+pnrsxXG07NzJla3fzRj4eqLJCHuMRTjO+aCXsWR7VtGllnRhyjbWn34fG7OJS750TRkWmjsmkWbrOpvDss8wkxffqOW82PG5uekIue20buyj6tTiqXmYSK714RhuaqGfHTMye1TlDqGjzhETZcesar+a9XljDVowJTEsSF5cBifQYFwcmHPdI6wr7CnvHlEEzMqhYWErwhgRJrjDKp6k4RZyOkr0TTQL4U4C8uR7n95r1q9I67iZWNi+hpCH4o7W0NALT10tYisVLZLEEI9uP2/qdiaVHqLns1tttVnK/G56FJy0l7sOKn40S/KKzmsFnnyxwrsqjWkYRwX0Xops6ktwD+okrhBS21ORp+i9j2kTaeYXTY1rwEfqSipkimd9jNBFcC2mg1OYqFTH4BJCeIicR1cBEoD0cSHbHyq7j/jklHGPpvYWSg+46jsVinhjRnEYRC1LmWHBUM+EefaK8DT6LlvMsfGiy0aGLgJtt33gnr7SdBO6A4x3N9owOb0GG8U1tNHaRlpmX+KzIiFt4yEI1EpY0Mrp9j1JSUppU10llyTHMmRTt0OfaHRNJhqybck4SnXEQnDE/FjY+FN+iTCD0hQ+MDwGYkP95O4N/VE1SPIAhUWbozwVeBJVwCni6yyALPW5MOIrWfSzEVnZRNJ9imuULw2OoNmO0Pds5YK6tBIoPfpxyD007ZlGkBpRPgD5E9tH4Kpbyw8D6ZHD88YPbHeNoKZl9apUZLo0xEACbD34syizSx82EKgEocARa7t+tpM+ba9rnoPPQxyr/dXolDFXK5ZxX/f+yHo5rFqD4CJ8uOZVApSXlVwz1YZV6Je3SZVFAsjofaTQOj7joVmNjx4HJfRAlNGbjX1jdycE0lNd3T9t++6j+fFm+FTiNdSC0TV58sDHnX9hf30RiNORYtkS1LgMlqybpB0oG3jsf83HzRZuI7OtpdUyqSotqVOfZMf49jWVq4h9VuURnlhg901LdUSVtLEqnoxNg9SGswOQQdeAb3E09na+T5bfqjY7RejKvxhEVV7gcZzZIM+DGgBD+GBA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PR3PR83MB0425.EURPRD83.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(1800799015)(376005)(366007)(38070700009); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: tkjY2ZP3hKzjy12BfKbjuuxcAbNTH787xV4CyNhMKHqJXCjUfxr3wdbxmCqsAUNaimbzxSA71H16lIaFFLFGJ0ozN/ijPOIjv9K30mF25BaijwyrAtyKMUlBBhYe2YGIBWLT97ac2QBlUQgPnMMvklT1xMkCTTPUt+yMOxJoQcwLI6EJwYij+woOvUCYaQ4GZH9ewvL+f7g8DP7C3U2++/WJ5OdoCbwhWBhvbEgmXIban/JCTAoUcQszArERpOtqOzY3Bhn5wO90g3YclJFNO+Nh3AUOEnkJT29OsXj630ybtWkqSBKrN2zrIYVHkXhazt4Ba2CuGKuaeTj7Cly+YirkJ0ymiyqQl5Z86FJsm+OouFzYw0oagO545Z8lVmLgbaF78eNgeehon1gQokO/GDjDd0Regd+G1bhkp7zfvZTH0Qs3QW2WxbXdyIcW0bDsJLLonZyHlvmHNUyVpA3wjsy/t0fi122dW7NSxP8jT7vphjFZvTUm7ftAT+Ve0Wi9l3ewIdw/7z2iRXfn/r1Gl1ODsICBv8x9C4ynfd676VVlSXzhd5oG2bqzNDVjHo27AgaVXPRxRiyFE4KHr/sejIa7+6DxZa7WA9ED4hD9cXnyGA90uoduOkEFq3SS1+/BDP6DWYfa3aAby+0OaE2GBkh/COyyamOEL97CSBTsotMzKK1aS90y//qWTJmb+0Fta6b3rsYHH4xMISYAW6c1RSgEJnBe8SVgDQu5DMmHzSAig4L17IQoWFoLJ2pmFevdXeVKkUW5UZLnz0Qe9Hz9PfXsuQnTSmVvQyxp9ZbzNNlhsQtht4ubaRrjc4TH1bMHJKNMTReQbvcGzG0Lnviqe9PONNlZMys8J+6sWIRzBw6mn3586D/QjACGOmZRS5Xl1IRgw8fSW34JYCby/kK4JC9J5CWzXifZ+1O2dYlu6JDi/7MOUtIl1UnSpQhrbM9U2QVs/zfbV4I/YqsW8u2oYtZ4KfozPTrZAxQTcryPa4liFmitNY6YUcLyYf9qftuHpJ8uVBUbzc3l3ukhWPLefDf9zh1tvyJxzChAT3tH12nldhMjbYdGPqDpOtu0A6fQTefh0MyQ9lZTUe9oIUoVnwl/1XNM8uQ3kmThf95zUnuuVG4wWhyY0lxHGvUfoz7iR6UqCce5eGRTIWH9ZfgYMJkWq6DYHrX2VD3uzsPj3HjSc5J88t3EmSCOK925m86reQ5mDhEPjFAWmn3B2Ux2DnCac6+U7+j53dL6LL/zz1VUZ++nU1jNzwvTPx/KiGHP7V6wHs1yX3Pe38j871f3vh3UgYLJEHZanII6UCLPxV6GcT9m9GtNBeWtBBTKbn68PmEAWwBO31R5NmuAzvuTalQ2rDaeKw5JqBRO47NYe7B95RlbGEB1+5GSaZ2PKXgtHaw64X7jul10KFT2Hj5v2Ufp7pxPrPfrwHz18MAOBMmGKP/brzUz2Stx8mxbjWHWcOm3HAuYqmgor1soZSuMvusnooV9SbRz+EUCTDc8DSZeC81xKpVGhjnZUuDC/amHF91avBvPOWGXN5mIQlswT7ho50mjhIPf+51i4ZEGNOeZKhT7btRIzzM3NjmbjRkY MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PR3PR83MB0425.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7adad307-a0e6-4d22-c545-08dc5ff09aa9 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2024 21:43:37.0785 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: j/gWwa+Xj2pImx0ySdx1TW/O3eo3gNhefvAgnU4R8kEj/rHGqeFlpIpO8MvSk1Z53MqE1U7F+oQ6Y/FSR3JH4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR83MB0563 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org This patch extracts the ix86 implementation for expanding a SYMBOL into its corresponding dllimport, far-address, or refptr symbol. It will be reused in the aarch64-w64-mingw32 target. The implementation is copied as is from i386/i386.cc with minor changes to follow to the code style. Also this patch replaces the original DLL import/export implementation in ix86 with mingw. gcc/ChangeLog: * config.gcc: Add winnt-dll.o, which contains the DLL import/export implementation. * config/i386/cygming.h (SUB_TARGET_RECORD_STUB): Remove the old implementation. Rename the required function to MinGW. Rename it to a conditional function that will reuse the MinGW implementation for COFF and nothing otherwise. * config/i386/i386-expand.cc (ix86_expand_move): Likewise. * config/i386/i386-expand.h (is_imported_p): Likewise. (mingw_GOT_alias_set): Likewise. (ix86_legitimize_pe_coff_symbol): Likewise. * config/i386/i386-protos.h: Likewise. * config/i386/i386.cc (is_imported_p): Likewise. (ix86_legitimize_pe_coff_symbol): Likewise. (ix86_GOT_alias_set): Likewise. (legitimize_pic_address): Likewise. (struct dllimport_hasher): (GTY): Likewise. (get_dllimport_decl): Likewise. (legitimize_pe_coff_extern_decl): Likewise. (legitimize_dllimport_symbol): Likewise. (legitimize_pe_coff_symbol): Likewise. (ix86_legitimize_address): Likewise. * config/mingw/winnt.h (mingw_pe_record_stub): Likewise. * config/mingw/winnt.cc (i386_pe_record_stub): Likewise. (mingw_pe_record_stub): Likewise. * config/mingw/t-cygming: Add the winnt-dll.o compilation. * config/mingw/winnt-dll.cc: New file. --- gcc/config.gcc | 6 +- gcc/config/i386/cygming.h | 2 +- gcc/config/i386/i386-expand.cc | 2 +- gcc/config/i386/i386-expand.h | 2 +- gcc/config/i386/i386-protos.h | 2 +- gcc/config/i386/i386.cc | 211 ++++-------------------------- gcc/config/mingw/t-cygming | 6 + gcc/config/mingw/winnt-dll.cc | 229 +++++++++++++++++++++++++++++++++ gcc/config/mingw/winnt-dll.h | 26 ++++ gcc/config/mingw/winnt.cc | 2 +- gcc/config/mingw/winnt.h | 1 + 11 files changed, 292 insertions(+), 197 deletions(-) create mode 100644 gcc/config/mingw/winnt-dll.cc create mode 100644 gcc/config/mingw/winnt-dll.h diff --git a/gcc/config.gcc b/gcc/config.gcc index ef7f854735a..be2b20a155c 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -2181,7 +2181,7 @@ i[34567]86-*-cygwin*) tmake_file="${tmake_file} mingw/t-cygming t-slibgcc" target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc" extra_options="${extra_options} mingw/cygming.opt i386/cygwin.opt" - extra_objs="${extra_objs} winnt.o winnt-stubs.o" + extra_objs="${extra_objs} winnt.o winnt-stubs.o winnt-dll.o" c_target_objs="${c_target_objs} msformat-c.o" cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o" d_target_objs="${d_target_objs} cygwin-d.o" @@ -2199,7 +2199,7 @@ x86_64-*-cygwin*) tmake_file="${tmake_file} mingw/t-cygming t-slibgcc" target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc" extra_options="${extra_options} mingw/cygming.opt i386/cygwin.opt" - extra_objs="${extra_objs} winnt.o winnt-stubs.o" + extra_objs="${extra_objs} winnt.o winnt-stubs.o winnt-dll.o" c_target_objs="${c_target_objs} msformat-c.o" cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o" d_target_objs="${d_target_objs} cygwin-d.o" @@ -2283,7 +2283,7 @@ i[34567]86-*-mingw* | x86_64-*-mingw*) *) ;; esac - extra_objs="${extra_objs} winnt.o winnt-stubs.o" + extra_objs="${extra_objs} winnt.o winnt-stubs.o winnt-dll.o" c_target_objs="${c_target_objs} msformat-c.o" cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o" gas=yes diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h index beedf7c398a..4110ceab824 100644 --- a/gcc/config/i386/cygming.h +++ b/gcc/config/i386/cygming.h @@ -459,7 +459,7 @@ do { \ #define TARGET_ASM_ASSEMBLE_VISIBILITY i386_pe_assemble_visibility #undef SUB_TARGET_RECORD_STUB -#define SUB_TARGET_RECORD_STUB i386_pe_record_stub +#define SUB_TARGET_RECORD_STUB mingw_pe_record_stub /* Static stack checking is supported by means of probes. */ #define STACK_CHECK_STATIC_BUILTIN 1 diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 8bb8f21e686..77bf4433aa8 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -412,7 +412,7 @@ ix86_expand_move (machine_mode mode, rtx operands[]) } else { - tmp = legitimize_pe_coff_symbol (op1, addend != NULL_RTX); + tmp = ix86_legitimize_pe_coff_symbol (op1, addend != NULL_RTX); if (tmp) { op1 = tmp; diff --git a/gcc/config/i386/i386-expand.h b/gcc/config/i386/i386-expand.h index 65cb49c921c..a8c20993954 100644 --- a/gcc/config/i386/i386-expand.h +++ b/gcc/config/i386/i386-expand.h @@ -36,7 +36,7 @@ struct expand_vec_perm_d rtx legitimize_tls_address (rtx x, enum tls_model model, bool for_mov); alias_set_type ix86_GOT_alias_set (void); rtx legitimize_pic_address (rtx orig, rtx reg); -rtx legitimize_pe_coff_symbol (rtx addr, bool inreg); +rtx ix86_legitimize_pe_coff_symbol (rtx addr, bool inreg); bool insn_defines_reg (unsigned int regno1, unsigned int regno2, rtx_insn *insn); diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 96368521380..dbced12f8d4 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config/mingw/winnt.h" +#include "config/mingw/winnt-dll.h" /* In i386-common.cc. */ extern bool ix86_handle_option (struct gcc_options *opts, @@ -314,7 +315,6 @@ extern void i386_pe_end_cold_function (FILE *, const char *, tree); extern void i386_pe_assemble_visibility (tree, int); extern tree i386_pe_mangle_decl_assembler_name (tree, tree); extern tree i386_pe_mangle_assembler_name (const char *); -extern void i386_pe_record_stub (const char *); extern void i386_pe_seh_init (FILE *); extern void i386_pe_seh_end_prologue (FILE *); diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 4d6b2b98761..a17e819602a 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -11230,20 +11230,6 @@ ix86_cannot_force_const_mem (machine_mode mode, rtx x) return !ix86_legitimate_constant_p (mode, x); } -/* Nonzero if the symbol is marked as dllimport, or as stub-variable, - otherwise zero. */ - -static bool -is_imported_p (rtx x) -{ - if (!TARGET_DLLIMPORT_DECL_ATTRIBUTES - || GET_CODE (x) != SYMBOL_REF) - return false; - - return SYMBOL_REF_DLLIMPORT_P (x) || SYMBOL_REF_STUBVAR_P (x); -} - - /* Nonzero if the constant value X is a legitimate general operand when generating PIC code. It is given that flag_pic is on and that X satisfies CONSTANT_P. */ @@ -11822,17 +11808,31 @@ constant_address_p (rtx x) return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1); } -/* Return a unique alias set for the GOT. */ + +#if TARGET_PECOFF +rtx ix86_legitimize_pe_coff_symbol (rtx addr, bool inreg) +{ + return legitimize_pe_coff_symbol (addr, inreg); +} alias_set_type ix86_GOT_alias_set (void) { - static alias_set_type set = -1; - if (set == -1) - set = new_alias_set (); - return set; + return mingw_GOT_alias_set (); +} +#else +rtx ix86_legitimize_pe_coff_symbol (rtx addr, bool inreg) +{ + return NULL_RTX; } +alias_set_type +ix86_GOT_alias_set (void) +{ + return -1; +} +#endif + /* Return a legitimate reference for ORIG (an address) using the register REG. If REG is 0, a new pseudo is generated. @@ -11869,7 +11869,7 @@ legitimize_pic_address (rtx orig, rtx reg) if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES) { - rtx tmp = legitimize_pe_coff_symbol (addr, true); + rtx tmp = ix86_legitimize_pe_coff_symbol (addr, true); if (tmp) return tmp; } @@ -11914,7 +11914,7 @@ legitimize_pic_address (rtx orig, rtx reg) on VxWorks, see gotoff_operand. */ || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF)) { - rtx tmp = legitimize_pe_coff_symbol (addr, true); + rtx tmp = ix86_legitimize_pe_coff_symbol (addr, true); if (tmp) return tmp; @@ -12489,173 +12489,6 @@ ix86_rewrite_tls_address (rtx pattern) return pattern; } -/* Create or return the unique __imp_DECL dllimport symbol corresponding - to symbol DECL if BEIMPORT is true. Otherwise create or return the - unique refptr-DECL symbol corresponding to symbol DECL. */ - -struct dllimport_hasher : ggc_cache_ptr_hash -{ - static inline hashval_t hash (tree_map *m) { return m->hash; } - static inline bool - equal (tree_map *a, tree_map *b) - { - return a->base.from == b->base.from; - } - - static int - keep_cache_entry (tree_map *&m) - { - return ggc_marked_p (m->base.from); - } -}; - -static GTY((cache)) hash_table *dllimport_map; - -static tree -get_dllimport_decl (tree decl, bool beimport) -{ - struct tree_map *h, in; - const char *name; - const char *prefix; - size_t namelen, prefixlen; - char *imp_name; - tree to; - rtx rtl; - - if (!dllimport_map) - dllimport_map = hash_table::create_ggc (512); - - in.hash = htab_hash_pointer (decl); - in.base.from = decl; - tree_map **loc = dllimport_map->find_slot_with_hash (&in, in.hash, INSERT); - h = *loc; - if (h) - return h->to; - - *loc = h = ggc_alloc (); - h->hash = in.hash; - h->base.from = decl; - h->to = to = build_decl (DECL_SOURCE_LOCATION (decl), - VAR_DECL, NULL, ptr_type_node); - DECL_ARTIFICIAL (to) = 1; - DECL_IGNORED_P (to) = 1; - DECL_EXTERNAL (to) = 1; - TREE_READONLY (to) = 1; - - name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); - name = targetm.strip_name_encoding (name); - if (beimport) - prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0 - ? "*__imp_" : "*__imp__"; - else - prefix = user_label_prefix[0] == 0 ? "*.refptr." : "*refptr."; - namelen = strlen (name); - prefixlen = strlen (prefix); - imp_name = (char *) alloca (namelen + prefixlen + 1); - memcpy (imp_name, prefix, prefixlen); - memcpy (imp_name + prefixlen, name, namelen + 1); - - name = ggc_alloc_string (imp_name, namelen + prefixlen); - rtl = gen_rtx_SYMBOL_REF (Pmode, name); - SET_SYMBOL_REF_DECL (rtl, to); - SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_STUBVAR; - if (!beimport) - { - SYMBOL_REF_FLAGS (rtl) |= SYMBOL_FLAG_EXTERNAL; -#ifdef SUB_TARGET_RECORD_STUB - SUB_TARGET_RECORD_STUB (name); -#endif - } - - rtl = gen_const_mem (Pmode, rtl); - set_mem_alias_set (rtl, ix86_GOT_alias_set ()); - - SET_DECL_RTL (to, rtl); - SET_DECL_ASSEMBLER_NAME (to, get_identifier (name)); - - return to; -} - -/* Expand SYMBOL into its corresponding far-address symbol. - WANT_REG is true if we require the result be a register. */ - -static rtx -legitimize_pe_coff_extern_decl (rtx symbol, bool want_reg) -{ - tree imp_decl; - rtx x; - - gcc_assert (SYMBOL_REF_DECL (symbol)); - imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), false); - - x = DECL_RTL (imp_decl); - if (want_reg) - x = force_reg (Pmode, x); - return x; -} - -/* Expand SYMBOL into its corresponding dllimport symbol. WANT_REG is - true if we require the result be a register. */ - -static rtx -legitimize_dllimport_symbol (rtx symbol, bool want_reg) -{ - tree imp_decl; - rtx x; - - gcc_assert (SYMBOL_REF_DECL (symbol)); - imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), true); - - x = DECL_RTL (imp_decl); - if (want_reg) - x = force_reg (Pmode, x); - return x; -} - -/* Expand SYMBOL into its corresponding dllimport or refptr symbol. WANT_REG - is true if we require the result be a register. */ - -rtx -legitimize_pe_coff_symbol (rtx addr, bool inreg) -{ - if (!TARGET_PECOFF) - return NULL_RTX; - - if (TARGET_DLLIMPORT_DECL_ATTRIBUTES) - { - if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr)) - return legitimize_dllimport_symbol (addr, inreg); - if (GET_CODE (addr) == CONST - && GET_CODE (XEXP (addr, 0)) == PLUS - && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF - && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0))) - { - rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), inreg); - return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1)); - } - } - - if (ix86_cmodel != CM_LARGE_PIC && ix86_cmodel != CM_MEDIUM_PIC) - return NULL_RTX; - if (GET_CODE (addr) == SYMBOL_REF - && !is_imported_p (addr) - && SYMBOL_REF_EXTERNAL_P (addr) - && SYMBOL_REF_DECL (addr)) - return legitimize_pe_coff_extern_decl (addr, inreg); - - if (GET_CODE (addr) == CONST - && GET_CODE (XEXP (addr, 0)) == PLUS - && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF - && !is_imported_p (XEXP (XEXP (addr, 0), 0)) - && SYMBOL_REF_EXTERNAL_P (XEXP (XEXP (addr, 0), 0)) - && SYMBOL_REF_DECL (XEXP (XEXP (addr, 0), 0))) - { - rtx t = legitimize_pe_coff_extern_decl (XEXP (XEXP (addr, 0), 0), inreg); - return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1)); - } - return NULL_RTX; -} - /* Try machine-dependent ways of modifying an illegitimate address to be legitimate. If we find one, return the new, valid address. This macro is used in only one place: `memory_address' in explow.cc. @@ -12695,7 +12528,7 @@ ix86_legitimize_address (rtx x, rtx, machine_mode mode) if (TARGET_DLLIMPORT_DECL_ATTRIBUTES) { - rtx tmp = legitimize_pe_coff_symbol (x, true); + rtx tmp = ix86_legitimize_pe_coff_symbol (x, true); if (tmp) return tmp; } diff --git a/gcc/config/mingw/t-cygming b/gcc/config/mingw/t-cygming index f5de941c8e5..73679a9d6c0 100644 --- a/gcc/config/mingw/t-cygming +++ b/gcc/config/mingw/t-cygming @@ -33,6 +33,12 @@ winnt-cxx.o: $(srcdir)/config/mingw/winnt-cxx.cc $(CONFIG_H) $(SYSTEM_H) \ $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ $(srcdir)/config/mingw/winnt-cxx.cc +winnt-dll.o: $(srcdir)/config/mingw/winnt-dll.cc $(CONFIG_H) $(SYSTEM_H) \ + coretypes.h \ + $(TM_H) $(TREE_H) flags.h \ + $(TM_P_H) $(HASHTAB_H) $(GGC_H) + $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + $(srcdir)/config/mingw/winnt-dll.cc winnt-stubs.o: $(srcdir)/config/mingw/winnt-stubs.cc $(CONFIG_H) $(SYSTEM_H) \ coretypes.h \ diff --git a/gcc/config/mingw/winnt-dll.cc b/gcc/config/mingw/winnt-dll.cc new file mode 100644 index 00000000000..349ade6f5c0 --- /dev/null +++ b/gcc/config/mingw/winnt-dll.cc @@ -0,0 +1,229 @@ +/* Expand a SYMBOL into its corresponding dllimport, far-address, +or refptr symbol. +Copyright (C) 2024 Free Software Foundation, Inc. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +http://www.gnu.org/licenses/. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "target.h" +#include "rtl.h" +#include "tree.h" +#include "memmodel.h" +#include "stringpool.h" +#include "emit-rtl.h" +#include "alias.h" +#include "varasm.h" +#include "output.h" +#include "explow.h" +#include "winnt.h" + +/* Create or return the unique __imp_DECL dllimport symbol corresponding + to symbol DECL if BEIMPORT is true. Otherwise create or return the + unique refptr-DECL symbol corresponding to symbol DECL. */ + +struct dllimport_hasher : ggc_cache_ptr_hash +{ + static inline hashval_t hash (tree_map *m) + { + return m->hash; + } + + static inline bool + equal (tree_map *a, tree_map *b) + { + return a->base.from == b->base.from; + } + + static int + keep_cache_entry (tree_map *&m) + { + return ggc_marked_p (m->base.from); + } +}; + +static GTY ((cache)) hash_table *dllimport_map; + +/* Nonzero if the symbol is marked as dllimport, or as stub-variable, + otherwise zero. */ + +bool +is_imported_p (rtx x) +{ + if (!TARGET_DLLIMPORT_DECL_ATTRIBUTES + || GET_CODE (x) != SYMBOL_REF) + return false; + + return SYMBOL_REF_DLLIMPORT_P (x) || SYMBOL_REF_STUBVAR_P (x); +} + +/* Return a unique alias set for the GOT. */ + +alias_set_type +mingw_GOT_alias_set (void) +{ + static alias_set_type set = -1; + if (set == -1) + set = new_alias_set (); + return set; +} + +static tree +get_dllimport_decl (tree decl, bool beimport) +{ + struct tree_map *h, in; + const char *name; + const char *prefix; + size_t namelen, prefixlen; + char *imp_name; + tree to; + rtx rtl; + + if (!dllimport_map) + dllimport_map = hash_table::create_ggc (512); + + in.hash = htab_hash_pointer (decl); + in.base.from = decl; + tree_map **loc = dllimport_map->find_slot_with_hash (&in, in.hash, INSERT); + h = *loc; + if (h) + return h->to; + + *loc = h = ggc_alloc (); + h->hash = in.hash; + h->base.from = decl; + h->to = to = build_decl (DECL_SOURCE_LOCATION (decl), + VAR_DECL, NULL, ptr_type_node); + DECL_ARTIFICIAL (to) = 1; + DECL_IGNORED_P (to) = 1; + DECL_EXTERNAL (to) = 1; + TREE_READONLY (to) = 1; + + name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + name = targetm.strip_name_encoding (name); + if (beimport) + prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0 + ? "*__imp_" : "*__imp__"; + else + prefix = user_label_prefix[0] == 0 ? "*.refptr." : "*refptr."; + namelen = strlen (name); + prefixlen = strlen (prefix); + imp_name = (char *) alloca (namelen + prefixlen + 1); + memcpy (imp_name, prefix, prefixlen); + memcpy (imp_name + prefixlen, name, namelen + 1); + + name = ggc_alloc_string (imp_name, namelen + prefixlen); + rtl = gen_rtx_SYMBOL_REF (Pmode, name); + SET_SYMBOL_REF_DECL (rtl, to); + SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_STUBVAR; + if (!beimport) + { + SYMBOL_REF_FLAGS (rtl) |= SYMBOL_FLAG_EXTERNAL; +#ifdef SUB_TARGET_RECORD_STUB + SUB_TARGET_RECORD_STUB (name); +#endif + } + + rtl = gen_const_mem (Pmode, rtl); + set_mem_alias_set (rtl, mingw_GOT_alias_set ()); + + SET_DECL_RTL (to, rtl); + SET_DECL_ASSEMBLER_NAME (to, get_identifier (name)); + + return to; +} + +/* Expand SYMBOL into its corresponding far-address symbol. + WANT_REG is true if we require the result be a register. */ + +static rtx +legitimize_pe_coff_extern_decl (rtx symbol, bool want_reg) +{ + tree imp_decl; + rtx x; + + gcc_assert (SYMBOL_REF_DECL (symbol)); + imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), false); + + x = DECL_RTL (imp_decl); + if (want_reg) + x = force_reg (Pmode, x); + return x; +} + +/* Expand SYMBOL into its corresponding dllimport symbol. WANT_REG is + true if we require the result be a register. */ + +static rtx +legitimize_dllimport_symbol (rtx symbol, bool want_reg) +{ + tree imp_decl; + rtx x; + + gcc_assert (SYMBOL_REF_DECL (symbol)); + imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), true); + + x = DECL_RTL (imp_decl); + if (want_reg) + x = force_reg (Pmode, x); + return x; +} + +/* Expand SYMBOL into its corresponding dllimport or refptr symbol. WANT_REG + is true if we require the result be a register. */ + +rtx +legitimize_pe_coff_symbol (rtx addr, bool inreg) +{ + if (!TARGET_PECOFF) + return NULL_RTX; + + if (TARGET_DLLIMPORT_DECL_ATTRIBUTES) + { + if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr)) + return legitimize_dllimport_symbol (addr, inreg); + if (GET_CODE (addr) == CONST + && GET_CODE (XEXP (addr, 0)) == PLUS + && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF + && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0))) + { + rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), inreg); + return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1)); + } + } + + if (ix86_cmodel != CM_LARGE_PIC && ix86_cmodel != CM_MEDIUM_PIC) + return NULL_RTX; + + if (GET_CODE (addr) == SYMBOL_REF + && !is_imported_p (addr) + && SYMBOL_REF_EXTERNAL_P (addr) + && SYMBOL_REF_DECL (addr)) + return legitimize_pe_coff_extern_decl (addr, inreg); + + if (GET_CODE (addr) == CONST + && GET_CODE (XEXP (addr, 0)) == PLUS + && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF + && !is_imported_p (XEXP (XEXP (addr, 0), 0)) + && SYMBOL_REF_EXTERNAL_P (XEXP (XEXP (addr, 0), 0)) + && SYMBOL_REF_DECL (XEXP (XEXP (addr, 0), 0))) + { + rtx t = legitimize_pe_coff_extern_decl (XEXP (XEXP (addr, 0), 0), inreg); + return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1)); + } + return NULL_RTX; +} diff --git a/gcc/config/mingw/winnt-dll.h b/gcc/config/mingw/winnt-dll.h new file mode 100644 index 00000000000..19c16e747a2 --- /dev/null +++ b/gcc/config/mingw/winnt-dll.h @@ -0,0 +1,26 @@ +/* Expand a SYMBOL into its corresponding dllimport, far-address, +or refptr symbol. +Copyright (C) 2024 Free Software Foundation, Inc. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +http://www.gnu.org/licenses/. */ + +#ifndef GCC_MINGW_WINNT_DLL_H +#define GCC_MINGW_WINNT_DLL_H + +extern bool is_imported_p (rtx x); +extern alias_set_type mingw_GOT_alias_set (void); +extern rtx legitimize_pe_coff_symbol (rtx addr, bool inreg); + +#endif \ No newline at end of file diff --git a/gcc/config/mingw/winnt.cc b/gcc/config/mingw/winnt.cc index 2a4fc03fc56..9901576ade0 100644 --- a/gcc/config/mingw/winnt.cc +++ b/gcc/config/mingw/winnt.cc @@ -672,7 +672,7 @@ mingw_pe_maybe_record_exported_symbol (tree decl, const char *name, int is_data) } void -i386_pe_record_stub (const char *name) +mingw_pe_record_stub (const char *name) { struct stub_list *p; diff --git a/gcc/config/mingw/winnt.h b/gcc/config/mingw/winnt.h index da8445904ce..646654e872d 100644 --- a/gcc/config/mingw/winnt.h +++ b/gcc/config/mingw/winnt.h @@ -23,6 +23,7 @@ extern void mingw_pe_declare_function_type (FILE *file, const char *name, int pub); extern void mingw_pe_encode_section_info (tree, rtx, int); extern void mingw_pe_maybe_record_exported_symbol (tree, const char *, int); +extern void mingw_pe_record_stub (const char *name); extern unsigned int mingw_pe_section_type_flags (tree, const char *, int); extern void mingw_pe_unique_section (tree, int);