]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
MIPS: Fix the issue with the '-fpatchable-function-entry=' feature.
authorChengLulu <chenglulu@loongson.cn>
Tue, 9 Sep 2025 11:19:04 +0000 (19:19 +0800)
committerYunQiang Su <yunqiang@isrc.iscas.ac.cn>
Sat, 27 Sep 2025 12:55:07 +0000 (20:55 +0800)
PR target/99217

gcc/ChangeLog:

* config/mips/mips.cc (mips_start_function_definition):
Implements the functionality of '-fpatchable-function-entry='.
(mips_print_patchable_function_entry): Define empty function.
(TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY): Define macro.

gcc/testsuite/ChangeLog:

* gcc.target/mips/pr99217.c: New test.

gcc/config/mips/mips.cc
gcc/testsuite/gcc.target/mips/pr99217.c [new file with mode: 0644]

index fa9ac079a01dace612d7665e3fffde921ea64388..1fa7ba8451c50f293f3c6f2f9d4ae5b1e0e08d87 100644 (file)
@@ -7476,6 +7476,9 @@ static void
 mips_start_function_definition (const char *name, bool mips16_p,
                                tree decl ATTRIBUTE_UNUSED)
 {
+  unsigned HOST_WIDE_INT patch_area_size = crtl->patch_area_size;
+  unsigned HOST_WIDE_INT patch_area_entry = crtl->patch_area_entry;
+
   if (mips16_p)
     fprintf (asm_out_file, "\t.set\tmips16\n");
   else
@@ -7488,6 +7491,10 @@ mips_start_function_definition (const char *name, bool mips16_p,
     fprintf (asm_out_file, "\t.set\tnomicromips\n");
 #endif
 
+  /* Emit the patching area before the entry label, if any.  */
+  if (patch_area_entry > 0)
+    default_print_patchable_function_entry (asm_out_file,
+                                           patch_area_entry, true);
   if (!flag_inhibit_size_directive)
     {
       fputs ("\t.ent\t", asm_out_file);
@@ -7499,6 +7506,13 @@ mips_start_function_definition (const char *name, bool mips16_p,
 
   /* Start the definition proper.  */
   ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, name, decl);
+
+  /* And the area after the label.  Record it if we haven't done so yet.  */
+  if (patch_area_size > patch_area_entry)
+    default_print_patchable_function_entry (asm_out_file,
+                                           patch_area_size
+                                           - patch_area_entry,
+                                           patch_area_entry == 0);
 }
 
 /* End a function definition started by mips_start_function_definition.  */
@@ -23350,6 +23364,21 @@ mips_bit_clear_p (enum machine_mode mode, unsigned HOST_WIDE_INT m)
   return false;
 }
 
+/* define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY */
+
+/* The MIPS function start is implemented in the prologue function.
+   TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY needs to be inserted
+   before or after the function name, so this function does not
+   use a public implementation. This function is implemented in
+   mips_start_function_definition. */
+
+void
+mips_print_patchable_function_entry (FILE *file ATTRIBUTE_UNUSED,
+                                    unsigned HOST_WIDE_INT
+                                    patch_area_size ATTRIBUTE_UNUSED,
+                                    bool record_p ATTRIBUTE_UNUSED)
+{}
+
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_ALIGNED_HI_OP
 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
@@ -23663,6 +23692,10 @@ mips_bit_clear_p (enum machine_mode mode, unsigned HOST_WIDE_INT m)
 #undef TARGET_DOCUMENTATION_NAME
 #define TARGET_DOCUMENTATION_NAME "MIPS"
 
+#undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
+#define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY \
+mips_print_patchable_function_entry
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 #include "gt-mips.h"
diff --git a/gcc/testsuite/gcc.target/mips/pr99217.c b/gcc/testsuite/gcc.target/mips/pr99217.c
new file mode 100644 (file)
index 0000000..ac1e27b
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fpatchable-function-entry=1" } */
+/* { dg-final { scan-assembler "foo:\n.*.LPFE0:\n\t.set\tnoreorder\n\tnop\n\t.set\treorder" } } */
+
+/* Test the placement of the .LPFE0 label.  */
+
+void
+foo (void)
+{
+}