public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use the section flag 'o' for __patchable_function_entries
@ 2020-02-07  2:57 H.J. Lu
  2020-10-02 13:00 ` PING: " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-02-07  2:57 UTC (permalink / raw)
  To: gcc-patches

This commit in GNU binutils 2.35:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e

added the section flag 'o' to .section directive:

.section __patchable_function_entries,"awo",@progbits,foo

which specifies the symbol name which the section references.  Assembler
creates a unique __patchable_function_entries section with the section,
where foo is defined, as its linked-to section.  Linker keeps a section
if its linked-to section is kept during garbage collection.

This patch checks assembler support for the section flag 'o' and uses
it to implement __patchable_function_entries section.  Since Solaris may
use GNU assembler with Solairs ld.  Even if GNU assembler supports the
section flag 'o', it doesn't mean that Solairs ld supports it.  This
feature is disabled for Solairs targets.

gcc/

	PR middle-end/93195
	PR middle-end/93197
	* configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
	the assembler supports the section flag 'o' for specifying
	section with link-order.
	* dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
	to targetm.asm_out.named_section.
	* config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
	* output.h (SECTION2_LINK_ORDER): New.
	(switch_to_section): Add an unsigned int argument.
	(default_no_named_section): Likewise.
	(default_elf_asm_named_section): Likewise.
	* target.def (asm_out.named_section): Likewise.
	* targhooks.c (default_print_patchable_function_entry): Pass
	current_function_decl to get_section and SECTION2_LINK_ORDER
	to switch_to_section.
	* varasm.c (default_no_named_section): Add an unsigned int
	argument.
	(default_elf_asm_named_section): Add an unsigned int argument,
	flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
	supports it.
	(switch_to_section): Add an unsigned int argument and pass it
	to targetm.asm_out.named_section.
	(handle_vtv_comdat_section): Pass 0 to
	targetm.asm_out.named_section.
	* config.in: Regenerated.
	* configure: Likewise.
	* doc/tm.texi: Likewise.

gcc/testsuite/

	PR middle-end/93195
	* g++.dg/pr93195a.C: New test.
	* g++.dg/pr93195b.C: Likewise.
	* lib/target-supports.exp
	(check_effective_target_o_flag_in_section): New proc.
---
 gcc/config.in                         |  6 ++++
 gcc/config/sol2.c                     |  3 +-
 gcc/configure                         | 52 +++++++++++++++++++++++++++
 gcc/configure.ac                      | 22 ++++++++++++
 gcc/doc/tm.texi                       |  5 +--
 gcc/dwarf2out.c                       |  4 +--
 gcc/output.h                          | 11 ++++--
 gcc/target.def                        |  5 +--
 gcc/targhooks.c                       |  4 ++-
 gcc/testsuite/g++.dg/pr93195a.C       | 27 ++++++++++++++
 gcc/testsuite/g++.dg/pr93195b.C       | 14 ++++++++
 gcc/testsuite/lib/target-supports.exp | 40 +++++++++++++++++++++
 gcc/varasm.c                          | 25 ++++++++++---
 13 files changed, 202 insertions(+), 16 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr93195a.C
 create mode 100644 gcc/testsuite/g++.dg/pr93195b.C

diff --git a/gcc/config.in b/gcc/config.in
index 48292861842..d1ecc5b15a6 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1313,6 +1313,12 @@
 #endif
 
 
+/* Define if your assembler supports 'o' flag in .section directive. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GAS_SECTION_LINK_ORDER
+#endif
+
+
 /* Define 0/1 if your assembler supports marking sections with SHF_MERGE flag.
    */
 #ifndef USED_FOR_TARGET
diff --git a/gcc/config/sol2.c b/gcc/config/sol2.c
index cf9d9f1f684..62bbdec2f97 100644
--- a/gcc/config/sol2.c
+++ b/gcc/config/sol2.c
@@ -224,7 +224,8 @@ solaris_elf_asm_comdat_section (const char *name, unsigned int flags, tree decl)
      emits this as a regular section.  Emit section before .group
      directive since Sun as treats undeclared sections as @progbits,
      which conflicts with .bss* sections which are @nobits.  */
-  targetm.asm_out.named_section (section, flags & ~SECTION_LINKONCE, decl);
+  targetm.asm_out.named_section (section, flags & ~SECTION_LINKONCE,
+				 0, decl);
   
   /* Sun as separates declaration of a group section and of the group
      itself, using the .group directive and the #comdat flag.  */
diff --git a/gcc/configure b/gcc/configure
index 5fa565a40a4..a7315e33a62 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -24185,6 +24185,58 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+# Test if the assembler supports the section flag 'o' for specifying
+# section with link-order.
+case "${target}" in
+  # Solaris may use GNU assembler with Solairs ld.  Even if GNU
+  # assembler supports the section flag 'o', it doesn't mean that
+  # Solairs ld supports it.
+  *-*-solaris2*)
+    gcc_cv_as_section_link_order=no
+    ;;
+  *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for section 'o' flag" >&5
+$as_echo_n "checking assembler for section 'o' flag... " >&6; }
+if ${gcc_cv_as_section_link_order+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_section_link_order=no
+    if test $in_tree_gas = yes; then
+    if test $gcc_cv_gas_vers -ge `expr \( \( 2 \* 1000 \) + 35 \) \* 1000 + 0`
+  then gcc_cv_as_section_link_order=yes
+fi
+  elif test x$gcc_cv_as != x; then
+    $as_echo '.section .foo,"a"
+.byte 0
+.section __patchable_function_entries,"awo",%progbits,.foo
+.byte 0' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags --fatal-warnings -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+	gcc_cv_as_section_link_order=yes
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_section_link_order" >&5
+$as_echo "$gcc_cv_as_section_link_order" >&6; }
+
+
+    ;;
+esac
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_GAS_SECTION_LINK_ORDER `if test $gcc_cv_as_section_link_order = yes; then echo 1; else echo 0; fi`
+_ACEOF
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for section merging support" >&5
 $as_echo_n "checking assembler for section merging support... " >&6; }
 if ${gcc_cv_as_shf_merge+:} false; then :
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 671b9a67d81..5619736ee0c 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3199,6 +3199,28 @@ AC_DEFINE_UNQUOTED(HAVE_GAS_SECTION_EXCLUDE,
   [`if test $gcc_cv_as_section_exclude_e = yes || test $gcc_cv_as_section_exclude_hash = yes; then echo 1; else echo 0; fi`],
 [Define if your assembler supports specifying the exclude section flag.])
 
+# Test if the assembler supports the section flag 'o' for specifying
+# section with link-order.
+case "${target}" in
+  # Solaris may use GNU assembler with Solairs ld.  Even if GNU
+  # assembler supports the section flag 'o', it doesn't mean that
+  # Solairs ld supports it.
+  *-*-solaris2*)
+    gcc_cv_as_section_link_order=no
+    ;;
+  *)
+    gcc_GAS_CHECK_FEATURE([section 'o' flag], gcc_cv_as_section_link_order,
+      [2,35,0], [--fatal-warnings],
+      [.section .foo,"a"
+.byte 0
+.section __patchable_function_entries,"awo",%progbits,.foo
+.byte 0])
+    ;;
+esac
+AC_DEFINE_UNQUOTED(HAVE_GAS_SECTION_LINK_ORDER,
+  [`if test $gcc_cv_as_section_link_order = yes; then echo 1; else echo 0; fi`],
+  [Define if your assembler supports 'o' flag in .section directive.])
+
 gcc_GAS_CHECK_FEATURE(section merging support, gcc_cv_as_shf_merge,
  [elf,2,12,0], [--fatal-warnings],
  [.section .rodata.str, "aMS", @progbits, 1])
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 19985adac3e..f50ce812a1d 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -8003,9 +8003,10 @@ the assembler source.  So you can use it to canonicalize the format
 of the filename using this macro.
 @end defmac
 
-@deftypefn {Target Hook} void TARGET_ASM_NAMED_SECTION (const char *@var{name}, unsigned int @var{flags}, tree @var{decl})
+@deftypefn {Target Hook} void TARGET_ASM_NAMED_SECTION (const char *@var{name}, unsigned int @var{flags}, unsigned int @var{flags2}, tree @var{decl})
 Output assembly directives to switch to section @var{name}.  The section
-should have attributes as specified by @var{flags}, which is a bit mask
+should have attributes as specified by @var{flags} and @var{flags2},
+which are bit masks
 of the @code{SECTION_*} flags defined in @file{output.h}.  If @var{decl}
 is non-NULL, it is the @code{VAR_DECL} or @code{FUNCTION_DECL} with which
 this section is associated.
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fe46c7e1eee..1b0dd2364bb 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -11303,7 +11303,7 @@ output_comdat_type_unit (comdat_type_node *node,
   comdat_key = get_identifier (tmp);
   targetm.asm_out.named_section (secname,
                                  SECTION_DEBUG | SECTION_LINKONCE,
-                                 comdat_key);
+				 0, comdat_key);
 #else
   tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
   sprintf (tmp, (dwarf_version >= 5
@@ -28511,7 +28511,7 @@ output_macinfo (const char *debug_line_label, bool early_lto_debug)
 					 | SECTION_LINKONCE
 					 | (early_lto_debug
 					    ? SECTION_EXCLUDE : 0),
-					 comdat_key);
+					 0, comdat_key);
 	  ASM_GENERATE_INTERNAL_LABEL (label,
 				       DEBUG_MACRO_SECTION_LABEL,
 				       ref->lineno + macinfo_label_base);
diff --git a/gcc/output.h b/gcc/output.h
index eb253c50329..becbeadc8ea 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -396,6 +396,9 @@ extern void no_asm_to_stream (FILE *);
    to declare the object.  */
 #define SECTION_NOSWITCH 0x400000
 
+/* Flags2 controlling properties of a section.  */
+#define SECTION2_LINK_ORDER	0x00000001 /* section needs link-order.  */
+
 /* A helper function for default_elf_select_section and
    default_elf_unique_section.  Categorizes the DECL.  */
 
@@ -542,7 +545,7 @@ extern void switch_to_other_text_partition (void);
 extern section *get_cdtor_priority_section (int, bool);
 
 extern bool unlikely_text_section_p (section *);
-extern void switch_to_section (section *);
+extern void switch_to_section (section *, unsigned int = 0);
 extern void output_section_asm_op (const void *);
 
 extern void record_tm_clone_pair (tree, tree);
@@ -557,8 +560,10 @@ extern unsigned int default_section_type_flags (tree, const char *, int);
 extern bool have_global_bss_p (void);
 extern bool bss_initializer_p (const_tree, bool = false);
 
-extern void default_no_named_section (const char *, unsigned int, tree);
-extern void default_elf_asm_named_section (const char *, unsigned int, tree);
+extern void default_no_named_section (const char *, unsigned int,
+				      unsigned int, tree);
+extern void default_elf_asm_named_section (const char *, unsigned int,
+					   unsigned int, tree);
 extern enum section_category categorize_decl_for_section (const_tree, int);
 extern void default_coff_asm_named_section (const char *, unsigned int, tree);
 extern void default_pe_asm_named_section (const char *, unsigned int, tree);
diff --git a/gcc/target.def b/gcc/target.def
index b5e82ff826e..97d53c909cf 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -414,11 +414,12 @@ described below.",
 DEFHOOK
 (named_section,
  "Output assembly directives to switch to section @var{name}.  The section\n\
-should have attributes as specified by @var{flags}, which is a bit mask\n\
+should have attributes as specified by @var{flags} and @var{flags2},\n\
+which are bit masks\n\
 of the @code{SECTION_*} flags defined in @file{output.h}.  If @var{decl}\n\
 is non-NULL, it is the @code{VAR_DECL} or @code{FUNCTION_DECL} with which\n\
 this section is associated.",
- void, (const char *name, unsigned int flags, tree decl),
+ void, (const char *name, unsigned int flags, unsigned int flags2, tree decl),
  default_no_named_section)
 
 /* Tell assembler what section attributes to assign this elf section
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 7cb04f30bdb..0bae7bad1d4 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1811,7 +1811,9 @@ default_print_patchable_function_entry (FILE *file,
       ASM_GENERATE_INTERNAL_LABEL (buf, "LPFE", patch_area_number);
 
       switch_to_section (get_section ("__patchable_function_entries",
-				      SECTION_WRITE | SECTION_RELRO, NULL));
+				      SECTION_WRITE | SECTION_RELRO,
+				      current_function_decl),
+			 SECTION2_LINK_ORDER);
       assemble_align (POINTER_SIZE);
       fputs (asm_op, file);
       assemble_name_raw (file, buf);
diff --git a/gcc/testsuite/g++.dg/pr93195a.C b/gcc/testsuite/g++.dg/pr93195a.C
new file mode 100644
index 00000000000..26d265da74e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr93195a.C
@@ -0,0 +1,27 @@
+/* { dg-do link { target { ! { nvptx*-*-* visium-*-* } } } } */
+// { dg-require-effective-target o_flag_in_section }
+/* { dg-options "-O0 -fpatchable-function-entry=1" } */
+/* { dg-additional-options "-fno-pie" { target sparc*-*-* } } */
+/* { dg-additional-sources pr93195b.C } */
+
+extern void bar1 (void);
+
+inline void
+foo (void)
+{
+}
+
+void
+bar (void)
+{
+  foo ();
+  bar1 ();
+}
+
+int
+main ()
+{
+  bar ();
+  return 0;
+}
+
diff --git a/gcc/testsuite/g++.dg/pr93195b.C b/gcc/testsuite/g++.dg/pr93195b.C
new file mode 100644
index 00000000000..303d8588c0f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr93195b.C
@@ -0,0 +1,14 @@
+/* { dg-do compile { target { ! { nvptx*-*-* visium-*-* } } } } */
+/* { dg-options "-O0 -fpatchable-function-entry=1" } */
+/* { dg-additional-options "-fno-pie" { target sparc*-*-* } } */
+
+inline void
+foo (void)
+{
+}
+
+void
+bar1 (void)
+{
+  foo ();
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index d3b2798df3e..ca3835204eb 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -9872,3 +9872,43 @@ proc check_effective_target_indirect_calls { } {
   }
   return 1
 }
+
+# Return 1 if this target supports 'o' flag in .section directive, 0
+# otherwise.  Cache the result.
+
+proc check_effective_target_o_flag_in_section { } {
+    global tool
+    global GCC_UNDER_TEST
+
+    # Need auto-host.h to check linker support.
+    if { ![file exists ../../auto-host.h ] } {
+	return 0
+    }
+
+    return [check_cached_effective_target o_flag_in_section {
+
+	set src pie[pid].c
+	set obj pie[pid].o
+
+	set f [open $src "w"]
+	puts $f "#include \"../../auto-host.h\""
+	puts $f "#if HAVE_GAS_SECTION_LINK_ORDER == 0"
+	puts $f "# error Assembler does not support 'o' flag in .section directive."
+	puts $f "#endif"
+	close $f
+
+	verbose "check_effective_target_o_flag_in_section compiling testfile $src" 2
+	set lines [${tool}_target_compile $src $obj object ""]
+
+	file delete $src
+	file delete $obj
+
+	if [string match "" $lines] then {
+	    verbose "check_effective_target_o_flag_in_section testfile compilation passed" 2
+	    return 1
+	} else {
+	    verbose "check_effective_target_o_flag_in_section testfile compilation failed" 2
+	    return 0
+	}
+    }]
+}
diff --git a/gcc/varasm.c b/gcc/varasm.c
index dc6da6c0b5b..8c9dc9dd476 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -6507,6 +6507,7 @@ have_global_bss_p (void)
 void
 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
 			  unsigned int flags ATTRIBUTE_UNUSED,
+			  unsigned int flags2 ATTRIBUTE_UNUSED,
 			  tree decl ATTRIBUTE_UNUSED)
 {
   /* Some object formats don't support named sections at all.  The
@@ -6520,7 +6521,7 @@ default_no_named_section (const char *name ATTRIBUTE_UNUSED,
 
 void
 default_elf_asm_named_section (const char *name, unsigned int flags,
-			       tree decl)
+			       unsigned int flags2, tree decl)
 {
   char flagchars[11], *f = flagchars;
   unsigned int numeric_value = 0;
@@ -6562,6 +6563,10 @@ default_elf_asm_named_section (const char *name, unsigned int flags,
 	*f++ = TLS_SECTION_ASM_FLAG;
       if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
 	*f++ = 'G';
+#if HAVE_GAS_SECTION_LINK_ORDER
+      if (flags2 & SECTION2_LINK_ORDER)
+	*f++ = 'o';
+#endif
 #ifdef MACH_DEP_SECTION_ASM_FLAG
       if (flags & SECTION_MACH_DEP)
 	*f++ = MACH_DEP_SECTION_ASM_FLAG;
@@ -6594,6 +6599,16 @@ default_elf_asm_named_section (const char *name, unsigned int flags,
 
       if (flags & SECTION_ENTSIZE)
 	fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
+#if HAVE_GAS_SECTION_LINK_ORDER
+      if (flags2 & SECTION2_LINK_ORDER)
+	{
+	  tree id = DECL_ASSEMBLER_NAME (decl);
+	  ultimate_transparent_alias_target (&id);
+	  const char *name = IDENTIFIER_POINTER (id);
+	  name = targetm.strip_name_encoding (name);
+	  fprintf (asm_out_file, ",%s", name);
+	}
+#endif
       if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
 	{
 	  if (TREE_CODE (decl) == IDENTIFIER_NODE)
@@ -7462,7 +7477,7 @@ output_section_asm_op (const void *directive)
    the current section is NEW_SECTION.  */
 
 void
-switch_to_section (section *new_section)
+switch_to_section (section *new_section, unsigned int flags2)
 {
   if (in_section == new_section)
     return;
@@ -7477,7 +7492,7 @@ switch_to_section (section *new_section)
     case SECTION_NAMED:
       targetm.asm_out.named_section (new_section->named.name,
 				     new_section->named.common.flags,
-				     new_section->named.decl);
+				     flags2, new_section->named.decl);
       break;
 
     case SECTION_UNNAMED:
@@ -8145,7 +8160,7 @@ handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
   targetm.asm_out.named_section (sect->named.name,
 				 sect->named.common.flags
 				 | SECTION_LINKONCE,
-				 DECL_NAME (decl));
+				 0, DECL_NAME (decl));
   in_section = sect;
 #else
   /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
@@ -8171,7 +8186,7 @@ handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
       targetm.asm_out.named_section (name,
 				     sect->named.common.flags
 				     | SECTION_LINKONCE,
-				     DECL_NAME (decl));
+				     0, DECL_NAME (decl));
       in_section = sect;
     }
   else
-- 
2.24.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING: [PATCH] Use the section flag 'o' for __patchable_function_entries
  2020-02-07  2:57 [PATCH] Use the section flag 'o' for __patchable_function_entries H.J. Lu
@ 2020-10-02 13:00 ` H.J. Lu
  2020-10-23 12:41   ` PING^2 " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-10-02 13:00 UTC (permalink / raw)
  To: GCC Patches, Jeffrey Law, Jakub Jelinek, Richard Biener,
	Richard Sandiford

On Thu, Feb 6, 2020 at 6:57 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> This commit in GNU binutils 2.35:
>
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e
>
> added the section flag 'o' to .section directive:
>
> .section __patchable_function_entries,"awo",@progbits,foo
>
> which specifies the symbol name which the section references.  Assembler
> creates a unique __patchable_function_entries section with the section,
> where foo is defined, as its linked-to section.  Linker keeps a section
> if its linked-to section is kept during garbage collection.
>
> This patch checks assembler support for the section flag 'o' and uses
> it to implement __patchable_function_entries section.  Since Solaris may
> use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> section flag 'o', it doesn't mean that Solairs ld supports it.  This
> feature is disabled for Solairs targets.
>
> gcc/
>
>         PR middle-end/93195
>         PR middle-end/93197
>         * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
>         the assembler supports the section flag 'o' for specifying
>         section with link-order.
>         * dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
>         to targetm.asm_out.named_section.
>         * config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
>         * output.h (SECTION2_LINK_ORDER): New.
>         (switch_to_section): Add an unsigned int argument.
>         (default_no_named_section): Likewise.
>         (default_elf_asm_named_section): Likewise.
>         * target.def (asm_out.named_section): Likewise.
>         * targhooks.c (default_print_patchable_function_entry): Pass
>         current_function_decl to get_section and SECTION2_LINK_ORDER
>         to switch_to_section.
>         * varasm.c (default_no_named_section): Add an unsigned int
>         argument.
>         (default_elf_asm_named_section): Add an unsigned int argument,
>         flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
>         supports it.
>         (switch_to_section): Add an unsigned int argument and pass it
>         to targetm.asm_out.named_section.
>         (handle_vtv_comdat_section): Pass 0 to
>         targetm.asm_out.named_section.
>         * config.in: Regenerated.
>         * configure: Likewise.
>         * doc/tm.texi: Likewise.
>
> gcc/testsuite/
>
>         PR middle-end/93195
>         * g++.dg/pr93195a.C: New test.
>         * g++.dg/pr93195b.C: Likewise.
>         * lib/target-supports.exp
>         (check_effective_target_o_flag_in_section): New proc.

PING

https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html

-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING^2 [PATCH] Use the section flag 'o' for __patchable_function_entries
  2020-10-02 13:00 ` PING: " H.J. Lu
@ 2020-10-23 12:41   ` H.J. Lu
  2020-10-31 12:01     ` PING^3 " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-10-23 12:41 UTC (permalink / raw)
  To: GCC Patches, Jeffrey Law, Jakub Jelinek, Richard Biener,
	Richard Sandiford

On Fri, Oct 2, 2020 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Feb 6, 2020 at 6:57 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > This commit in GNU binutils 2.35:
> >
> > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e
> >
> > added the section flag 'o' to .section directive:
> >
> > .section __patchable_function_entries,"awo",@progbits,foo
> >
> > which specifies the symbol name which the section references.  Assembler
> > creates a unique __patchable_function_entries section with the section,
> > where foo is defined, as its linked-to section.  Linker keeps a section
> > if its linked-to section is kept during garbage collection.
> >
> > This patch checks assembler support for the section flag 'o' and uses
> > it to implement __patchable_function_entries section.  Since Solaris may
> > use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> > section flag 'o', it doesn't mean that Solairs ld supports it.  This
> > feature is disabled for Solairs targets.
> >
> > gcc/
> >
> >         PR middle-end/93195
> >         PR middle-end/93197
> >         * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
> >         the assembler supports the section flag 'o' for specifying
> >         section with link-order.
> >         * dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
> >         to targetm.asm_out.named_section.
> >         * config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
> >         * output.h (SECTION2_LINK_ORDER): New.
> >         (switch_to_section): Add an unsigned int argument.
> >         (default_no_named_section): Likewise.
> >         (default_elf_asm_named_section): Likewise.
> >         * target.def (asm_out.named_section): Likewise.
> >         * targhooks.c (default_print_patchable_function_entry): Pass
> >         current_function_decl to get_section and SECTION2_LINK_ORDER
> >         to switch_to_section.
> >         * varasm.c (default_no_named_section): Add an unsigned int
> >         argument.
> >         (default_elf_asm_named_section): Add an unsigned int argument,
> >         flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
> >         supports it.
> >         (switch_to_section): Add an unsigned int argument and pass it
> >         to targetm.asm_out.named_section.
> >         (handle_vtv_comdat_section): Pass 0 to
> >         targetm.asm_out.named_section.
> >         * config.in: Regenerated.
> >         * configure: Likewise.
> >         * doc/tm.texi: Likewise.
> >
> > gcc/testsuite/
> >
> >         PR middle-end/93195
> >         * g++.dg/pr93195a.C: New test.
> >         * g++.dg/pr93195b.C: Likewise.
> >         * lib/target-supports.exp
> >         (check_effective_target_o_flag_in_section): New proc.
>
> PING
>
> https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html

PING.


-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING^3 [PATCH] Use the section flag 'o' for __patchable_function_entries
  2020-10-23 12:41   ` PING^2 " H.J. Lu
@ 2020-10-31 12:01     ` H.J. Lu
  2020-11-07 15:47       ` PING^4 " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-10-31 12:01 UTC (permalink / raw)
  To: GCC Patches, Jeffrey Law, Jakub Jelinek, Richard Biener,
	Richard Sandiford

On Fri, Oct 23, 2020 at 5:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Oct 2, 2020 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Thu, Feb 6, 2020 at 6:57 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > This commit in GNU binutils 2.35:
> > >
> > > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e
> > >
> > > added the section flag 'o' to .section directive:
> > >
> > > .section __patchable_function_entries,"awo",@progbits,foo
> > >
> > > which specifies the symbol name which the section references.  Assembler
> > > creates a unique __patchable_function_entries section with the section,
> > > where foo is defined, as its linked-to section.  Linker keeps a section
> > > if its linked-to section is kept during garbage collection.
> > >
> > > This patch checks assembler support for the section flag 'o' and uses
> > > it to implement __patchable_function_entries section.  Since Solaris may
> > > use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> > > section flag 'o', it doesn't mean that Solairs ld supports it.  This
> > > feature is disabled for Solairs targets.
> > >
> > > gcc/
> > >
> > >         PR middle-end/93195
> > >         PR middle-end/93197
> > >         * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
> > >         the assembler supports the section flag 'o' for specifying
> > >         section with link-order.
> > >         * dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
> > >         to targetm.asm_out.named_section.
> > >         * config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
> > >         * output.h (SECTION2_LINK_ORDER): New.
> > >         (switch_to_section): Add an unsigned int argument.
> > >         (default_no_named_section): Likewise.
> > >         (default_elf_asm_named_section): Likewise.
> > >         * target.def (asm_out.named_section): Likewise.
> > >         * targhooks.c (default_print_patchable_function_entry): Pass
> > >         current_function_decl to get_section and SECTION2_LINK_ORDER
> > >         to switch_to_section.
> > >         * varasm.c (default_no_named_section): Add an unsigned int
> > >         argument.
> > >         (default_elf_asm_named_section): Add an unsigned int argument,
> > >         flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
> > >         supports it.
> > >         (switch_to_section): Add an unsigned int argument and pass it
> > >         to targetm.asm_out.named_section.
> > >         (handle_vtv_comdat_section): Pass 0 to
> > >         targetm.asm_out.named_section.
> > >         * config.in: Regenerated.
> > >         * configure: Likewise.
> > >         * doc/tm.texi: Likewise.
> > >
> > > gcc/testsuite/
> > >
> > >         PR middle-end/93195
> > >         * g++.dg/pr93195a.C: New test.
> > >         * g++.dg/pr93195b.C: Likewise.
> > >         * lib/target-supports.exp
> > >         (check_effective_target_o_flag_in_section): New proc.
> >
> > PING
> >
> > https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html
>
> PING.
>

PING.

-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING^4 [PATCH] Use the section flag 'o' for __patchable_function_entries
  2020-10-31 12:01     ` PING^3 " H.J. Lu
@ 2020-11-07 15:47       ` H.J. Lu
  2020-11-18 14:00         ` PING^5 " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-11-07 15:47 UTC (permalink / raw)
  To: GCC Patches, Jeffrey Law, Jakub Jelinek, Richard Biener,
	Richard Sandiford

On Sat, Oct 31, 2020 at 5:01 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Oct 23, 2020 at 5:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Fri, Oct 2, 2020 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Thu, Feb 6, 2020 at 6:57 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > >
> > > > This commit in GNU binutils 2.35:
> > > >
> > > > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e
> > > >
> > > > added the section flag 'o' to .section directive:
> > > >
> > > > .section __patchable_function_entries,"awo",@progbits,foo
> > > >
> > > > which specifies the symbol name which the section references.  Assembler
> > > > creates a unique __patchable_function_entries section with the section,
> > > > where foo is defined, as its linked-to section.  Linker keeps a section
> > > > if its linked-to section is kept during garbage collection.
> > > >
> > > > This patch checks assembler support for the section flag 'o' and uses
> > > > it to implement __patchable_function_entries section.  Since Solaris may
> > > > use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> > > > section flag 'o', it doesn't mean that Solairs ld supports it.  This
> > > > feature is disabled for Solairs targets.
> > > >
> > > > gcc/
> > > >
> > > >         PR middle-end/93195
> > > >         PR middle-end/93197
> > > >         * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
> > > >         the assembler supports the section flag 'o' for specifying
> > > >         section with link-order.
> > > >         * dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
> > > >         to targetm.asm_out.named_section.
> > > >         * config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
> > > >         * output.h (SECTION2_LINK_ORDER): New.
> > > >         (switch_to_section): Add an unsigned int argument.
> > > >         (default_no_named_section): Likewise.
> > > >         (default_elf_asm_named_section): Likewise.
> > > >         * target.def (asm_out.named_section): Likewise.
> > > >         * targhooks.c (default_print_patchable_function_entry): Pass
> > > >         current_function_decl to get_section and SECTION2_LINK_ORDER
> > > >         to switch_to_section.
> > > >         * varasm.c (default_no_named_section): Add an unsigned int
> > > >         argument.
> > > >         (default_elf_asm_named_section): Add an unsigned int argument,
> > > >         flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
> > > >         supports it.
> > > >         (switch_to_section): Add an unsigned int argument and pass it
> > > >         to targetm.asm_out.named_section.
> > > >         (handle_vtv_comdat_section): Pass 0 to
> > > >         targetm.asm_out.named_section.
> > > >         * config.in: Regenerated.
> > > >         * configure: Likewise.
> > > >         * doc/tm.texi: Likewise.
> > > >
> > > > gcc/testsuite/
> > > >
> > > >         PR middle-end/93195
> > > >         * g++.dg/pr93195a.C: New test.
> > > >         * g++.dg/pr93195b.C: Likewise.
> > > >         * lib/target-supports.exp
> > > >         (check_effective_target_o_flag_in_section): New proc.
> > >
> > > PING
> > >
> > > https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html
> >
> > PING.
> >
>
> PING.
>

PING.


-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING^5 [PATCH] Use the section flag 'o' for __patchable_function_entries
  2020-11-07 15:47       ` PING^4 " H.J. Lu
@ 2020-11-18 14:00         ` H.J. Lu
  2020-12-02  5:23           ` Jeff Law
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-11-18 14:00 UTC (permalink / raw)
  To: GCC Patches, Jeffrey Law, Jakub Jelinek, Richard Biener,
	Richard Sandiford

[-- Attachment #1: Type: text/plain, Size: 5302 bytes --]

On Sat, Nov 7, 2020 at 7:47 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Sat, Oct 31, 2020 at 5:01 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Fri, Oct 23, 2020 at 5:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Fri, Oct 2, 2020 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > >
> > > > On Thu, Feb 6, 2020 at 6:57 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > > >
> > > > > This commit in GNU binutils 2.35:
> > > > >
> > > > > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e
> > > > >
> > > > > added the section flag 'o' to .section directive:
> > > > >
> > > > > .section __patchable_function_entries,"awo",@progbits,foo
> > > > >
> > > > > which specifies the symbol name which the section references.  Assembler
> > > > > creates a unique __patchable_function_entries section with the section,
> > > > > where foo is defined, as its linked-to section.  Linker keeps a section
> > > > > if its linked-to section is kept during garbage collection.
> > > > >
> > > > > This patch checks assembler support for the section flag 'o' and uses
> > > > > it to implement __patchable_function_entries section.  Since Solaris may
> > > > > use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> > > > > section flag 'o', it doesn't mean that Solairs ld supports it.  This
> > > > > feature is disabled for Solairs targets.
> > > > >
> > > > > gcc/
> > > > >
> > > > >         PR middle-end/93195
> > > > >         PR middle-end/93197
> > > > >         * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
> > > > >         the assembler supports the section flag 'o' for specifying
> > > > >         section with link-order.
> > > > >         * dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
> > > > >         to targetm.asm_out.named_section.
> > > > >         * config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
> > > > >         * output.h (SECTION2_LINK_ORDER): New.
> > > > >         (switch_to_section): Add an unsigned int argument.
> > > > >         (default_no_named_section): Likewise.
> > > > >         (default_elf_asm_named_section): Likewise.
> > > > >         * target.def (asm_out.named_section): Likewise.
> > > > >         * targhooks.c (default_print_patchable_function_entry): Pass
> > > > >         current_function_decl to get_section and SECTION2_LINK_ORDER
> > > > >         to switch_to_section.
> > > > >         * varasm.c (default_no_named_section): Add an unsigned int
> > > > >         argument.
> > > > >         (default_elf_asm_named_section): Add an unsigned int argument,
> > > > >         flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
> > > > >         supports it.
> > > > >         (switch_to_section): Add an unsigned int argument and pass it
> > > > >         to targetm.asm_out.named_section.
> > > > >         (handle_vtv_comdat_section): Pass 0 to
> > > > >         targetm.asm_out.named_section.
> > > > >         * config.in: Regenerated.
> > > > >         * configure: Likewise.
> > > > >         * doc/tm.texi: Likewise.
> > > > >
> > > > > gcc/testsuite/
> > > > >
> > > > >         PR middle-end/93195
> > > > >         * g++.dg/pr93195a.C: New test.
> > > > >         * g++.dg/pr93195b.C: Likewise.
> > > > >         * lib/target-supports.exp
> > > > >         (check_effective_target_o_flag_in_section): New proc.
> > > >
> > > > PING
> > > >
> > > > https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html
> > >
> > > PING.
> > >
> >
> > PING.
> >
>
> PING.

Here is a simpler patch.  OK for master?

This commit in GNU binutils 2.35:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715
829eed0622616f6ae0182900de3e

added the section flag 'o' to .section directive:

.section __patchable_function_entries,"awo",@progbits,foo

which specifies the symbol name which the section references.  Assembler
creates a unique __patchable_function_entries section with the section,
where foo is defined, as its linked-to section.  Linker keeps a section
if its linked-to section is kept during garbage collection.

This patch checks assembler support for the section flag 'o' and uses
it to implement __patchable_function_entries section.  Since Solaris may
use GNU assembler with Solairs ld.  Even if GNU assembler supports the
section flag 'o', it doesn't mean that Solairs ld supports it.  This
feature is disabled for Solairs targets.

gcc/

PR middle-end/93195
PR middle-end/93197
* configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define 1 if
the assembler supports the section flag 'o' for specifying
section with link-order.
* output.h (SECTION_LINK_ORDER): New.  Defined to 0x4000000.
(SECTION_MACH_DEP): Changed from 0x4000000 to 0x8000000.
* targhooks.c (default_print_patchable_function_entry): Pass
SECTION_LINK_ORDER to switch_to_section if the section flag 'o'
works.  Pass current_function_decl to switch_to_section.
* varasm.c (default_elf_asm_named_section): Use 'o' flag for
SECTION_LINK_ORDER if assembler supports it.
* config.in: Regenerated.
* configure: Likewise.

gcc/testsuite/

PR middle-end/93195
* g++.dg/pr93195a.C: New test.
* g++.dg/pr93195b.C: Likewise.
* lib/target-supports.exp
(check_effective_target_o_flag_in_section): New proc.

-- 
H.J.

[-- Attachment #2: 0001-Use-the-section-flag-o-for-__patchable_function_entr.patch --]
[-- Type: application/x-patch, Size: 11622 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PING^5 [PATCH] Use the section flag 'o' for __patchable_function_entries
  2020-11-18 14:00         ` PING^5 " H.J. Lu
@ 2020-12-02  5:23           ` Jeff Law
  2020-12-02 13:15             ` V2 " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Law @ 2020-12-02  5:23 UTC (permalink / raw)
  To: H.J. Lu, GCC Patches, Jakub Jelinek, Richard Biener, Richard Sandiford



On 11/18/20 7:00 AM, H.J. Lu wrote:
> On Sat, Nov 7, 2020 at 7:47 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sat, Oct 31, 2020 at 5:01 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Fri, Oct 23, 2020 at 5:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Fri, Oct 2, 2020 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Thu, Feb 6, 2020 at 6:57 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>> This commit in GNU binutils 2.35:
>>>>>>
>>>>>> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e
>>>>>>
>>>>>> added the section flag 'o' to .section directive:
>>>>>>
>>>>>> .section __patchable_function_entries,"awo",@progbits,foo
>>>>>>
>>>>>> which specifies the symbol name which the section references.  Assembler
>>>>>> creates a unique __patchable_function_entries section with the section,
>>>>>> where foo is defined, as its linked-to section.  Linker keeps a section
>>>>>> if its linked-to section is kept during garbage collection.
>>>>>>
>>>>>> This patch checks assembler support for the section flag 'o' and uses
>>>>>> it to implement __patchable_function_entries section.  Since Solaris may
>>>>>> use GNU assembler with Solairs ld.  Even if GNU assembler supports the
>>>>>> section flag 'o', it doesn't mean that Solairs ld supports it.  This
>>>>>> feature is disabled for Solairs targets.
>>>>>>
>>>>>> gcc/
>>>>>>
>>>>>>         PR middle-end/93195
>>>>>>         PR middle-end/93197
>>>>>>         * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
>>>>>>         the assembler supports the section flag 'o' for specifying
>>>>>>         section with link-order.
>>>>>>         * dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
>>>>>>         to targetm.asm_out.named_section.
>>>>>>         * config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
>>>>>>         * output.h (SECTION2_LINK_ORDER): New.
>>>>>>         (switch_to_section): Add an unsigned int argument.
>>>>>>         (default_no_named_section): Likewise.
>>>>>>         (default_elf_asm_named_section): Likewise.
>>>>>>         * target.def (asm_out.named_section): Likewise.
>>>>>>         * targhooks.c (default_print_patchable_function_entry): Pass
>>>>>>         current_function_decl to get_section and SECTION2_LINK_ORDER
>>>>>>         to switch_to_section.
>>>>>>         * varasm.c (default_no_named_section): Add an unsigned int
>>>>>>         argument.
>>>>>>         (default_elf_asm_named_section): Add an unsigned int argument,
>>>>>>         flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
>>>>>>         supports it.
>>>>>>         (switch_to_section): Add an unsigned int argument and pass it
>>>>>>         to targetm.asm_out.named_section.
>>>>>>         (handle_vtv_comdat_section): Pass 0 to
>>>>>>         targetm.asm_out.named_section.
>>>>>>         * config.in: Regenerated.
>>>>>>         * configure: Likewise.
>>>>>>         * doc/tm.texi: Likewise.
>>>>>>
>>>>>> gcc/testsuite/
>>>>>>
>>>>>>         PR middle-end/93195
>>>>>>         * g++.dg/pr93195a.C: New test.
>>>>>>         * g++.dg/pr93195b.C: Likewise.
>>>>>>         * lib/target-supports.exp
>>>>>>         (check_effective_target_o_flag_in_section): New proc.
>>>>> PING
>>>>>
>>>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html
>>>> PING.
>>>>
>>> PING.
>>>
>> PING.
> Here is a simpler patch.  OK for master?
>
> This commit in GNU binutils 2.35:
>
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715
> 829eed0622616f6ae0182900de3e
>
> added the section flag 'o' to .section directive:
>
> .section __patchable_function_entries,"awo",@progbits,foo
>
> which specifies the symbol name which the section references.  Assembler
> creates a unique __patchable_function_entries section with the section,
> where foo is defined, as its linked-to section.  Linker keeps a section
> if its linked-to section is kept during garbage collection.
>
> This patch checks assembler support for the section flag 'o' and uses
> it to implement __patchable_function_entries section.  Since Solaris may
> use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> section flag 'o', it doesn't mean that Solairs ld supports it.  This
> feature is disabled for Solairs targets.
>
> gcc/
>
> PR middle-end/93195
> PR middle-end/93197
> * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define 1 if
> the assembler supports the section flag 'o' for specifying
> section with link-order.
> * output.h (SECTION_LINK_ORDER): New.  Defined to 0x4000000.
> (SECTION_MACH_DEP): Changed from 0x4000000 to 0x8000000.
> * targhooks.c (default_print_patchable_function_entry): Pass
> SECTION_LINK_ORDER to switch_to_section if the section flag 'o'
> works.  Pass current_function_decl to switch_to_section.
> * varasm.c (default_elf_asm_named_section): Use 'o' flag for
> SECTION_LINK_ORDER if assembler supports it.
> * config.in: Regenerated.
> * configure: Likewise.
>
> gcc/testsuite/
>
> PR middle-end/93195
> * g++.dg/pr93195a.C: New test.
> * g++.dg/pr93195b.C: Likewise.
> * lib/target-supports.exp
> (check_effective_target_o_flag_in_section): New proc.
So you need to document the new effective target test in
sourcebuild.texi.  I see new #if in targhooks.c.  If that could be made
a if (...) it'd be greatly appreciated.

OK with those changes.

jeff


^ permalink raw reply	[flat|nested] 12+ messages in thread

* V2 [PATCH] Use the section flag 'o' for __patchable_function_entries
  2020-12-02  5:23           ` Jeff Law
@ 2020-12-02 13:15             ` H.J. Lu
  2020-12-15 20:48               ` [PATCH] varasm: Fix up __patchable_function_entries handling Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-12-02 13:15 UTC (permalink / raw)
  To: Jeff Law; +Cc: GCC Patches, Jakub Jelinek, Richard Biener, Richard Sandiford

[-- Attachment #1: Type: text/plain, Size: 5761 bytes --]

On Tue, Dec 1, 2020 at 9:23 PM Jeff Law <law@redhat.com> wrote:
>
>
>
> On 11/18/20 7:00 AM, H.J. Lu wrote:
> > On Sat, Nov 7, 2020 at 7:47 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >> On Sat, Oct 31, 2020 at 5:01 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>> On Fri, Oct 23, 2020 at 5:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>>> On Fri, Oct 2, 2020 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>>>> On Thu, Feb 6, 2020 at 6:57 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>>>>> This commit in GNU binutils 2.35:
> >>>>>>
> >>>>>> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e
> >>>>>>
> >>>>>> added the section flag 'o' to .section directive:
> >>>>>>
> >>>>>> .section __patchable_function_entries,"awo",@progbits,foo
> >>>>>>
> >>>>>> which specifies the symbol name which the section references.  Assembler
> >>>>>> creates a unique __patchable_function_entries section with the section,
> >>>>>> where foo is defined, as its linked-to section.  Linker keeps a section
> >>>>>> if its linked-to section is kept during garbage collection.
> >>>>>>
> >>>>>> This patch checks assembler support for the section flag 'o' and uses
> >>>>>> it to implement __patchable_function_entries section.  Since Solaris may
> >>>>>> use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> >>>>>> section flag 'o', it doesn't mean that Solairs ld supports it.  This
> >>>>>> feature is disabled for Solairs targets.
> >>>>>>
> >>>>>> gcc/
> >>>>>>
> >>>>>>         PR middle-end/93195
> >>>>>>         PR middle-end/93197
> >>>>>>         * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define if
> >>>>>>         the assembler supports the section flag 'o' for specifying
> >>>>>>         section with link-order.
> >>>>>>         * dwarf2out.c (output_comdat_type_unit): Pass 0 as flags2
> >>>>>>         to targetm.asm_out.named_section.
> >>>>>>         * config/sol2.c (solaris_elf_asm_comdat_section): Likewise.
> >>>>>>         * output.h (SECTION2_LINK_ORDER): New.
> >>>>>>         (switch_to_section): Add an unsigned int argument.
> >>>>>>         (default_no_named_section): Likewise.
> >>>>>>         (default_elf_asm_named_section): Likewise.
> >>>>>>         * target.def (asm_out.named_section): Likewise.
> >>>>>>         * targhooks.c (default_print_patchable_function_entry): Pass
> >>>>>>         current_function_decl to get_section and SECTION2_LINK_ORDER
> >>>>>>         to switch_to_section.
> >>>>>>         * varasm.c (default_no_named_section): Add an unsigned int
> >>>>>>         argument.
> >>>>>>         (default_elf_asm_named_section): Add an unsigned int argument,
> >>>>>>         flags2.  Use 'o' flag for SECTION2_LINK_ORDER if assembler
> >>>>>>         supports it.
> >>>>>>         (switch_to_section): Add an unsigned int argument and pass it
> >>>>>>         to targetm.asm_out.named_section.
> >>>>>>         (handle_vtv_comdat_section): Pass 0 to
> >>>>>>         targetm.asm_out.named_section.
> >>>>>>         * config.in: Regenerated.
> >>>>>>         * configure: Likewise.
> >>>>>>         * doc/tm.texi: Likewise.
> >>>>>>
> >>>>>> gcc/testsuite/
> >>>>>>
> >>>>>>         PR middle-end/93195
> >>>>>>         * g++.dg/pr93195a.C: New test.
> >>>>>>         * g++.dg/pr93195b.C: Likewise.
> >>>>>>         * lib/target-supports.exp
> >>>>>>         (check_effective_target_o_flag_in_section): New proc.
> >>>>> PING
> >>>>>
> >>>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html
> >>>> PING.
> >>>>
> >>> PING.
> >>>
> >> PING.
> > Here is a simpler patch.  OK for master?
> >
> > This commit in GNU binutils 2.35:
> >
> > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715
> > 829eed0622616f6ae0182900de3e
> >
> > added the section flag 'o' to .section directive:
> >
> > .section __patchable_function_entries,"awo",@progbits,foo
> >
> > which specifies the symbol name which the section references.  Assembler
> > creates a unique __patchable_function_entries section with the section,
> > where foo is defined, as its linked-to section.  Linker keeps a section
> > if its linked-to section is kept during garbage collection.
> >
> > This patch checks assembler support for the section flag 'o' and uses
> > it to implement __patchable_function_entries section.  Since Solaris may
> > use GNU assembler with Solairs ld.  Even if GNU assembler supports the
> > section flag 'o', it doesn't mean that Solairs ld supports it.  This
> > feature is disabled for Solairs targets.
> >
> > gcc/
> >
> > PR middle-end/93195
> > PR middle-end/93197
> > * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define 1 if
> > the assembler supports the section flag 'o' for specifying
> > section with link-order.
> > * output.h (SECTION_LINK_ORDER): New.  Defined to 0x4000000.
> > (SECTION_MACH_DEP): Changed from 0x4000000 to 0x8000000.
> > * targhooks.c (default_print_patchable_function_entry): Pass
> > SECTION_LINK_ORDER to switch_to_section if the section flag 'o'
> > works.  Pass current_function_decl to switch_to_section.
> > * varasm.c (default_elf_asm_named_section): Use 'o' flag for
> > SECTION_LINK_ORDER if assembler supports it.
> > * config.in: Regenerated.
> > * configure: Likewise.
> >
> > gcc/testsuite/
> >
> > PR middle-end/93195
> > * g++.dg/pr93195a.C: New test.
> > * g++.dg/pr93195b.C: Likewise.
> > * lib/target-supports.exp
> > (check_effective_target_o_flag_in_section): New proc.
> So you need to document the new effective target test in
> sourcebuild.texi.  I see new #if in targhooks.c.  If that could be made

Fixed.

> a if (...) it'd be greatly appreciated.

Fixed.

> OK with those changes.
>

This is the patch I am checking in.

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-Use-the-section-flag-o-for-__patchable_function_entr.patch --]
[-- Type: text/x-patch, Size: 12070 bytes --]

From 5fc5a1c35a95398036b3858cfef448621a4d1514 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 3 Feb 2020 11:55:43 -0800
Subject: [PATCH] Use the section flag 'o' for __patchable_function_entries

This commit in GNU binutils 2.35:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e

added the section flag 'o' to .section directive:

.section __patchable_function_entries,"awo",@progbits,foo

which specifies the symbol name which the section references.  Assembler
creates a unique __patchable_function_entries section with the section,
where foo is defined, as its linked-to section.  Linker keeps a section
if its linked-to section is kept during garbage collection.

This patch checks assembler support for the section flag 'o' and uses
it to implement __patchable_function_entries section.  Since Solaris may
use GNU assembler with Solairs ld.  Even if GNU assembler supports the
section flag 'o', it doesn't mean that Solairs ld supports it.  This
feature is disabled for Solairs targets.

gcc/

	PR middle-end/93195
	PR middle-end/93197
	* configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define 1 if
	the assembler supports the section flag 'o' for specifying
	section with link-order.
	* output.h (SECTION_LINK_ORDER): New.  Defined to 0x8000000.
	(SECTION_MACH_DEP): Changed from 0x8000000 to 0x10000000.
	* targhooks.c (default_print_patchable_function_entry): Pass
	SECTION_LINK_ORDER to switch_to_section if the section flag 'o'
	works.  Pass current_function_decl to switch_to_section.
	* varasm.c (default_elf_asm_named_section): Use 'o' flag for
	SECTION_LINK_ORDER if assembler supports it.
	* config.in: Regenerated.
	* configure: Likewise.

gcc/testsuite/

	PR middle-end/93195
	* g++.dg/pr93195a.C: New test.
	* g++.dg/pr93195b.C: Likewise.
	* lib/target-supports.exp
	(check_effective_target_o_flag_in_section): New proc.
---
 gcc/config.in                         |  6 ++++
 gcc/configure                         | 52 +++++++++++++++++++++++++++
 gcc/configure.ac                      | 22 ++++++++++++
 gcc/doc/sourcebuild.texi              |  3 ++
 gcc/output.h                          |  3 +-
 gcc/targhooks.c                       |  5 ++-
 gcc/testsuite/g++.dg/pr93195a.C       | 27 ++++++++++++++
 gcc/testsuite/g++.dg/pr93195b.C       | 14 ++++++++
 gcc/testsuite/lib/target-supports.exp | 40 +++++++++++++++++++++
 gcc/varasm.c                          | 10 ++++++
 10 files changed, 180 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr93195a.C
 create mode 100644 gcc/testsuite/g++.dg/pr93195b.C

diff --git a/gcc/config.in b/gcc/config.in
index b6e041d311e..216505abd2c 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1386,6 +1386,12 @@
 #endif
 
 
+/* Define 0/1 if your assembler supports 'o' flag in .section directive. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GAS_SECTION_LINK_ORDER
+#endif
+
+
 /* Define 0/1 if your assembler supports marking sections with SHF_GNU_RETAIN
    flag. */
 #ifndef USED_FOR_TARGET
diff --git a/gcc/configure b/gcc/configure
index 747822208f2..785d6560987 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -24481,6 +24481,58 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+# Test if the assembler supports the section flag 'o' for specifying
+# section with link-order.
+case "${target}" in
+  # Solaris may use GNU assembler with Solairs ld.  Even if GNU
+  # assembler supports the section flag 'o', it doesn't mean that
+  # Solairs ld supports it.
+  *-*-solaris2*)
+    gcc_cv_as_section_link_order=no
+    ;;
+  *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for section 'o' flag" >&5
+$as_echo_n "checking assembler for section 'o' flag... " >&6; }
+if ${gcc_cv_as_section_link_order+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_section_link_order=no
+    if test $in_tree_gas = yes; then
+    if test $gcc_cv_gas_vers -ge `expr \( \( 2 \* 1000 \) + 35 \) \* 1000 + 0`
+  then gcc_cv_as_section_link_order=yes
+fi
+  elif test x$gcc_cv_as != x; then
+    $as_echo '.section .foo,"a"
+.byte 0
+.section __patchable_function_entries,"awo",%progbits,.foo
+.byte 0' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags --fatal-warnings -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+	gcc_cv_as_section_link_order=yes
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_section_link_order" >&5
+$as_echo "$gcc_cv_as_section_link_order" >&6; }
+
+
+    ;;
+esac
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_GAS_SECTION_LINK_ORDER `if test $gcc_cv_as_section_link_order = yes; then echo 1; else echo 0; fi`
+_ACEOF
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for section merging support" >&5
 $as_echo_n "checking assembler for section merging support... " >&6; }
 if ${gcc_cv_as_shf_merge+:} false; then :
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 478d0d6f238..062f57fa12b 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3350,6 +3350,28 @@ AC_DEFINE_UNQUOTED(HAVE_GAS_SHF_GNU_RETAIN,
   [`if test $gcc_cv_as_shf_gnu_retain = yes; then echo 1; else echo 0; fi`],
   [Define 0/1 if your assembler supports marking sections with SHF_GNU_RETAIN flag.])
 
+# Test if the assembler supports the section flag 'o' for specifying
+# section with link-order.
+case "${target}" in
+  # Solaris may use GNU assembler with Solairs ld.  Even if GNU
+  # assembler supports the section flag 'o', it doesn't mean that
+  # Solairs ld supports it.
+  *-*-solaris2*)
+    gcc_cv_as_section_link_order=no
+    ;;
+  *)
+    gcc_GAS_CHECK_FEATURE([section 'o' flag], gcc_cv_as_section_link_order,
+      [2,35,0], [--fatal-warnings],
+      [.section .foo,"a"
+.byte 0
+.section __patchable_function_entries,"awo",%progbits,.foo
+.byte 0])
+    ;;
+esac
+AC_DEFINE_UNQUOTED(HAVE_GAS_SECTION_LINK_ORDER,
+  [`if test $gcc_cv_as_section_link_order = yes; then echo 1; else echo 0; fi`],
+  [Define 0/1 if your assembler supports 'o' flag in .section directive.])
+
 gcc_GAS_CHECK_FEATURE(section merging support, gcc_cv_as_shf_merge,
  [elf,2,12,0], [--fatal-warnings],
  [.section .rodata.str, "aMS", @progbits, 1])
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 55538c3586b..586dce75740 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2548,6 +2548,9 @@ Target supports the @code{noinit} variable attribute.
 @item nonpic
 Target does not generate PIC by default.
 
+@item o_flag_in_section
+Target supports the 'o' flag in .section directive in assembly inputs.
+
 @item offload_gcn
 Target has been configured for OpenACC/OpenMP offloading on AMD GCN.
 
diff --git a/gcc/output.h b/gcc/output.h
index 729c52099e6..fa8ace1f394 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -382,10 +382,11 @@ extern void no_asm_to_stream (FILE *);
 #define SECTION_RELRO	 0x1000000	/* data is readonly after relocation processing */
 #define SECTION_EXCLUDE  0x2000000	/* discarded by the linker */
 #define SECTION_RETAIN	 0x4000000	/* retained by the linker.  */
+#define SECTION_LINK_ORDER 0x8000000	/* section needs link-order.  */
 
 /* NB: The maximum SECTION_MACH_DEP is 0x10000000 since AVR needs 4 bits
    in SECTION_MACH_DEP.  */
-#define SECTION_MACH_DEP 0x8000000	/* subsequent bits reserved for target */
+#define SECTION_MACH_DEP 0x10000000	/* subsequent bits reserved for target */
 
 /* This SECTION_STYLE is used for unnamed sections that we can switch
    to using a special assembler directive.  */
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index e634df3f6c6..6e12e13d68e 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1864,8 +1864,11 @@ default_print_patchable_function_entry (FILE *file,
       patch_area_number++;
       ASM_GENERATE_INTERNAL_LABEL (buf, "LPFE", patch_area_number);
 
+      unsigned int flags = SECTION_WRITE | SECTION_RELRO;
+      if (HAVE_GAS_SECTION_LINK_ORDER)
+	flags |= SECTION_LINK_ORDER;
       switch_to_section (get_section ("__patchable_function_entries",
-				      SECTION_WRITE | SECTION_RELRO, NULL));
+				      flags, current_function_decl));
       assemble_align (POINTER_SIZE);
       fputs (asm_op, file);
       assemble_name_raw (file, buf);
diff --git a/gcc/testsuite/g++.dg/pr93195a.C b/gcc/testsuite/g++.dg/pr93195a.C
new file mode 100644
index 00000000000..26d265da74e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr93195a.C
@@ -0,0 +1,27 @@
+/* { dg-do link { target { ! { nvptx*-*-* visium-*-* } } } } */
+// { dg-require-effective-target o_flag_in_section }
+/* { dg-options "-O0 -fpatchable-function-entry=1" } */
+/* { dg-additional-options "-fno-pie" { target sparc*-*-* } } */
+/* { dg-additional-sources pr93195b.C } */
+
+extern void bar1 (void);
+
+inline void
+foo (void)
+{
+}
+
+void
+bar (void)
+{
+  foo ();
+  bar1 ();
+}
+
+int
+main ()
+{
+  bar ();
+  return 0;
+}
+
diff --git a/gcc/testsuite/g++.dg/pr93195b.C b/gcc/testsuite/g++.dg/pr93195b.C
new file mode 100644
index 00000000000..303d8588c0f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr93195b.C
@@ -0,0 +1,14 @@
+/* { dg-do compile { target { ! { nvptx*-*-* visium-*-* } } } } */
+/* { dg-options "-O0 -fpatchable-function-entry=1" } */
+/* { dg-additional-options "-fno-pie" { target sparc*-*-* } } */
+
+inline void
+foo (void)
+{
+}
+
+void
+bar1 (void)
+{
+  foo ();
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 9d0a25d77e5..89c4f67554f 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10702,3 +10702,43 @@ proc check_effective_target_R_flag_in_section { } {
 	}
     }]
 }
+
+# Return 1 if this target supports 'o' flag in .section directive, 0
+# otherwise.  Cache the result.
+
+proc check_effective_target_o_flag_in_section { } {
+    global tool
+    global GCC_UNDER_TEST
+
+    # Need auto-host.h to check linker support.
+    if { ![file exists ../../auto-host.h ] } {
+	return 0
+    }
+
+    return [check_cached_effective_target o_flag_in_section {
+
+	set src pie[pid].c
+	set obj pie[pid].o
+
+	set f [open $src "w"]
+	puts $f "#include \"../../auto-host.h\""
+	puts $f "#if HAVE_GAS_SECTION_LINK_ORDER == 0"
+	puts $f "# error Assembler does not support 'o' flag in .section directive."
+	puts $f "#endif"
+	close $f
+
+	verbose "check_effective_target_o_flag_in_section compiling testfile $src" 2
+	set lines [${tool}_target_compile $src $obj object ""]
+
+	file delete $src
+	file delete $obj
+
+	if [string match "" $lines] then {
+	    verbose "check_effective_target_o_flag_in_section testfile compilation passed" 2
+	    return 1
+	} else {
+	    verbose "check_effective_target_o_flag_in_section testfile compilation failed" 2
+	    return 0
+	}
+    }]
+}
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 6c13f528f7b..961d2d6fe3b 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -6789,6 +6789,8 @@ default_elf_asm_named_section (const char *name, unsigned int flags,
 	*f++ = 'G';
       if (flags & SECTION_RETAIN)
 	*f++ = 'R';
+      if (flags & SECTION_LINK_ORDER)
+	*f++ = 'o';
 #ifdef MACH_DEP_SECTION_ASM_FLAG
       if (flags & SECTION_MACH_DEP)
 	*f++ = MACH_DEP_SECTION_ASM_FLAG;
@@ -6821,6 +6823,14 @@ default_elf_asm_named_section (const char *name, unsigned int flags,
 
       if (flags & SECTION_ENTSIZE)
 	fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
+      if (flags & SECTION_LINK_ORDER)
+	{
+	  tree id = DECL_ASSEMBLER_NAME (decl);
+	  ultimate_transparent_alias_target (&id);
+	  const char *name = IDENTIFIER_POINTER (id);
+	  name = targetm.strip_name_encoding (name);
+	  fprintf (asm_out_file, ",%s", name);
+	}
       if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
 	{
 	  if (TREE_CODE (decl) == IDENTIFIER_NODE)
-- 
2.28.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] varasm: Fix up __patchable_function_entries handling
  2020-12-02 13:15             ` V2 " H.J. Lu
@ 2020-12-15 20:48               ` Jakub Jelinek
  2020-12-16 13:36                 ` H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2020-12-15 20:48 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jeff Law, GCC Patches, Richard Sandiford

On Wed, Dec 02, 2020 at 05:15:21AM -0800, H.J. Lu via Gcc-patches wrote:
> gcc/
> 
> 	PR middle-end/93195
> 	PR middle-end/93197
> 	* configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define 1 if
> 	the assembler supports the section flag 'o' for specifying
> 	section with link-order.
> 	* output.h (SECTION_LINK_ORDER): New.  Defined to 0x8000000.
> 	(SECTION_MACH_DEP): Changed from 0x8000000 to 0x10000000.
> 	* targhooks.c (default_print_patchable_function_entry): Pass
> 	SECTION_LINK_ORDER to switch_to_section if the section flag 'o'
> 	works.  Pass current_function_decl to switch_to_section.
> 	* varasm.c (default_elf_asm_named_section): Use 'o' flag for
> 	SECTION_LINK_ORDER if assembler supports it.
> 	* config.in: Regenerated.
> 	* configure: Likewise.

Dunno if it is an assembler bug or gcc bug, but this SECTION_LINK_ORDER
stuff doesn't seem to work properly.

If I compile:
static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) __attribute__((patchable_function_entry(0, 0))) int foo (int x)
{
  return x + 1;
}

static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) __attribute__((patchable_function_entry(0, 0))) int bar (int x)
{
  return x + 2;
}

int
baz (int x)
{
  return foo (x) + 1;
}

int
qux (int x)
{
  return bar (x) + 2;
}
(distilled from aarch64 Linux kernel) with
-O2 -fpatchable-function-entry=2 on aarch64 compiler configured against
latest binutils, I get:
...
	.section	__patchable_function_entries,"awo",@progbits,baz
...
	.section	__patchable_function_entries
...
in the assembly, but when it is assembled, one gets:
  [ 4] __patchable_function_entries PROGBITS        0000000000000000 000060 000008 00 WAL  1   0  8
  [ 5] .rela__patchable_function_entries RELA            0000000000000000 000280 000018 18   I 12   4  8
  [ 6] __patchable_function_entries PROGBITS        0000000000000000 000068 000008 00      0   0  8
  [ 7] .rela__patchable_function_entries RELA            0000000000000000 000298 000018 18   I 12   6  8
i.e. one writable allocated section with SHF_LINK_ORDER and another
non-allocated non-writable without link order.  In the kernel case there is
always one entry in the WAL section and then dozens or more in the
non-allocated one.
The kernel then fails to link:
WARNING: modpost: vmlinux.o (__patchable_function_entries): unexpected non-allocatable section.
Did you forget to use "ax"/"aw" in a .S file?
Note that for example <linux/init.h> contains
section definitions for use in .S files.
ld: .init.data has both ordered [`__patchable_function_entries' in init/main.o] and unordered [`.init.data' in ./drivers/firmware/efi/libstub/vsprintf.stub.o] sections
ld: final link failed: bad value
make: *** [Makefile:1175: vmlinux] Error 1

If it is correct that the assembler requires full section flags for the
SECTION_LINK_ORDER .section directives in every case (like it does for
comdat or for retain), then we should do something like the following
untested change, but if it is gas bug, it should be fixed there.

2020-12-15  Jakub Jelinek  <jakub@redhat.com>

	* varasm.c (default_elf_asm_named_section): Always force
	section flags even for sections with SECTION_LINK_ORDER flag.

--- gcc/varasm.c.jj	2020-12-13 17:07:53.910477664 +0100
+++ gcc/varasm.c	2020-12-15 21:33:35.169314414 +0100
@@ -6781,10 +6781,10 @@ default_elf_asm_named_section (const cha
 
   /* If we have already declared this section, we can use an
      abbreviated form to switch back to it -- unless this section is
-     part of a COMDAT groups or with SHF_GNU_RETAIN, in which case GAS
-     requires the full declaration every time.  */
+     part of a COMDAT groups or with SHF_GNU_RETAIN or with SHF_LINK_ORDER,
+     in which case GAS requires the full declaration every time.  */
   if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
-      && !(flags & SECTION_RETAIN)
+      && !(flags & (SECTION_RETAIN | SECTION_LINK_ORDER))
       && (flags & SECTION_DECLARED))
     {
       fprintf (asm_out_file, "\t.section\t%s\n", name);


	Jakub


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] varasm: Fix up __patchable_function_entries handling
  2020-12-15 20:48               ` [PATCH] varasm: Fix up __patchable_function_entries handling Jakub Jelinek
@ 2020-12-16 13:36                 ` H.J. Lu
  2020-12-16 13:47                   ` Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-12-16 13:36 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, GCC Patches, Richard Sandiford

On Wed, Dec 16, 2020 at 5:05 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Wed, Dec 02, 2020 at 05:15:21AM -0800, H.J. Lu via Gcc-patches wrote:
> > gcc/
> >
> >       PR middle-end/93195
> >       PR middle-end/93197
> >       * configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define 1 if
> >       the assembler supports the section flag 'o' for specifying
> >       section with link-order.
> >       * output.h (SECTION_LINK_ORDER): New.  Defined to 0x8000000.
> >       (SECTION_MACH_DEP): Changed from 0x8000000 to 0x10000000.
> >       * targhooks.c (default_print_patchable_function_entry): Pass
> >       SECTION_LINK_ORDER to switch_to_section if the section flag 'o'
> >       works.  Pass current_function_decl to switch_to_section.
> >       * varasm.c (default_elf_asm_named_section): Use 'o' flag for
> >       SECTION_LINK_ORDER if assembler supports it.
> >       * config.in: Regenerated.
> >       * configure: Likewise.
>
> Dunno if it is an assembler bug or gcc bug, but this SECTION_LINK_ORDER
> stuff doesn't seem to work properly.
>
> If I compile:
> static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) __attribute__((patchable_function_entry(0, 0))) int foo (int x)
> {
>   return x + 1;
> }
>
> static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) __attribute__((patchable_function_entry(0, 0))) int bar (int x)
> {
>   return x + 2;
> }
>
> int
> baz (int x)
> {
>   return foo (x) + 1;
> }
>
> int
> qux (int x)
> {
>   return bar (x) + 2;
> }
> (distilled from aarch64 Linux kernel) with
> -O2 -fpatchable-function-entry=2 on aarch64 compiler configured against
> latest binutils, I get:
> ...
>         .section        __patchable_function_entries,"awo",@progbits,baz
> ...
>         .section        __patchable_function_entries
> ...
> in the assembly, but when it is assembled, one gets:
>   [ 4] __patchable_function_entries PROGBITS        0000000000000000 000060 000008 00 WAL  1   0  8
>   [ 5] .rela__patchable_function_entries RELA            0000000000000000 000280 000018 18   I 12   4  8
>   [ 6] __patchable_function_entries PROGBITS        0000000000000000 000068 000008 00      0   0  8
>   [ 7] .rela__patchable_function_entries RELA            0000000000000000 000298 000018 18   I 12   6  8
> i.e. one writable allocated section with SHF_LINK_ORDER and another
> non-allocated non-writable without link order.  In the kernel case there is
> always one entry in the WAL section and then dozens or more in the
> non-allocated one.
> The kernel then fails to link:
> WARNING: modpost: vmlinux.o (__patchable_function_entries): unexpected non-allocatable section.
> Did you forget to use "ax"/"aw" in a .S file?
> Note that for example <linux/init.h> contains
> section definitions for use in .S files.
> ld: .init.data has both ordered [`__patchable_function_entries' in init/main.o] and unordered [`.init.data' in ./drivers/firmware/efi/libstub/vsprintf.stub.o] sections
> ld: final link failed: bad value
> make: *** [Makefile:1175: vmlinux] Error 1
>
> If it is correct that the assembler requires full section flags for the
> SECTION_LINK_ORDER .section directives in every case (like it does for

gas is correct.

> comdat or for retain), then we should do something like the following
> untested change, but if it is gas bug, it should be fixed there.
>
> 2020-12-15  Jakub Jelinek  <jakub@redhat.com>
>
>         * varasm.c (default_elf_asm_named_section): Always force
>         section flags even for sections with SECTION_LINK_ORDER flag.
>
> --- gcc/varasm.c.jj     2020-12-13 17:07:53.910477664 +0100
> +++ gcc/varasm.c        2020-12-15 21:33:35.169314414 +0100
> @@ -6781,10 +6781,10 @@ default_elf_asm_named_section (const cha
>
>    /* If we have already declared this section, we can use an
>       abbreviated form to switch back to it -- unless this section is
> -     part of a COMDAT groups or with SHF_GNU_RETAIN, in which case GAS
> -     requires the full declaration every time.  */
> +     part of a COMDAT groups or with SHF_GNU_RETAIN or with SHF_LINK_ORDER,
> +     in which case GAS requires the full declaration every time.  */
>    if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
> -      && !(flags & SECTION_RETAIN)
> +      && !(flags & (SECTION_RETAIN | SECTION_LINK_ORDER))
>        && (flags & SECTION_DECLARED))
>      {
>        fprintf (asm_out_file, "\t.section\t%s\n", name);
>
>
>         Jakub
>

LGTM.  But I can't approve it.

Thanks.

--
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] varasm: Fix up __patchable_function_entries handling
  2020-12-16 13:36                 ` H.J. Lu
@ 2020-12-16 13:47                   ` Jakub Jelinek
  2020-12-16 14:18                     ` Jeff Law
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2020-12-16 13:47 UTC (permalink / raw)
  To: H.J. Lu, Jeff Law; +Cc: GCC Patches, Richard Sandiford

On Wed, Dec 16, 2020 at 05:36:04AM -0800, H.J. Lu wrote:
> gas is correct.
> 
> > comdat or for retain), then we should do something like the following
> > untested change, but if it is gas bug, it should be fixed there.
> >
> > 2020-12-15  Jakub Jelinek  <jakub@redhat.com>
> >
> >         * varasm.c (default_elf_asm_named_section): Always force
> >         section flags even for sections with SECTION_LINK_ORDER flag.
> >

> LGTM.  But I can't approve it.

Bootstrapped/regtested on x86_64-linux and i686-linux successfully.
Ok for trunk?

	Jakub


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] varasm: Fix up __patchable_function_entries handling
  2020-12-16 13:47                   ` Jakub Jelinek
@ 2020-12-16 14:18                     ` Jeff Law
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Law @ 2020-12-16 14:18 UTC (permalink / raw)
  To: Jakub Jelinek, H.J. Lu; +Cc: GCC Patches, Richard Sandiford



On 12/16/20 6:47 AM, Jakub Jelinek wrote:
> On Wed, Dec 16, 2020 at 05:36:04AM -0800, H.J. Lu wrote:
>> gas is correct.
>>
>>> comdat or for retain), then we should do something like the following
>>> untested change, but if it is gas bug, it should be fixed there.
>>>
>>> 2020-12-15  Jakub Jelinek  <jakub@redhat.com>
>>>
>>>         * varasm.c (default_elf_asm_named_section): Always force
>>>         section flags even for sections with SECTION_LINK_ORDER flag.
>>>
>> LGTM.  But I can't approve it.
> Bootstrapped/regtested on x86_64-linux and i686-linux successfully.
> Ok for trunk?
Yes.  I probably wasn't clear about that yesterday ;-)

jeff


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-12-16 14:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07  2:57 [PATCH] Use the section flag 'o' for __patchable_function_entries H.J. Lu
2020-10-02 13:00 ` PING: " H.J. Lu
2020-10-23 12:41   ` PING^2 " H.J. Lu
2020-10-31 12:01     ` PING^3 " H.J. Lu
2020-11-07 15:47       ` PING^4 " H.J. Lu
2020-11-18 14:00         ` PING^5 " H.J. Lu
2020-12-02  5:23           ` Jeff Law
2020-12-02 13:15             ` V2 " H.J. Lu
2020-12-15 20:48               ` [PATCH] varasm: Fix up __patchable_function_entries handling Jakub Jelinek
2020-12-16 13:36                 ` H.J. Lu
2020-12-16 13:47                   ` Jakub Jelinek
2020-12-16 14:18                     ` Jeff Law

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).