This commit is a follow up of bugzilla #107181. The commit /a0aafbc/ changed the default implementation of the SELECT_SECTION hook in order to match clang/llvm behaviour w.r.t the placement of `const volatile' objects.
However, the following targets use target-specific selection functions and they choke on the testcase pr25521.c: *rx - target sets its const variables as '.section C,"a",@progbits'. *powerpc - its 32bit version is eager to allocate globals in .sdata sections. Normally, one can expect for the variable to be allocated in .srodata, however, in case of powerpc-*-* or powerpc64-*-* (with -m32) 'targetm.have_srodata_section == false' and the code in categorize_decl_for_section(varasm.cc), forces it to allocate in .sdata. /* If the target uses small data sections, select it. */ else if (targetm.in_small_data_p (decl)) { if (ret == SECCAT_BSS) ret = SECCAT_SBSS; else if targetm.have_srodata_section && ret == SECCAT_RODATA) ret = SECCAT_SRODATA; else ret = SECCAT_SDATA; } LLVM compiler does not generate .sdata symbols at all, having different code generation even for non const volatile symbols. Targets that for acceptable reasons could not match the LLVM generated code were marked as XFAIL. gcc/testsuite/ChangeLog: * lib/target-supports.exp: Added check_effective_target_const_volatile_readonly_section. * gcc.dg/pr25521.c: Added XFAIL. --- gcc/testsuite/gcc.dg/pr25521.c | 3 +-- gcc/testsuite/lib/target-supports.exp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/pr25521.c b/gcc/testsuite/gcc.dg/pr25521.c index 63363a03b9f..597a2fc25d8 100644 --- a/gcc/testsuite/gcc.dg/pr25521.c +++ b/gcc/testsuite/gcc.dg/pr25521.c @@ -6,5 +6,4 @@ const volatile int foo = 30; - -/* { dg-final { scan-assembler "\\.s\?rodata" } } */ +/* { dg-final { scan-assembler-symbol-section {^_?foo$} {^\.(const|s?rodata)} { xfail { ! const_volatile_readonly_section } } } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 2a058c67c53..631d4593447 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -12196,3 +12196,15 @@ proc check_is_prog_name_available { prog } { return 1 } + +# returns 1 if target does selects a readonly section for const volatile variables. +proc check_effective_target_const_volatile_readonly_section { } { + + if { [istarget rx*-*-*] + || [istarget powerpc-*-*] + || [istarget rs6000*-*-*] + || [check-flags { "" { powerpc64-*-* } { -m32 } }] } { + return 0 + } + return 1 +} -- 2.30.2