From: Evgeny Karpov <Evgeny.Karpov@microsoft.com>
To: Evgeny Karpov <Evgeny.Karpov@microsoft.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: "richard.sandiford@arm.com" <richard.sandiford@arm.com>,
"Richard Earnshaw (lists)" <Richard.Earnshaw@arm.com>,
Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>,
Radek Barton <radek.barton@microsoft.com>
Subject: [PATCH v1 6/6] aarch64: Add DLL import/export to AArch64 target
Date: Thu, 18 Apr 2024 21:49:00 +0000 [thread overview]
Message-ID: <PR3PR83MB0425ABAF6F80A79B4FA8DCB6F80E2@PR3PR83MB0425.EURPRD83.prod.outlook.com> (raw)
In-Reply-To: <PR3PR83MB0425E5A9911AEB3716BEC140F80E2@PR3PR83MB0425.EURPRD83.prod.outlook.com>
This patch reuses the MinGW implementation to enable DLL import/export
functionality for the aarch64-w64-mingw32 target. It also modifies
environment configurations for MinGW.
gcc/ChangeLog:
* config.gcc: Add winnt-dll.o, which contains the DLL
import/export implementation.
* config/aarch64/aarch64-protos.h (legitimize_pe_coff_symbol):
Declare a MinGW function for expanding a symbol for COFF.
* config/aarch64/aarch64.cc (aarch64_legitimize_pe_coff_symbol):
Add a conditional function that reuses the MinGW implementation
for COFF and does nothing otherwise.
(aarch64_load_symref_appropriately): Add dllimport
implementation.
(aarch64_expand_call): Likewise.
(aarch64_legitimize_address): Likewise.
* config/aarch64/cygming.h (SYMBOL_FLAG_DLLIMPORT): Modify MinGW
environment to support DLL import/export.
(SYMBOL_FLAG_DLLEXPORT): Likewise.
(SYMBOL_REF_DLLIMPORT_P): Likewise.
(SYMBOL_FLAG_STUBVAR): Likewise.
(SYMBOL_REF_STUBVAR_P): Likewise.
(mingw_pe_valid_dllimport_attribute_p): Likewise.
(mingw_pe_file_end): Likewise.
(mingw_pe_record_stub): Likewise.
(TARGET_VALID_DLLIMPORT_ATTRIBUTE_P): Likewise.
(TARGET_ASM_FILE_END): Likewise.
(SUB_TARGET_RECORD_STUB): Likewise.
---
gcc/config.gcc | 2 +-
gcc/config/aarch64/aarch64-protos.h | 1 +
gcc/config/aarch64/aarch64.cc | 37 +++++++++++++++++++++++++++++
gcc/config/aarch64/cygming.h | 19 +++++++++++++--
4 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index be2b20a155c..dce3a422daf 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1280,7 +1280,7 @@ aarch64-*-mingw*)
tmake_file="${tmake_file} aarch64/t-aarch64"
target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
extra_options="${extra_options} mingw/cygming.opt mingw/mingw.opt"
- extra_objs="${extra_objs} winnt.o"
+ extra_objs="${extra_objs} winnt.o winnt-dll.o"
c_target_objs="${c_target_objs} msformat-c.o"
d_target_objs="${d_target_objs} winnt-d.o"
tmake_file="${tmake_file} mingw/t-cygming"
diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
index 95972556c56..996acb60d61 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -25,6 +25,7 @@
#include "input.h"
#include "config/arm/aarch-common.h"
#include "config/mingw/winnt.h"
+#include "config/mingw/winnt-dll.h"
/* SYMBOL_SMALL_ABSOLUTE: Generate symbol accesses through
high and lo relocs that calculate the base address using a PC
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 19205927430..7e28b5f0c08 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -856,6 +856,10 @@ static const attribute_spec aarch64_gnu_attributes[] =
{ "Advanced SIMD type", 1, 1, false, true, false, true, NULL, NULL },
{ "SVE type", 3, 3, false, true, false, true, NULL, NULL },
{ "SVE sizeless type", 0, 0, false, true, false, true, NULL, NULL },
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
+ { "dllimport", 0, 0, false, false, false, false, handle_dll_attribute, NULL },
+ { "dllexport", 0, 0, false, false, false, false, handle_dll_attribute, NULL },
+#endif
#ifdef SUBTARGET_ATTRIBUTE_TABLE
SUBTARGET_ATTRIBUTE_TABLE
#endif
@@ -2815,6 +2819,15 @@ tls_symbolic_operand_type (rtx addr)
return tls_kind;
}
+rtx aarch64_legitimize_pe_coff_symbol (rtx addr, bool inreg)
+{
+#if TARGET_PECOFF
+ return legitimize_pe_coff_symbol (addr, inreg);
+#else
+ return NULL_RTX;
+#endif
+}
+
/* We'll allow lo_sum's in addresses in our legitimate addresses
so that combine would take care of combining addresses where
necessary, but for generation purposes, we'll generate the address
@@ -2861,6 +2874,17 @@ static void
aarch64_load_symref_appropriately (rtx dest, rtx imm,
enum aarch64_symbol_type type)
{
+ /* If legitimize returns a value
+ copy it directly to the destination and return. */
+
+ rtx tmp = aarch64_legitimize_pe_coff_symbol (imm, true);
+
+ if (tmp)
+ {
+ emit_insn (gen_rtx_SET (dest, tmp));
+ return;
+ }
+
switch (type)
{
case SYMBOL_SMALL_ABSOLUTE:
@@ -11231,6 +11255,12 @@ aarch64_expand_call (rtx result, rtx mem, rtx cookie, bool sibcall)
gcc_assert (MEM_P (mem));
callee = XEXP (mem, 0);
+
+ tmp = aarch64_legitimize_pe_coff_symbol (callee, false);
+
+ if (tmp)
+ callee = tmp;
+
mode = GET_MODE (callee);
gcc_assert (mode == Pmode);
@@ -12707,6 +12737,13 @@ aarch64_anchor_offset (HOST_WIDE_INT offset, HOST_WIDE_INT size,
static rtx
aarch64_legitimize_address (rtx x, rtx /* orig_x */, machine_mode mode)
{
+ if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
+ {
+ rtx tmp = aarch64_legitimize_pe_coff_symbol (x, true);
+ if (tmp)
+ return tmp;
+ }
+
/* Try to split X+CONST into Y=X+(CONST & ~mask), Y+(CONST&mask),
where mask is selected by alignment and size of the offset.
We try to pick as large a range for the offset as possible to
diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h
index 76623153080..4beebf9e093 100644
--- a/gcc/config/aarch64/cygming.h
+++ b/gcc/config/aarch64/cygming.h
@@ -28,12 +28,18 @@ along with GCC; see the file COPYING3. If not see
#define print_reg(rtx, code, file) (gcc_unreachable ())
-#define SYMBOL_FLAG_DLLIMPORT 0
-#define SYMBOL_FLAG_DLLEXPORT 0
+#define SYMBOL_FLAG_DLLIMPORT (SYMBOL_FLAG_MACH_DEP << 0)
+#define SYMBOL_REF_DLLIMPORT_P(X) \
+ ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_DLLIMPORT) != 0)
+#define SYMBOL_FLAG_DLLEXPORT (SYMBOL_FLAG_MACH_DEP << 1)
#define SYMBOL_REF_DLLEXPORT_P(X) \
((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_DLLEXPORT) != 0)
+#define SYMBOL_FLAG_STUBVAR (SYMBOL_FLAG_MACH_DEP << 2)
+#define SYMBOL_REF_STUBVAR_P(X) \
+ ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_STUBVAR) != 0)
+
/* Disable SEH and declare the required SEH-related macros that are
still needed for compilation. */
#undef TARGET_SEH
@@ -59,6 +65,12 @@ still needed for compilation. */
#define TARGET_ASM_UNIQUE_SECTION mingw_pe_unique_section
#define TARGET_ENCODE_SECTION_INFO mingw_pe_encode_section_info
+#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P mingw_pe_valid_dllimport_attribute_p
+
+/* Output function declarations at the end of the file. */
+#undef TARGET_ASM_FILE_END
+#define TARGET_ASM_FILE_END mingw_pe_file_end
+
/* Declare the type properly for any external libcall. */
#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
mingw_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
@@ -158,6 +170,9 @@ still needed for compilation. */
{ "selectany", 0, 0, true, false, false, false, \
mingw_handle_selectany_attribute, NULL }
+#undef SUB_TARGET_RECORD_STUB
+#define SUB_TARGET_RECORD_STUB mingw_pe_record_stub
+
#define SUPPORTS_ONE_ONLY 1
/* Define this to be nonzero if static stack checking is supported. */
--
2.25.1
next prev parent reply other threads:[~2024-04-18 21:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 21:35 [PATCH v1 0/6] Add DLL import/export implementation to AArch64 Evgeny Karpov
2024-04-18 21:41 ` [PATCH v1 1/6] Move mingw_* declarations to the mingw folder Evgeny Karpov
2024-04-18 21:43 ` [PATCH v1 2/6] Extract ix86 dllimport implementation to mingw Evgeny Karpov
2024-05-22 11:05 ` Richard Sandiford
2024-05-22 14:32 ` Evgeny Karpov
2024-05-23 8:35 ` Uros Bizjak
2024-05-23 8:41 ` Uros Bizjak
2024-05-23 17:53 ` Evgeny Karpov
2024-05-23 19:37 ` Uros Bizjak
2024-04-18 21:45 ` [PATCH v1 3/6] Rename functions for reuse in AArch64 Evgeny Karpov
2024-05-22 11:46 ` Richard Sandiford
2024-04-18 21:46 ` [PATCH v1 4/6] aarch64: Add selectany attribute handling Evgeny Karpov
2024-05-22 11:57 ` Richard Sandiford
2024-04-18 21:48 ` [PATCH v1 5/6] Adjust DLL import/export implementation for AArch64 Evgeny Karpov
2024-05-22 12:07 ` Richard Sandiford
2024-04-18 21:49 ` Evgeny Karpov [this message]
2024-06-04 20:10 ` [PATCH v1 0/6] Add DLL import/export implementation to AArch64 Evgeny Karpov
2024-06-05 6:01 ` Uros Bizjak
2024-06-05 23:41 ` Jonathan Yong
2024-06-06 9:23 ` Evgeny Karpov
2024-06-08 1:59 ` Jonathan Yong
2024-06-05 8:13 ` Richard Sandiford
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=PR3PR83MB0425ABAF6F80A79B4FA8DCB6F80E2@PR3PR83MB0425.EURPRD83.prod.outlook.com \
--to=evgeny.karpov@microsoft.com \
--cc=Richard.Earnshaw@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=maxim.kuvyrkov@linaro.org \
--cc=radek.barton@microsoft.com \
--cc=richard.sandiford@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).