Prompted by PR go/85429 (gotools unconditionally using gas syntax for setting SHF_EXCLUDE), I looked into what it takes to enable the flag (SECTION_EXCLUDE in gcc) on Solaris with /bin/as. Here's what I found:
* Unlike most (all?) other section flags, the Solaris/x86 as doesn't accept the "e" flag for SHF_EXCLUDE, but needs #exclude instead, just as on SPARC. * Solaris/SPARC as does use #exclude to set the flag, completely in line with its section flag syntax. * I noticed that the configure check for the "e" section flag is currently only run on x86, although gas on ELF targets supports it everywhere. The following patch fixes all this. There's one point to note: running gcc_GAS_CHECK_FEATURE twice with the same cache variable for different syntaxes of some feature won't work: as currently happens for gcc_cv_as_shf_merge, when the first such test returns no, the second one isn't even run, using the cached no value instead. Bootstrapped without regressions on i386-pc-solaris2.1[01], sparc-sun-solaris2.1[01] (each with as and gas), and x86_64-pc-linux-gnu. Ok for mainline? Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University 2018-04-18 Rainer Orth <r...@cebitec.uni-bielefeld.de> * configure.ac (gcc_cv_as_section_has_e): Move to common section. Rename to... (gcc_cv_as_section_exclude): ... this. Try Solaris as #exclude syntax. * configure: Regenerate. * config.in: Regenerate. * config/i386/i386.c (i386_solaris_elf_named_section): Handle SECTION_EXCLUDE. * config/sparc/sparc.c (sparc_solaris_elf_asm_named_section) [HAVE_GAS_SECTION_EXCLUDE]: Handle SECTION_EXCLUDE. * varasm.c (default_elf_asm_named_section): Don't check if HAVE_GAS_SECTION_EXCLUDE is defined.
# HG changeset patch # Parent 2c8ad65d830fdf48991fa8f278e5d0d896120b86 Support Solaris as SHF_EXCLUDE flag syntax diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -45240,6 +45240,15 @@ i386_solaris_elf_named_section (const ch solaris_elf_asm_comdat_section (name, flags, decl); return; } + + /* Solaris/x86 as uses the same syntax for the SHF_EXCLUDE flags as the + SPARC assembler. One cannot mix single-letter flags and #exclude, so + only emit the latter here. */ + if (flags & SECTION_EXCLUDE) + { + fprintf (asm_out_file, "\t.section\t%s,#exclude\n", name); + return; + } #endif default_elf_asm_named_section (name, flags, decl); diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c --- a/gcc/config/sparc/sparc.c +++ b/gcc/config/sparc/sparc.c @@ -10502,6 +10502,10 @@ sparc_solaris_elf_asm_named_section (con if (!(flags & SECTION_DEBUG)) fputs (",#alloc", asm_out_file); +#if HAVE_GAS_SECTION_EXCLUDE + if (flags & SECTION_EXCLUDE) + fputs (",#exclude", asm_out_file); +#endif if (flags & SECTION_WRITE) fputs (",#write", asm_out_file); if (flags & SECTION_TLS) diff --git a/gcc/configure.ac b/gcc/configure.ac --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -2953,6 +2953,34 @@ if test $gcc_cv_as_eh_frame = buggy; the [Define if your assembler mis-optimizes .eh_frame data.]) fi +# Test if the assembler supports the section flag 'e' or #exclude for +# specifying an excluded section. +gcc_GAS_CHECK_FEATURE([section exclude flag], gcc_cv_as_section_exclude_e, + [2,22,51], [--fatal-warnings], + [.section foo1,"e" + .byte 0,0,0,0]) +if test $gcc_cv_as_section_exclude_e = no; then + case "${target}" in + # Solaris as uses #exclude instead. + *-*-solaris2*) + case "${target}" in + sparc*-*-solaris2*) + conftest_s='.section "foo1", #exclude' + ;; + i?86-*-solaris2* | x86_64-*-solaris2*) + conftest_s='.section foo1, #exclude' + ;; + esac + ;; + esac + gcc_GAS_CHECK_FEATURE([section exclude flag], gcc_cv_as_section_exclude_hash,,, + [$conftest_s + .byte 0,0,0,0]) +fi +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.]) + gcc_GAS_CHECK_FEATURE(section merging support, gcc_cv_as_shf_merge, [elf,2,12,0], [--fatal-warnings], [.section .rodata.str, "aMS", @progbits, 1]) @@ -4202,16 +4230,6 @@ foo: nop [AC_DEFINE(HAVE_AS_XBRACE_COMMENT_OPTION, 1, [Define if your assembler supports -xbrace_comment option.])]) - # Test if the assembler supports the section flag 'e' for specifying - # an excluded section. - gcc_GAS_CHECK_FEATURE([.section with e], gcc_cv_as_section_has_e, - [2,22,51], [--fatal-warnings], -[.section foo1,"e" -.byte 0,0,0,0]) - AC_DEFINE_UNQUOTED(HAVE_GAS_SECTION_EXCLUDE, - [`if test $gcc_cv_as_section_has_e = yes; then echo 1; else echo 0; fi`], - [Define if your assembler supports specifying the section flag e.]) - gcc_GAS_CHECK_FEATURE([filds and fists mnemonics], gcc_cv_as_ix86_filds,,, [filds (%ebp); fists (%ebp)],, diff --git a/gcc/varasm.c b/gcc/varasm.c --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -6427,7 +6427,7 @@ default_elf_asm_named_section (const cha { if (!(flags & SECTION_DEBUG)) *f++ = 'a'; -#if defined (HAVE_GAS_SECTION_EXCLUDE) && HAVE_GAS_SECTION_EXCLUDE == 1 +#if HAVE_GAS_SECTION_EXCLUDE if (flags & SECTION_EXCLUDE) *f++ = 'e'; #endif