diff mbox series

[v2,5/9] aarch64: Multiple adjustments to support the SMALL code model correctly

Message ID DBBPR83MB061367C4E1A722E4C2E0D4DBF89E2@DBBPR83MB0613.EURPRD83.prod.outlook.com
State New
Headers show
Series SMALL code model fixes, optimization fixes, LTO and minimal C++ enablement | expand

Commit Message

Evgeny Karpov Sept. 6, 2024, 11:56 a.m. UTC
LOCAL_LABEL_PREFIX has been changed to help the assembly
compiler recognize local labels. Emitting locals has been
replaced with the .lcomm directive to declare uninitialized
data without defining an exact section. Functions and objects
were missing declarations. Binutils was not able to distinguish
static from external, or an object from a function.
mingw_pe_declare_object_type has been added to have type
information for relocation on AArch64, which is not the case
for ix86.

This fix relies on changes in binutils.
aarch64: Relocation fixes and LTO
https://sourceware.org/pipermail/binutils/2024-August/136481.html

gcc/ChangeLog:

	* config/aarch64/aarch64-coff.h (LOCAL_LABEL_PREFIX):
	Use "." as the local label prefix.
	(ASM_OUTPUT_ALIGNED_LOCAL): Remove.
	(ASM_OUTPUT_LOCAL): New.
	* config/aarch64/cygming.h (ASM_OUTPUT_EXTERNAL_LIBCALL):
	Update.
	(ASM_DECLARE_OBJECT_NAME): New.
	(ASM_DECLARE_FUNCTION_NAME): New.
	* config/i386/cygming.h (ASM_DECLARE_COLD_FUNCTION_NAME):
	Update.
	(ASM_OUTPUT_EXTERNAL_LIBCALL): Update.
	* config/mingw/winnt.cc (mingw_pe_declare_function_type):
	Rename into ...
	(mingw_pe_declare_type): ... this.
	(i386_pe_start_function): Update.
	* config/mingw/winnt.h (mingw_pe_declare_function_type):
	Rename into ...
	(mingw_pe_declare_type): ... this.
---
 gcc/config/aarch64/aarch64-coff.h | 22 ++++++----------------
 gcc/config/aarch64/cygming.h      | 18 +++++++++++++++++-
 gcc/config/i386/cygming.h         |  8 ++++----
 gcc/config/mingw/winnt.cc         | 18 +++++++++---------
 gcc/config/mingw/winnt.h          |  3 +--
 5 files changed, 37 insertions(+), 32 deletions(-)
diff mbox series

Patch

diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h
index 81fd9954f75..17f346fe540 100644
--- a/gcc/config/aarch64/aarch64-coff.h
+++ b/gcc/config/aarch64/aarch64-coff.h
@@ -20,9 +20,8 @@ 
 #ifndef GCC_AARCH64_COFF_H
 #define GCC_AARCH64_COFF_H
 
-#ifndef LOCAL_LABEL_PREFIX
-# define LOCAL_LABEL_PREFIX 	""
-#endif
+#undef LOCAL_LABEL_PREFIX
+#define LOCAL_LABEL_PREFIX  "."
 
 /* Using long long breaks -ansi and -std=c90, so these will need to be
    made conditional for an LLP64 ABI.  */
@@ -54,19 +53,10 @@ 
     }
 #endif
 
-/* Output a local common block.  /bin/as can't do this, so hack a
-   `.space' into the bss segment.  Note that this is *bad* practice,
-   which is guaranteed NOT to work since it doesn't define STATIC
-   COMMON space but merely STATIC BSS space.  */
-#ifndef ASM_OUTPUT_ALIGNED_LOCAL
-# define ASM_OUTPUT_ALIGNED_LOCAL(STREAM, NAME, SIZE, ALIGN)		\
-    {									\
-      switch_to_section (bss_section);					\
-      ASM_OUTPUT_ALIGN (STREAM, floor_log2 (ALIGN / BITS_PER_UNIT));	\
-      ASM_OUTPUT_LABEL (STREAM, NAME);					\
-      fprintf (STREAM, "\t.space\t%d\n", (int)(SIZE));			\
-    }
-#endif
+#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)  \
+( fputs (".lcomm ", (FILE)),			\
+  assemble_name ((FILE), (NAME)),		\
+  fprintf ((FILE), ",%lu\n", (ROUNDED)))
 
 #define ASM_OUTPUT_SKIP(STREAM, NBYTES) 	\
   fprintf (STREAM, "\t.space\t%d  // skip\n", (int) (NBYTES))
diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h
index e4ceab82b9e..0e484a84ba9 100644
--- a/gcc/config/aarch64/cygming.h
+++ b/gcc/config/aarch64/cygming.h
@@ -78,7 +78,7 @@  still needed for compilation.  */
 
 /* 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)
+  mingw_pe_declare_type (FILE, XSTR (FUN, 0), 1, 1)
 
 /* Use section relative relocations for debugging offsets.  Unlike
    other targets that fake this by putting the section VMA at 0, PE
@@ -213,6 +213,22 @@  still needed for compilation.  */
 
 #define SUPPORTS_ONE_ONLY 1
 
+#undef ASM_DECLARE_OBJECT_NAME
+#define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL)			\
+  do {									\
+    mingw_pe_declare_type (STREAM, NAME, TREE_PUBLIC (DECL), 0);	\
+    ASM_OUTPUT_LABEL ((STREAM), (NAME));				\
+  } while (0)
+
+
+#undef ASM_DECLARE_FUNCTION_NAME
+#define ASM_DECLARE_FUNCTION_NAME(STREAM, NAME, DECL)			\
+  do {									\
+    mingw_pe_declare_type (STREAM, NAME, TREE_PUBLIC (DECL), 1);	\
+    aarch64_declare_function_name (STREAM, NAME, DECL);			\
+  } while (0)
+
+
 /* Define this to be nonzero if static stack checking is supported.  */
 #define STACK_CHECK_STATIC_BUILTIN 1
 
diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
index 1633017eff6..4c3d925e8b3 100644
--- a/gcc/config/i386/cygming.h
+++ b/gcc/config/i386/cygming.h
@@ -309,7 +309,7 @@  do {						\
 #define ASM_DECLARE_COLD_FUNCTION_NAME(FILE, NAME, DECL)	\
   do								\
     {								\
-      mingw_pe_declare_function_type (FILE, NAME, 0);		\
+      mingw_pe_declare_type (FILE, NAME, 0, 1);		\
       i386_pe_seh_cold_init (FILE, NAME);			\
       ASM_OUTPUT_LABEL (FILE, NAME);				\
     }								\
@@ -335,7 +335,7 @@  do {						\
 
 /* 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)
+  mingw_pe_declare_type (FILE, XSTR (FUN, 0), 1, 1)
 
 /* This says out to put a global symbol in the BSS section.  */
 #undef ASM_OUTPUT_ALIGNED_BSS
@@ -420,8 +420,8 @@  do {						\
 	= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL));		\
       mingw_pe_maybe_record_exported_symbol (DECL, alias, 0);		\
       if (TREE_CODE (DECL) == FUNCTION_DECL)				\
-	mingw_pe_declare_function_type (STREAM, alias,			\
-				       TREE_PUBLIC (DECL));		\
+	mingw_pe_declare_type (STREAM, alias,			\
+				       TREE_PUBLIC (DECL), 1);		\
       ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET));	\
     } while (0)
 
diff --git a/gcc/config/mingw/winnt.cc b/gcc/config/mingw/winnt.cc
index 1e2ec53e841..f93e80a1d52 100644
--- a/gcc/config/mingw/winnt.cc
+++ b/gcc/config/mingw/winnt.cc
@@ -575,20 +575,20 @@  i386_pe_asm_output_aligned_decl_common (FILE *stream, tree decl,
 
 #include "gsyms.h"
 
-/* Mark a function appropriately.  This should only be called for
+/* Mark a function or an object appropriately.  This should only be called for
    functions for which we are not emitting COFF debugging information.
    FILE is the assembler output file, NAME is the name of the
    function, and PUB is nonzero if the function is globally
    visible.  */
 
 void
-mingw_pe_declare_function_type (FILE *file, const char *name, int pub)
+mingw_pe_declare_type (FILE *file, const char *name, bool pub, bool func)
 {
   fprintf (file, "\t.def\t");
   assemble_name (file, name);
   fprintf (file, ";\t.scl\t%d;\t.type\t%d;\t.endef\n",
 	   pub ? (int) C_EXT : (int) C_STAT,
-	   (int) DT_FCN << N_BTSHFT);
+	  (int) (func ? DT_FCN : DT_NON) << N_BTSHFT);
 }
 
 /* Keep a list of external functions.  */
@@ -771,12 +771,12 @@  mingw_pe_file_end (void)
 	     the real function so that an (unused) import is created.  */
 	  const char *realsym = i386_find_on_wrapper_list (p->name);
 	  if (realsym)
-	    mingw_pe_declare_function_type (asm_out_file,
-		concat ("__real_", realsym, NULL), TREE_PUBLIC (decl));
+	    mingw_pe_declare_type (asm_out_file,
+		concat ("__real_", realsym, NULL), TREE_PUBLIC (decl), 1);
 #endif /* CXX_WRAP_SPEC_LIST */
 	  TREE_ASM_WRITTEN (decl) = 1;
-	  mingw_pe_declare_function_type (asm_out_file, p->name,
-					 TREE_PUBLIC (decl));
+	  mingw_pe_declare_type (asm_out_file, p->name,
+					 TREE_PUBLIC (decl), 1);
 	}
     }
 
@@ -815,7 +815,7 @@  mingw_pe_file_end (void)
 #ifdef ASM_WEAKEN_LABEL
 	      ASM_WEAKEN_LABEL (asm_out_file, name);
 #endif
-	      mingw_pe_declare_function_type (asm_out_file, name, 1);
+	      mingw_pe_declare_type (asm_out_file, name, 1, 1);
 	    }
 
 	  fprintf (asm_out_file, "\t.section\t.rdata$%s, \"dr\"\n"
@@ -1374,7 +1374,7 @@  void
 i386_pe_start_function (FILE *f, const char *name, tree decl)
 {
   mingw_pe_maybe_record_exported_symbol (decl, name, 0);
-  mingw_pe_declare_function_type (f, name, TREE_PUBLIC (decl));
+  mingw_pe_declare_type (f, name, TREE_PUBLIC (decl), 1);
   /* In case section was altered by debugging output.  */
   if (decl != NULL_TREE)
     switch_to_section (function_section (decl));
diff --git a/gcc/config/mingw/winnt.h b/gcc/config/mingw/winnt.h
index a21a36b7e5d..14bff19e697 100644
--- a/gcc/config/mingw/winnt.h
+++ b/gcc/config/mingw/winnt.h
@@ -23,8 +23,7 @@  http://www.gnu.org/licenses/.  */
 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_declare_function_type (FILE *file, const char *name,
-	int pub);
+extern void mingw_pe_declare_type (FILE *, const char *, bool, bool);
 extern void mingw_pe_encode_section_info (tree, rtx, int);
 extern void mingw_pe_file_end (void);
 extern void mingw_pe_maybe_record_exported_symbol (tree, const char *, int);