On Thu, Nov 12, 2020 at 02:41:52PM -0800, H.J. Lu wrote: > diff --git a/gcc/varasm.c b/gcc/varasm.c > index 435c7b348a5..c48ef9692ee 100644 > --- a/gcc/varasm.c > +++ b/gcc/varasm.c > @@ -289,6 +289,10 @@ get_section (const char *name, unsigned int flags, tree > decl, > slot = section_htab->find_slot_with_hash (name, htab_hash_string (name), > INSERT); > flags |= SECTION_NAMED; > +#if HAVE_GAS_SHF_GNU_RETAIN > + if (decl != nullptr && DECL_PRESERVE_P (decl))
Minor nit, but I think this should be "decl != NULL_TREE". We should also test that "used" with the "section" attribute applies the "R" flag. Please apply the attached patch if this gets approved. These new tests pass with arm-none-eabi and x86_64-pc-linux-gnu. Thanks, Jozef
commit cf8e26deb43d13268ab6ee231995aecbf41ba3a3 Author: Jozef Lawrynowicz <joze...@mittosystems.com> Date: Fri Nov 13 11:07:14 2020 +0000 Test "used" attribute in conjunction "section" attribute 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 b7763af11e4..5f6cbca6e33 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 @@ -4,6 +4,7 @@ /* { dg-final { scan-assembler ".bss.*,\"awR\"" } } */ /* { dg-final { scan-assembler ".data.*,\"awR\"" } } */ /* { dg-final { scan-assembler ".rodata.*,\"aR\"" } } */ +/* { dg-final { scan-assembler ".data.used_foo_sec,\"awR\"" } } */ void __attribute__((used)) used_fn (void) { } void unused_fn (void) { } @@ -30,3 +31,5 @@ int __attribute__((used)) used_data2 = 1; const int __attribute__((used)) used_rodata2 = 2; int __attribute__((used)) used_comm2; static int __attribute__((used)) used_lcomm2; + +int __attribute__((used,section(".data.used_foo_sec"))) used_foo = 2; 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 e3b3cf184f8..be5f3917ac8 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 @@ -10,6 +10,7 @@ /* { dg-final { scan-assembler ".rodata.used_rodata2,\"aR\"" } } */ /* { dg-final { scan-assembler ".bss.used_lcomm,\"awR\"" { target arm-*-* } } } */ /* { dg-final { scan-assembler ".bss.used_lcomm2,\"awR\"" { target arm-*-* } } } */ +/* { dg-final { scan-assembler ".data.used_foo_sec,\"awR\"" } } */ /* { dg-options "-ffunction-sections -fdata-sections" } */ #include "attr-used-retain-1.c"