[gcc r17-2653] testsuite: Provide gnu_retain effective target

Rainer Orth via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:469a256c2e3a8888c2e7a65d3fa832baf457b1c9

commit r17-2653-g469a256c2e3a8888c2e7a65d3fa832baf457b1c9
Author: Rainer Orth <[email protected]>
Date:   Thu Jul 23 10:20:56 2026 +0200

    testsuite: Provide gnu_retain effective target
    
    The existing R_flag_in_section effective target is badly named: the name
    carries no mnemonic value and is actually an implementation detail of a
    specific assembler section flag syntax.
    
    This patch uses the et-static framework to replace it by a new
    gnu_retain keyword.  Given that the existing R_flag_in_section
    implementation checks for both HAVE_GAS_SHF_GNU_RETAIN and
    HAVE_INITFINI_ARRAY_SUPPORT, this patch starts with matching
    shf_gnu_retain and sht_init_array keywords and combines them into
    gnu_retain proper.
    
    The existing tests are adaptated accordingly.
    
    Bootstrapped without regressions on i386-pc-solaris2.11 and
    x86_64-pc-linux-gnu.
    
    2026-01-13  Rainer Orth  <[email protected]>
    
            gcc:
            * configure.ac (HAVE_GAS_SHF_GNU_RETAIN): Clarify comment.
            * config.in: Regenerate.
    
            * doc/sourcebuild.texi (Effective-Target Keywords)
            (R_flag_in_section): Remove.
            (Effective-Target Keywords, gnu_retain): New keyword.
            (Effective-Target Keywords, shf_gnu_retain): Likewise.
            (Effective-Target Keywords, sht_init_array): Likewise.
    
            gcc/testsuite:
            * lib/et-static.def (shf_gnu_retain, sht_init_array): New
            effective targets.
            * lib/target-supports.exp
            (check_effective_target_R_flag_in_section): Remove.
            (check_effective_target_gnu_retain): New proc.
    
            * c-c++-common/attr-retain-1.c: Use gnu_retain
            instead of R_flag_in_section.
            * c-c++-common/attr-retain-2.c: Likewise.
            * c-c++-common/attr-retain-3.c: Likewise.
            * c-c++-common/attr-retain-4.c: Likewise.
            * c-c++-common/attr-retain-5.c: Likewise.
            * c-c++-common/attr-retain-6.c: Likewise.
            * c-c++-common/attr-retain-7.c: Likewise.
            * c-c++-common/attr-retain-8.c: Likewise.
            * c-c++-common/attr-retain-9.c: Likewise.
            * c-c++-common/attr-retain-10.c: Likewise.
            * c-c++-common/attr-retain-11.c: Likewise.
            * c-c++-common/attr-used-2.c: Likewise.
            * c-c++-common/attr-used-3.c: Likewise.
            * c-c++-common/attr-used-4.c: Likewise.
            * c-c++-common/attr-used-5.c: Likewise.
            * c-c++-common/attr-used-6.c: Likewise.
            * c-c++-common/attr-used-7.c: Likewise.
            * c-c++-common/attr-used-8.c: Likewise.
            * c-c++-common/attr-used-9.c: Likewise.
            * c-c++-common/attr-used.c: Likewise.
            * c-c++-common/pr99113.c: Likewise.
            * gcc.c-torture/compile/attr-retain-1.c: Likewise.
            * gcc.c-torture/compile/attr-retain-2.c: Likewise.
            * gcc.c-torture/compile/attr-used-retain-1.c: Likewise.
            * gcc.c-torture/compile/attr-used-retain-2.c: Likewise.

Diff:
---
 gcc/config.in                                      |  3 +-
 gcc/configure.ac                                   |  2 +-
 gcc/doc/sourcebuild.texi                           | 12 +++++--
 gcc/testsuite/c-c++-common/attr-retain-1.c         |  4 +--
 gcc/testsuite/c-c++-common/attr-retain-10.c        |  8 ++---
 gcc/testsuite/c-c++-common/attr-retain-11.c        |  8 ++---
 gcc/testsuite/c-c++-common/attr-retain-2.c         |  4 +--
 gcc/testsuite/c-c++-common/attr-retain-3.c         |  4 +--
 gcc/testsuite/c-c++-common/attr-retain-4.c         |  4 +--
 gcc/testsuite/c-c++-common/attr-retain-5.c         |  8 ++---
 gcc/testsuite/c-c++-common/attr-retain-6.c         |  8 ++---
 gcc/testsuite/c-c++-common/attr-retain-7.c         |  8 ++---
 gcc/testsuite/c-c++-common/attr-retain-8.c         |  8 ++---
 gcc/testsuite/c-c++-common/attr-retain-9.c         |  6 ++--
 gcc/testsuite/c-c++-common/attr-used-2.c           |  2 +-
 gcc/testsuite/c-c++-common/attr-used-3.c           |  2 +-
 gcc/testsuite/c-c++-common/attr-used-4.c           |  2 +-
 gcc/testsuite/c-c++-common/attr-used-5.c           |  4 +--
 gcc/testsuite/c-c++-common/attr-used-6.c           |  4 +--
 gcc/testsuite/c-c++-common/attr-used-7.c           |  4 +--
 gcc/testsuite/c-c++-common/attr-used-8.c           |  4 +--
 gcc/testsuite/c-c++-common/attr-used-9.c           |  4 +--
 gcc/testsuite/c-c++-common/attr-used.c             |  2 +-
 gcc/testsuite/c-c++-common/pr99113.c               |  2 +-
 .../gcc.c-torture/compile/attr-retain-1.c          |  2 +-
 .../gcc.c-torture/compile/attr-retain-2.c          |  2 +-
 .../gcc.c-torture/compile/attr-used-retain-1.c     |  2 +-
 .../gcc.c-torture/compile/attr-used-retain-2.c     |  2 +-
 gcc/testsuite/lib/et-static.def                    |  8 +++++
 gcc/testsuite/lib/target-supports.exp              | 42 +++-------------------
 30 files changed, 78 insertions(+), 97 deletions(-)

diff --git a/gcc/config.in b/gcc/config.in
index 22421a6cbeb0..95a1087c8a57 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1528,8 +1528,7 @@
 #endif
 
 
-/* Define 0/1 if your assembler supports marking sections with SHF_GNU_RETAIN
-   flag. */
+/* Define 0/1 if your assembler and linker support SHF_GNU_RETAIN. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_GAS_SHF_GNU_RETAIN
 #endif
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 6c560ceb90f4..c400be9114a5 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3771,7 +3771,7 @@ case "${target}" in
 esac
 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.])
+  [Define 0/1 if your assembler and linker support SHF_GNU_RETAIN.])
 
 # Test if the assembler supports the section flag 'o' for specifying
 # section with link-order.
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 603633e6932c..f3c5b13840c4 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -3040,9 +3040,6 @@ Target supports weak undefined symbols
 @subsubsection Other attributes
 
 @table @code
-@item R_flag_in_section
-Target supports the 'R' flag in .section directive in assembly inputs.
-
 @item asm_goto_with_outputs
 Target supports 'asm goto' with outputs.
 
@@ -3115,6 +3112,9 @@ Target supports @option{--gc-sections}.
 @item gld
 Target uses GNU @command{ld}.
 
+@item gnu_retain
+Target supports GNU retain.
+
 @item keeps_null_pointer_checks
 Target keeps null pointer checks, either due to the use of
 @option{-fno-delete-null-pointer-checks} or hardwired into the target.
@@ -3208,9 +3208,15 @@ and @code{double}.  These optabs are: @code{fma_optab}, @code{fms_optab},
 @item section_anchors
 Target supports section anchors.
 
+@item shf_gnu_retain
+Target supports @code{SHF_GNU_RETAIN}.
+
 @item short_enums
 Target defaults to short enums.
 
+@item sht_init_array
+Target supports @code{SHT_INIT_ARRAY} and @code{SHT_PREINIT_ARRAY} sections.
+
 @item solaris_as
 Target uses the Solaris @command{as}.
 
diff --git a/gcc/testsuite/c-c++-common/attr-retain-1.c b/gcc/testsuite/c-c++-common/attr-retain-1.c
index d060fbf22cd6..9316c2caf63b 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-1.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-options "-O3" } */
 
 static void function_declaration_before(void)
@@ -13,4 +13,4 @@ static void function_declaration_after(void)
 
 /* { dg-final { scan-assembler "function_declaration_before" } } */
 /* { dg-final { scan-assembler "function_declaration_after" } } */
-/* { dg-final { scan-assembler "\.text.*,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler "\.text.*,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-10.c b/gcc/testsuite/c-c++-common/attr-retain-10.c
index 0bac947023a4..fadc54a9c58b 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-10.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-10.c
@@ -1,11 +1,11 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */
 /* { dg-options "-Wall -O2 -fno-toplevel-reorder" } */
 
 int __attribute__((used,retain,section(".data.foo"))) foo2 = 2;
 int between = 1;
 int __attribute__((section(".data.foo"))) foo1 = 1;
-/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target R_flag_in_section } .-1 } */
+/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target gnu_retain } .-1 } */
 
-/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-11.c b/gcc/testsuite/c-c++-common/attr-retain-11.c
index d1d3d9e8c9f3..a5dc5d6ca34c 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-11.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-11.c
@@ -1,11 +1,11 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */
 /* { dg-options "-Wall -O2 -fno-toplevel-reorder" } */
 
 int __attribute__((section(".data.foo"))) foo1 = 1;
-/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target R_flag_in_section } .-1 } */
+/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target gnu_retain } .-1 } */
 int between = 1;
 int __attribute__((used,retain,section(".data.foo"))) foo2 = 2;
 
-/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-2.c b/gcc/testsuite/c-c++-common/attr-retain-2.c
index 6baba844adc1..1fe721ea364d 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-2.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-2.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-options "-Wall -O2" } */
 
 static int xyzzy __attribute__((__used__, __retain__)) = 1; 
@@ -9,4 +9,4 @@ void foo()
 }
 
 /* { dg-final { scan-assembler "xyzzy" } } */
-/* { dg-final { scan-assembler "\.data.*,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler "\.data.*,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-3.c b/gcc/testsuite/c-c++-common/attr-retain-3.c
index a4077a1644db..383403987c61 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-3.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-3.c
@@ -1,7 +1,7 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-options "-Wall -O2 -fcommon" } */
 
 static int xyzzy __attribute__((__used__, __retain__)); 
 
 /* { dg-final { scan-assembler "xyzzy" } } */
-/* { dg-final { scan-assembler ",\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ",\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-4.c b/gcc/testsuite/c-c++-common/attr-retain-4.c
index 590e47cec864..bf5899e0ac4f 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-4.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-4.c
@@ -1,7 +1,7 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-options "-Wall -O2 -fcommon" } */
 
 int xyzzy __attribute__((__used__, __retain__)); 
 
 /* { dg-final { scan-assembler "xyzzy" } } */
-/* { dg-final { scan-assembler ",\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ",\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-5.c b/gcc/testsuite/c-c++-common/attr-retain-5.c
index 5f8ed48d077f..4139ecc68c38 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-5.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-5.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */
 /* { dg-options "-Wall -O2" } */
 
@@ -11,7 +11,7 @@ extern struct dtv_slotinfo_list *list;
 
 static int __attribute__ ((section ("__libc_freeres_fn")))
 free_slotinfo (struct dtv_slotinfo_list **elemp)
-/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target R_flag_in_section } .-1 } */
+/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target gnu_retain } .-1 } */
 {
   if (!free_slotinfo (&(*elemp)->next))
     return 0;
@@ -27,5 +27,5 @@ static void free_mem (void)
   free_slotinfo (&list);
 }
 
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-6.c b/gcc/testsuite/c-c++-common/attr-retain-6.c
index ace9a7e1b059..19b6e23c9982 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-6.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-6.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */
 /* { dg-options "-Wall -O2" } */
 
@@ -22,10 +22,10 @@ free_slotinfo (struct dtv_slotinfo_list **elemp)
 
 __attribute__ ((section ("__libc_freeres_fn")))
 void free_mem (void)
-/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target R_flag_in_section } .-1 } */
+/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target gnu_retain } .-1 } */
 {
   free_slotinfo (&list);
 }
 
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-7.c b/gcc/testsuite/c-c++-common/attr-retain-7.c
index c56d18a88e0d..c0ce0a54aebc 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-7.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-7.c
@@ -1,10 +1,10 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */
 /* { dg-options "-Wall -O2" } */
 
 int __attribute__((used,retain,section(".data.foo"))) foo2 = 2;
 int __attribute__((section(".data.foo"))) foo1 = 1;
-/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target R_flag_in_section } .-1 } */
+/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target gnu_retain } .-1 } */
 
-/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-8.c b/gcc/testsuite/c-c++-common/attr-retain-8.c
index c1a9b52972e8..c9f264af1684 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-8.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-8.c
@@ -1,10 +1,10 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */
 /* { dg-options "-Wall -O2" } */
 
 int __attribute__((section(".data.foo"))) foo1 = 1;
-/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target R_flag_in_section } .-1 } */
+/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target gnu_retain } .-1 } */
 int __attribute__((used,retain,section(".data.foo"))) foo2 = 2;
 
-/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-retain-9.c b/gcc/testsuite/c-c++-common/attr-retain-9.c
index ab9bf4a7a3f1..8fe21cdb89a4 100644
--- a/gcc/testsuite/c-c++-common/attr-retain-9.c
+++ b/gcc/testsuite/c-c++-common/attr-retain-9.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */
 /* { dg-options "-Wall -O2" } */
 
@@ -28,5 +28,5 @@ static void free_mem (void)
 }
 
 /* { dg-final { scan-assembler-not "__libc_freeres_fn\n" } } */
-/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"ax\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"ax\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-2.c b/gcc/testsuite/c-c++-common/attr-used-2.c
index 5849747d1e4b..266cb8b9339c 100644
--- a/gcc/testsuite/c-c++-common/attr-used-2.c
+++ b/gcc/testsuite/c-c++-common/attr-used-2.c
@@ -9,4 +9,4 @@ void foo()
 }
 
 /* { dg-final { scan-assembler "xyzzy" } } */
-/* { dg-final { scan-assembler-not "\.data.*,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler-not "\.data.*,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-3.c b/gcc/testsuite/c-c++-common/attr-used-3.c
index 5a6ea991dc4b..c5f625a9d656 100644
--- a/gcc/testsuite/c-c++-common/attr-used-3.c
+++ b/gcc/testsuite/c-c++-common/attr-used-3.c
@@ -4,4 +4,4 @@
 static int xyzzy __attribute__((__used__)); 
 
 /* { dg-final { scan-assembler "xyzzy" } } */
-/* { dg-final { scan-assembler-not ",\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler-not ",\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-4.c b/gcc/testsuite/c-c++-common/attr-used-4.c
index 40c2c659d3c7..b30e4fe209d7 100644
--- a/gcc/testsuite/c-c++-common/attr-used-4.c
+++ b/gcc/testsuite/c-c++-common/attr-used-4.c
@@ -4,4 +4,4 @@
 int xyzzy __attribute__((__used__)); 
 
 /* { dg-final { scan-assembler "xyzzy" } } */
-/* { dg-final { scan-assembler-not ",\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler-not ",\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-5.c b/gcc/testsuite/c-c++-common/attr-used-5.c
index 7d968433f52a..056671d8d81e 100644
--- a/gcc/testsuite/c-c++-common/attr-used-5.c
+++ b/gcc/testsuite/c-c++-common/attr-used-5.c
@@ -24,5 +24,5 @@ static void free_mem (void)
   free_slotinfo (&list);
 }
 
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-6.c b/gcc/testsuite/c-c++-common/attr-used-6.c
index 7347e35c7f7a..af0852460157 100644
--- a/gcc/testsuite/c-c++-common/attr-used-6.c
+++ b/gcc/testsuite/c-c++-common/attr-used-6.c
@@ -24,5 +24,5 @@ void free_mem (void)
   free_slotinfo (&list);
 }
 
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-7.c b/gcc/testsuite/c-c++-common/attr-used-7.c
index 4ab942b7338c..238c5a0a726d 100644
--- a/gcc/testsuite/c-c++-common/attr-used-7.c
+++ b/gcc/testsuite/c-c++-common/attr-used-7.c
@@ -6,5 +6,5 @@
 int __attribute__((used,section(".data.foo"))) foo2 = 2;
 int __attribute__((section(".data.foo"))) foo1 = 1;
 
-/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler-not ".data.foo,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler-not ".data.foo,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-8.c b/gcc/testsuite/c-c++-common/attr-used-8.c
index 3fb55a55cbd9..588d169d5c27 100644
--- a/gcc/testsuite/c-c++-common/attr-used-8.c
+++ b/gcc/testsuite/c-c++-common/attr-used-8.c
@@ -6,5 +6,5 @@
 int __attribute__((section(".data.foo"))) foo1 = 1;
 int __attribute__((used,section(".data.foo"))) foo2 = 2;
 
-/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler-not ".data.foo,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler-not ".data.foo,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used-9.c b/gcc/testsuite/c-c++-common/attr-used-9.c
index ce3a4fbbd2f3..d274e37c3945 100644
--- a/gcc/testsuite/c-c++-common/attr-used-9.c
+++ b/gcc/testsuite/c-c++-common/attr-used-9.c
@@ -26,5 +26,5 @@ static void free_mem (void)
 }
 
 /* { dg-final { scan-assembler-not "__libc_freeres_fn\n" } } */
-/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target R_flag_in_section } } } */
-/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler "__libc_freeres_fn,\"ax\"" { target gnu_retain } } } */
+/* { dg-final { scan-assembler-not "__libc_freeres_fn,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/attr-used.c b/gcc/testsuite/c-c++-common/attr-used.c
index 96c6d6743461..6c34a471826e 100644
--- a/gcc/testsuite/c-c++-common/attr-used.c
+++ b/gcc/testsuite/c-c++-common/attr-used.c
@@ -11,4 +11,4 @@ static void function_declaration_after(void) __attribute__((__used__));
 
 /* { dg-final { scan-assembler "function_declaration_before" } } */
 /* { dg-final { scan-assembler "function_declaration_after" } } */
-/* { dg-final { scan-assembler-not "\.text.*,\"axR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler-not "\.text.*,\"axR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/c-c++-common/pr99113.c b/gcc/testsuite/c-c++-common/pr99113.c
index 01814014ac8d..a15d6f302a11 100644
--- a/gcc/testsuite/c-c++-common/pr99113.c
+++ b/gcc/testsuite/c-c++-common/pr99113.c
@@ -4,4 +4,4 @@
 static int xyzzy __attribute__((__used__)) = 1; 
 
 /* { dg-final { scan-assembler "xyzzy" } } */
-/* { dg-final { scan-assembler-not "\.data.*,\"awR\"" { target R_flag_in_section } } } */
+/* { dg-final { scan-assembler-not "\.data.*,\"awR\"" { target gnu_retain } } } */
diff --git a/gcc/testsuite/gcc.c-torture/compile/attr-retain-1.c b/gcc/testsuite/gcc.c-torture/compile/attr-retain-1.c
index 84f489adb2c6..963c7860dfaa 100644
--- a/gcc/testsuite/gcc.c-torture/compile/attr-retain-1.c
+++ b/gcc/testsuite/gcc.c-torture/compile/attr-retain-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* Prevent readonly data from being put in writable sdata for 32-bit powerpc. */
 /* { dg-options "-G0" { target { powerpc*-*-* && ilp32 } } } */
 /* { dg-final { scan-assembler ".text.*,\"axR\"" } } */
diff --git a/gcc/testsuite/gcc.c-torture/compile/attr-retain-2.c b/gcc/testsuite/gcc.c-torture/compile/attr-retain-2.c
index 692e07b08f9d..5ae043411d95 100644
--- a/gcc/testsuite/gcc.c-torture/compile/attr-retain-2.c
+++ b/gcc/testsuite/gcc.c-torture/compile/attr-retain-2.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target R_flag_in_section } } */
+/* { dg-do compile { target gnu_retain } } */
 /* { dg-final { scan-assembler ".text.used_fn,\"axR\"" } } */
 /* { dg-final { scan-assembler ".text.used_fn2,\"axR\"" } } */
 /* { dg-final { scan-assembler ".bss.used_bss,\"awR\"" } } */
diff --git a/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-1.c b/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-1.c
index bf5ca48c3160..e8e2284087f6 100644
--- a/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-1.c
+++ b/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-require-effective-target R_flag_in_section } */
+/* { dg-require-effective-target gnu_retain } */
 /* { dg-final { scan-assembler-not ".text.*,\"axR\"" } } */
 /* { dg-final { scan-assembler-not ".bss.*,\"awR\"" } } */
 /* { dg-final { scan-assembler-not ".data.*,\"awR\"" } } */
diff --git a/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-2.c b/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-2.c
index 7858e62c1541..7e79a2c0b5ed 100644
--- a/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-2.c
+++ b/gcc/testsuite/gcc.c-torture/compile/attr-used-retain-2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-require-effective-target R_flag_in_section } */
+/* { dg-require-effective-target gnu_retain } */
 /* { dg-final { scan-assembler-not ".text.used_fn,\"axR\"" } } */
 /* { dg-final { scan-assembler-not ".text.used_fn2,\"axR\"" } } */
 /* { dg-final { scan-assembler-not ".bss.used_bss,\"awR\"" } } */
diff --git a/gcc/testsuite/lib/et-static.def b/gcc/testsuite/lib/et-static.def
index 895e548bc87b..2c3b6eaa3ef3 100644
--- a/gcc/testsuite/lib/et-static.def
+++ b/gcc/testsuite/lib/et-static.def
@@ -48,6 +48,14 @@ powerpc_as_p10_htm
 HAVE_AS_POWER10_HTM
 your assembler supports htm insns on power10
 
+shf_gnu_retain
+HAVE_GAS_SHF_GNU_RETAIN
+this target supports SHF_GNU_RETAIN
+
+sht_init_array
+HAVE_INITFINI_ARRAY_SUPPORT
+this target supports SHT_INIT_ARRAY
+
 solaris_as
 HAVE_SOLARIS_AS
 using the Solaris assembler
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 38107ee7b185..0111fac3e42b 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -14199,44 +14199,12 @@ proc check_effective_target_no_fsanitize_address {} {
     return 0;
 }
 
-# Return 1 if this target supports 'R' flag in .section directive, 0
-# otherwise.  Cache the result.
-
-proc check_effective_target_R_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 R_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_SHF_GNU_RETAIN == 0 || HAVE_INITFINI_ARRAY_SUPPORT == 0"
-	puts $f "# error Assembler does not support 'R' flag in .section directive."
-	puts $f "#endif"
-	close $f
-
-	verbose "check_effective_target_R_flag_in_section compiling testfile $src" 2
-	set lines [${tool}_target_compile $src $obj assembly ""]
-
-	file delete $src
-	file delete $obj
+# Return 1 if the target supports GNU Retain, 0 otherwise.
+# This means both SHF_GNU_RETAIN and SHT_INIT_ARRAY to simplify uses.
 
-	if [string match "" $lines] then {
-	    verbose "check_effective_target_R_flag_in_section testfile compilation passed" 2
-	    return 1
-	} else {
-	    verbose "check_effective_target_R_flag_in_section testfile compilation failed" 2
-	    return 0
-	}
-    }]
+proc check_effective_target_gnu_retain { } {
+    return [expr { [check_effective_target_shf_gnu_retain]
+                   && [check_effective_target_sht_init_array] } ]
 }
 
 # Return 1 if this target supports 'o' flag in .section directive, 0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.