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.
To be committed to trunk after et-static soak time.
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
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.
* testsuite/c-c++-common/attr-used-6.c: Use gnu_retain
instead of R_flag_in_section.
* testsuite/c-c++-common/attr-used-7.c: Likewise.
* testsuite/c-c++-common/attr-retain-8.c: Likewise.
* testsuite/c-c++-common/attr-retain-11.c: Likewise.
* testsuite/c-c++-common/attr-used-5.c: Likewise.
* testsuite/c-c++-common/attr-retain-2.c: Likewise.
* testsuite/c-c++-common/attr-retain-3.c: Likewise.
* testsuite/c-c++-common/attr-used-4.c: Likewise.
* testsuite/c-c++-common/attr-retain-10.c: Likewise.
* testsuite/c-c++-common/attr-retain-9.c: Likewise.
* testsuite/c-c++-common/pr99113.c: Likewise.
* testsuite/c-c++-common/attr-retain-7.c: Likewise.
* testsuite/c-c++-common/attr-retain-6.c: Likewise.
* testsuite/c-c++-common/attr-used-9.c: Likewise.
* testsuite/c-c++-common/attr-used-3.c: Likewise.
* testsuite/c-c++-common/attr-retain-4.c: Likewise.
* testsuite/c-c++-common/attr-retain-5.c: Likewise.
* testsuite/c-c++-common/attr-used-2.c: Likewise.
* testsuite/c-c++-common/attr-used.c: Likewise.
* testsuite/c-c++-common/attr-used-8.c: Likewise.
* testsuite/gcc.c-torture/compile/attr-retain-2.c: Likewise.
* testsuite/gcc.c-torture/compile/attr-retain-1.c: Likewise.
* testsuite/gcc.c-torture/compile/attr-used-retain-1.c: Likewise.
* testsuite/gcc.c-torture/compile/attr-used-retain-2.c: Likewise.
# HG changeset patch
# Parent da069316e46b74994e549900acfba732fdae61cd
build: testsuite: Provide gnu_retain and initfini_array effective targets
diff --git a/gcc/config.in b/gcc/config.in
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1535,8 +1535,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
--- 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
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -3008,9 +3008,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.
@@ -3083,6 +3080,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.
@@ -3176,9 +3176,15 @@ and @code{double}. These optabs are: @c
@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
--- 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(v
/* { 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
__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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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(v
/* { 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -14090,44 +14090,12 @@ proc check_effective_target_no_fsanitize
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
-
- 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
- }
- }]
+# Return 1 if the target supports GNU Retain, 0 otherwise.
+# This means both SHF_GNU_RETAIN and SHT_INIT_ARRAY to simplify uses.
+
+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