From be2b1891b1330350e6a319d42be216ce38f3ca42 Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Mon, 15 Jul 2024 15:28:13 +0200 Subject: [PATCH 1/6] Handle aligment when it is bigger than BIGGEST_ALIGMENT --- gcc/config/aarch64/aarch64-coff.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h index e3703cd6220..3afd26506cf 100644 --- a/gcc/config/aarch64/aarch64-coff.h +++ b/gcc/config/aarch64/aarch64-coff.h @@ -65,11 +65,12 @@ #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGNMENT) \ { \ - unsigned HOST_WIDE_INT rounded = MAX((SIZE), 1); \ - unsigned HOST_WIDE_INT alignment = MAX((ALIGNMENT), BIGGEST_ALIGNMENT); \ - rounded += (alignment / BITS_PER_UNIT) - 1; \ - rounded = (rounded / (alignment / BITS_PER_UNIT) \ - * (alignment / BITS_PER_UNIT)); \ + unsigned HOST_WIDE_INT rounded = SIZE; \ + if (SIZE == 0) \ + rounded = 1; \ + rounded += (ALIGNMENT / BITS_PER_UNIT) - 1; \ + rounded = (rounded / (ALIGNMENT / BITS_PER_UNIT) \ + * ((ALIGNMENT) / BITS_PER_UNIT)); \ ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, rounded); \ } From 62ba4c0ad08555d7bd66fb082f7008368b43e2ee Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Mon, 15 Jul 2024 16:44:45 +0200 Subject: [PATCH 2/6] Add visibility support --- gcc/config/aarch64/cygming.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h index b062e6d9ce5..274432b731f 100644 --- a/gcc/config/aarch64/cygming.h +++ b/gcc/config/aarch64/cygming.h @@ -319,12 +319,17 @@ do { \ #define HAVE_64BIT_POINTERS 1 +extern void i386_pe_assemble_visibility (tree, int); + /* Kludge because of missing PE-COFF support for early LTO debug. */ #undef TARGET_ASM_LTO_START #define TARGET_ASM_LTO_START mingw_pe_asm_lto_start #undef TARGET_ASM_LTO_END #define TARGET_ASM_LTO_END mingw_pe_asm_lto_end +#undef TARGET_ASM_ASSEMBLE_VISIBILITY +#define TARGET_ASM_ASSEMBLE_VISIBILITY i386_pe_assemble_visibility + /* According to Windows x64 software convention, the maximum stack allocatable in the prologue is 4G - 8 bytes. Furthermore, there is a limited set of instructions allowed to adjust the stack pointer in the epilog, forcing the From 3c741f2c27e53d85f5e5b82c1b016323417512ff Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Tue, 16 Jul 2024 22:43:32 +0200 Subject: [PATCH 3/6] Use the biggest adjustment Replace GOT symbols with ABSOLUTE --- gcc/config/aarch64/aarch64-coff.h | 11 +++++------ gcc/config/aarch64/aarch64.cc | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h index 3afd26506cf..55da023921e 100644 --- a/gcc/config/aarch64/aarch64-coff.h +++ b/gcc/config/aarch64/aarch64-coff.h @@ -65,12 +65,11 @@ #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGNMENT) \ { \ - unsigned HOST_WIDE_INT rounded = SIZE; \ - if (SIZE == 0) \ - rounded = 1; \ - rounded += (ALIGNMENT / BITS_PER_UNIT) - 1; \ - rounded = (rounded / (ALIGNMENT / BITS_PER_UNIT) \ - * ((ALIGNMENT) / BITS_PER_UNIT)); \ + unsigned HOST_WIDE_INT rounded = MAX((SIZE), 1); \ + unsigned HOST_WIDE_INT alignment = MAX((ALIGNMENT), BIGGEST_ALIGNMENT); \ + rounded += (alignment / BITS_PER_UNIT) - 1; \ + rounded = (rounded / (alignment / BITS_PER_UNIT) \ + * (alignment / BITS_PER_UNIT)); \ ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, rounded); \ } diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index cc94a3fe959..19672a3ee3e 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -21035,7 +21035,7 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) if ((flag_pic || SYMBOL_REF_WEAK (x)) && !aarch64_symbol_binds_local_p (x)) return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC - ? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G; + ? SYMBOL_SMALL_ABSOLUTE : SYMBOL_SMALL_ABSOLUTE; /* Same reasoning as the tiny code model, but the offset cap here is 1MB, allowing +/-3.9GB for the offset to the symbol. */ From 47069d35ea8d25c417985cdea08d46383fb933c5 Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Thu, 18 Jul 2024 13:03:28 +0200 Subject: [PATCH 4/6] Refactor changes for excluding GOT Add a workaround for __main reference in mingw --- gcc/config/aarch64/aarch64.cc | 5 ++++- gcc/config/aarch64/cygming.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 19672a3ee3e..16ccd671faa 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -20908,6 +20908,9 @@ aarch64_tlsdesc_abi_id () static bool aarch64_symbol_binds_local_p (const_rtx x) { + if (TARGET_PECOFF) + return true; + return (SYMBOL_REF_DECL (x) ? targetm.binds_local_p (SYMBOL_REF_DECL (x)) : SYMBOL_REF_LOCAL_P (x)); @@ -21035,7 +21038,7 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) if ((flag_pic || SYMBOL_REF_WEAK (x)) && !aarch64_symbol_binds_local_p (x)) return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC - ? SYMBOL_SMALL_ABSOLUTE : SYMBOL_SMALL_ABSOLUTE; + ? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G; /* Same reasoning as the tiny code model, but the offset cap here is 1MB, allowing +/-3.9GB for the offset to the symbol. */ diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h index 274432b731f..87ca2ddbac5 100644 --- a/gcc/config/aarch64/cygming.h +++ b/gcc/config/aarch64/cygming.h @@ -295,7 +295,7 @@ do { \ #undef ASM_DECLARE_FUNCTION_NAME #define ASM_DECLARE_FUNCTION_NAME(STR, NAME, DECL) \ - mingw_pe_declare_function_type (STR, NAME, TREE_PUBLIC (DECL)); \ + mingw_pe_declare_function_type (STR, NAME, !strcmp((NAME), "__main") || TREE_PUBLIC (DECL)); \ aarch64_declare_function_name (STR, NAME, DECL) From 114b8e9e670393fb2f0d2579430e0399a7f1f36f Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Thu, 8 Aug 2024 08:58:49 +0200 Subject: [PATCH 5/6] Refactor after rebase --- gcc/config/aarch64/aarch64-coff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h index 55da023921e..e3703cd6220 100644 --- a/gcc/config/aarch64/aarch64-coff.h +++ b/gcc/config/aarch64/aarch64-coff.h @@ -69,7 +69,7 @@ unsigned HOST_WIDE_INT alignment = MAX((ALIGNMENT), BIGGEST_ALIGNMENT); \ rounded += (alignment / BITS_PER_UNIT) - 1; \ rounded = (rounded / (alignment / BITS_PER_UNIT) \ - * (alignment / BITS_PER_UNIT)); \ + * (alignment / BITS_PER_UNIT)); \ ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, rounded); \ } From 738070d908e7b14ce2c870ce98d37cfc52c52822 Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Thu, 8 Aug 2024 09:58:17 +0200 Subject: [PATCH 6/6] Reuse visibility attribute implementation from ix86 --- gcc/config/aarch64/aarch64.cc | 3 --- gcc/config/aarch64/cygming.h | 6 ++---- gcc/config/i386/cygming.h | 2 +- gcc/config/i386/i386-protos.h | 1 - gcc/config/mingw/winnt.cc | 2 +- gcc/config/mingw/winnt.h | 1 + 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 16ccd671faa..cc94a3fe959 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -20908,9 +20908,6 @@ aarch64_tlsdesc_abi_id () static bool aarch64_symbol_binds_local_p (const_rtx x) { - if (TARGET_PECOFF) - return true; - return (SYMBOL_REF_DECL (x) ? targetm.binds_local_p (SYMBOL_REF_DECL (x)) : SYMBOL_REF_LOCAL_P (x)); diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h index 87ca2ddbac5..125486bf56f 100644 --- a/gcc/config/aarch64/cygming.h +++ b/gcc/config/aarch64/cygming.h @@ -295,7 +295,7 @@ do { \ #undef ASM_DECLARE_FUNCTION_NAME #define ASM_DECLARE_FUNCTION_NAME(STR, NAME, DECL) \ - mingw_pe_declare_function_type (STR, NAME, !strcmp((NAME), "__main") || TREE_PUBLIC (DECL)); \ + mingw_pe_declare_function_type (STR, NAME, TREE_PUBLIC (DECL)); \ aarch64_declare_function_name (STR, NAME, DECL) @@ -319,8 +319,6 @@ do { \ #define HAVE_64BIT_POINTERS 1 -extern void i386_pe_assemble_visibility (tree, int); - /* Kludge because of missing PE-COFF support for early LTO debug. */ #undef TARGET_ASM_LTO_START #define TARGET_ASM_LTO_START mingw_pe_asm_lto_start @@ -328,7 +326,7 @@ extern void i386_pe_assemble_visibility (tree, int); #define TARGET_ASM_LTO_END mingw_pe_asm_lto_end #undef TARGET_ASM_ASSEMBLE_VISIBILITY -#define TARGET_ASM_ASSEMBLE_VISIBILITY i386_pe_assemble_visibility +#define TARGET_ASM_ASSEMBLE_VISIBILITY mingw_pe_assemble_visibility /* According to Windows x64 software convention, the maximum stack allocatable in the prologue is 4G - 8 bytes. Furthermore, there is a limited set of diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h index 49c3275f564..9929d1fc5a1 100644 --- a/gcc/config/i386/cygming.h +++ b/gcc/config/i386/cygming.h @@ -458,7 +458,7 @@ do { \ #define SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME i386_pe_mangle_decl_assembler_name #undef TARGET_ASM_ASSEMBLE_VISIBILITY -#define TARGET_ASM_ASSEMBLE_VISIBILITY i386_pe_assemble_visibility +#define TARGET_ASM_ASSEMBLE_VISIBILITY mingw_pe_assemble_visibility #undef SUB_TARGET_RECORD_STUB #define SUB_TARGET_RECORD_STUB(NAME, DECL) mingw_pe_record_stub((NAME), 0) diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 8db34cf3667..4e84450e987 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -319,7 +319,6 @@ extern void i386_pe_asm_output_aligned_decl_common (FILE *, tree, extern void i386_pe_start_function (FILE *, const char *, tree); extern void i386_pe_end_function (FILE *, const char *, tree); 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 *); diff --git a/gcc/config/mingw/winnt.cc b/gcc/config/mingw/winnt.cc index f3ffad2040b..4f0ae28ed1b 100644 --- a/gcc/config/mingw/winnt.cc +++ b/gcc/config/mingw/winnt.cc @@ -260,7 +260,7 @@ i386_pe_maybe_mangle_decl_assembler_name (tree decl, tree id) user-specified visibility attributes. */ void -i386_pe_assemble_visibility (tree decl, int) +mingw_pe_assemble_visibility (tree decl, int) { if (!decl || !lookup_attribute ("visibility", DECL_ATTRIBUTES (decl))) diff --git a/gcc/config/mingw/winnt.h b/gcc/config/mingw/winnt.h index 6d73e2df857..005ea412bcc 100644 --- a/gcc/config/mingw/winnt.h +++ b/gcc/config/mingw/winnt.h @@ -25,6 +25,7 @@ extern tree mingw_handle_selectany_attribute (tree *, tree, tree, int, bool *); extern void mingw_pe_asm_named_section (const char *, unsigned int, tree); extern void mingw_pe_asm_lto_start (void); extern void mingw_pe_asm_lto_end (void); +extern void mingw_pe_assemble_visibility (tree, int); extern void mingw_pe_declare_function_type (FILE *file, const char *name, int pub); extern void mingw_pe_encode_section_info (tree, rtx, int);