The vast majority of the remaining uses of HAVE_GNU_AS are in
Solaris-specific code to distinguish uses of GNU as from Solaris as.
It's simpler to turn the check around, checking for Solaris as directly
instead.

The following patch does just that.

Tested on sparcv9-sun-solaris2.11, amd64-pc-solaris2.11,
sparc64-unknown-linux-gnu, and x86_64-pc-linux-gnu.

Ok for trunk?

Once this is in, only four uses of HAVE_GNU_AS remain, which are either
unnecessary or can be replaced with configure tests instead.  I'll
follow up on those soon.

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2026-02-08  Rainer Orth  <[email protected]>

        gcc:
        * configure.ac (solaris_as): New check.
        (gcc_cv_as_working_gdwarf_n_flag): Escape '.' in filename.
        (tls_section_flag): Test solaris_as instead of gas_flag.
        * acinclude.m4: (gcc_cv_initfini_array): Likewise.
        (gcc_cv_as_flags): Likewise.
        * configure: Regenerate.
        * config.in: Regenerate.
        * config/i386/i386.cc: Switch to HAVE_SOLARIS_AS.
        * config/i386/sol2.h: Likewise.
        * config/sol2.h: Likewise.
        * config/sparc/sol2.h: Likewise.
        * config/sparc/sparc.cc: Likewise.
        * config/sparc/sparc.md: Likewise.

# HG changeset patch
# Parent  4cc502b602f439a3014d3ace815a7a29a50fa05d
Switch to HAVE_SOLARIS_AS

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -308,20 +308,20 @@ int (*fp) (void) __attribute__ ((section
 	    gcc_cv_initfini_array=yes
 	  fi
 	elif test x"$gcc_cv_as" != x -a x"$gcc_cv_ld" != x -a x"$gcc_cv_objdump" != x ; then
-	  case $target:$gas_flag in
-	    *:yes)
-	      sh_flags='"a"'
-	      sh_type='%progbits'
-	      ;;
-	    i?86-*-solaris2*:no | x86_64-*-solaris2*:no)
+	  case $target:$solaris_as in
+	    i?86-*-solaris2*:yes | x86_64-*-solaris2*:yes)
 	      sh_flags='"a"'
 	      sh_type='@progbits'
 	      ;;
-	    sparc*-*-solaris2*:no)
+	    sparc*-*-solaris2*:yes)
 	      sh_flags='#alloc'
 	      sh_type='#progbits'
 	      sh_quote='"'
 	      ;;
+	    *:*)
+	      sh_flags='"a"'
+	      sh_type='%progbits'
+	      ;;
 	  esac
 	  case "$target:$gnu_ld_flag" in
 	    *:yes)
@@ -464,7 +464,7 @@ dnl # Used by gcc_GAS_CHECK_FEATURE
 dnl #
 AC_DEFUN([gcc_GAS_FLAGS],
 [AC_CACHE_CHECK([assembler flags], gcc_cv_as_flags,
-[ case "$target:$gas_flag" in
+[ case "$target:$solaris_as" in
   *-*-darwin*:*)
     dnl Darwin with the native assembler uses -arch i386/x86_64/ppc/ppc64.
     dnl
@@ -492,7 +492,7 @@ AC_DEFUN([gcc_GAS_FLAGS],
 	;;
     esac
     ;;
-  *-*-solaris2*:no)
+  *-*-solaris2*:yes)
     dnl Solaris with the native assembler uses -m32/-m64 consistently.
     case "$target" in
       i?86-*-* | sparc-*-*)
diff --git a/gcc/config.in b/gcc/config.in
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -2067,6 +2067,12 @@
 #endif
 
 
+/* Define to 1 if using the Solaris assembler. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_SOLARIS_AS
+#endif
+
+
 /* Define to 1 if you have the <stddef.h> header file. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_STDDEF_H
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -25116,7 +25116,7 @@ i386_solaris_elf_named_section (const ch
       return;
     }
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
   if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
     {
       solaris_elf_asm_comdat_section (name, flags, decl);
diff --git a/gcc/config/i386/sol2.h b/gcc/config/i386/sol2.h
--- a/gcc/config/i386/sol2.h
+++ b/gcc/config/i386/sol2.h
@@ -55,17 +55,15 @@ along with GCC; see the file COPYING3.  
 #define CC1_SPEC "%(cc1_cpu) " ASAN_CC1_SPEC SCTF_CC1_SPEC \
   " %{mx32:%e-mx32 is not supported on Solaris}"
 
-/* GNU as understands --32 and --64, but the native Solaris
-   assembler requires -m32 or -m64 instead.  */
-#if HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
+#define ASM_CPU32_DEFAULT_SPEC "-m32"
+#define ASM_CPU64_DEFAULT_SPEC "-m64"
+#else
 #define ASM_CPU32_DEFAULT_SPEC "--32"
 #define ASM_CPU64_DEFAULT_SPEC "--64"
-#else
-#define ASM_CPU32_DEFAULT_SPEC "-m32"
-#define ASM_CPU64_DEFAULT_SPEC "-m64"
 #endif
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
 /* Since Studio 12.6, as needs -xbrace_comment=no so its AVX512 syntax is
    fully compatible with gas.  */
 #define ASM_XBRACE_COMMENT_SPEC "-xbrace_comment=no"
@@ -145,7 +143,7 @@ along with GCC; see the file COPYING3.  
       }							\
   } while (0)
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
 /* The Sun assembler uses .tcomm for TLS common sections.  */
 #define TLS_COMMON_ASM_OP ".tcomm"
 
@@ -175,7 +173,7 @@ along with GCC; see the file COPYING3.  
       ASM_OUTPUT_LABEL (FILE, NAME);				\
     }								\
   while (0)
-#endif /* !HAVE_GNU_AS */
+#endif /* HAVE_SOLARIS_AS */
 
 /* As in sparc/sol2.h, override the default from i386/x86-64.h to work
    around Sun as TLS bug.  */
@@ -206,13 +204,13 @@ along with GCC; see the file COPYING3.  
 
 /* Sun as requires "h" flag for large sections, GNU as can do without, but
    accepts "l".  */
-#if HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
+#define MACH_DEP_SECTION_ASM_FLAG 'h'
+#else
 #define MACH_DEP_SECTION_ASM_FLAG 'l'
-#else
-#define MACH_DEP_SECTION_ASM_FLAG 'h'
 #endif
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
 /* Emit COMDAT group signature symbols for Sun as.  */
 #undef TARGET_ASM_FILE_END
 #define TARGET_ASM_FILE_END solaris_file_end
@@ -225,7 +223,7 @@ along with GCC; see the file COPYING3.  
 #define DTORS_SECTION_ASM_OP	"\t.section\t.dtors, \"aw\""
 #endif
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
 #define LARGECOMM_SECTION_ASM_OP "\t.lbcomm\t"
 #endif
 
diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -441,7 +441,7 @@ along with GCC; see the file COPYING3.  
     }								\
   while (0)
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
 #define TARGET_ASM_ASSEMBLE_VISIBILITY solaris_assemble_visibility
 
diff --git a/gcc/config/sparc/sol2.h b/gcc/config/sparc/sol2.h
--- a/gcc/config/sparc/sol2.h
+++ b/gcc/config/sparc/sol2.h
@@ -53,7 +53,7 @@ along with GCC; see the file COPYING3.  
 #define AS_SPARC32_FLAG ""
 #define AS_SPARC64_FLAG ""
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
 #undef ASM_ARCH32_SPEC
 #define ASM_ARCH32_SPEC "-m32"
 #undef ASM_ARCH64_SPEC
@@ -369,7 +369,7 @@ extern const char *host_detect_local_cpu
     }									\
   while (0)
 
-#if !HAVE_GNU_AS
+#if HAVE_SOLARIS_AS
 /* This is how to output an assembler line that says to advance
    the location counter to a multiple of 2**LOG bytes using the
    NOP instruction as padding.  The filler pattern doesn't work
@@ -385,7 +385,7 @@ extern const char *host_detect_local_cpu
 /* Sun as requires doublequoted section names on SPARC.  While GNU as
    supports that, too, we prefer the standard variant.  */
 #define SECTION_NAME_FORMAT	"\"%s\""
-#endif /* !HAVE_GNU_AS */
+#endif /* HAVE_SOLARIS_AS */
 
 /* Undefine this so that attribute((init_priority)) works with GNU ld.  */
 #if HAVE_GNU_LD
diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc
--- a/gcc/config/sparc/sparc.cc
+++ b/gcc/config/sparc/sparc.cc
@@ -877,7 +877,7 @@ char sparc_hard_reg_printed[8];
 #define TARGET_STACK_PROTECT_GUARD hook_tree_void_null
 #endif
 
-#if HAVE_GNU_AS
+#if !HAVE_SOLARIS_AS
 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
 #define TARGET_ASM_OUTPUT_DWARF_DTPREL sparc_output_dwarf_dtprel
 #endif
@@ -4701,7 +4701,7 @@ sparc_tls_got (void)
 
   /* In non-PIC mode, Sun as (unlike GNU as) emits PC-relative relocations for
      the GOT symbol with the 32-bit ABI, so we reload the GOT register.  */
-  if (!HAVE_GNU_AS && TARGET_ARCH32)
+  if (HAVE_SOLARIS_AS && TARGET_ARCH32)
     {
       load_got_register ();
       return got_register_rtx;
@@ -4805,7 +4805,7 @@ sparc_legitimize_tls_address (rtx addr)
 	  emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
 	else
 	  emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
-	if (!HAVE_GNU_AS)
+	if (HAVE_SOLARIS_AS)
 	  {
 	    ret = gen_reg_rtx (Pmode);
 	    emit_insn (gen_tie_add (Pmode, ret, gen_rtx_REG (Pmode, 7),
diff --git a/gcc/config/sparc/sparc.md b/gcc/config/sparc/sparc.md
--- a/gcc/config/sparc/sparc.md
+++ b/gcc/config/sparc/sparc.md
@@ -557,7 +557,7 @@
 
 ;; Attributes for branch scheduling
 (define_attr "tls_delay_slot" "false,true"
-  (symbol_ref "((HAVE_GNU_AS && HAVE_GNU_LD) != 0
+  (symbol_ref "((!HAVE_SOLARIS_AS && HAVE_GNU_LD) != 0
 		? TLS_DELAY_SLOT_TRUE : TLS_DELAY_SLOT_FALSE)"))
 
 (define_attr "in_sibcall_delay" "false,true"
@@ -8070,7 +8070,7 @@
 		(unspec:P [(match_operand:P 2 "register_operand" "r")
 			   (match_operand 3 "tie_symbolic_operand" "")]
 			  UNSPEC_TLSIE)))]
-  "!HAVE_GNU_AS"
+  "HAVE_SOLARIS_AS"
   "add\\t%1, %2, %0, %%tie_add(%a3)")
 
 (define_insn "@tle_hix22<P:mode>"
diff --git a/gcc/configure b/gcc/configure
--- a/gcc/configure
+++ b/gcc/configure
@@ -25490,6 +25490,29 @@ fi
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Solaris assembler" >&5
+$as_echo_n "checking Solaris assembler... " >&6; }
+case $target in
+  *-*-solaris2*)
+    if $gcc_cv_as -V 2>&1 | grep 'Compiler Common.*SunOS' > /dev/null; then
+      solaris_as=yes
+    elif $gcc_cv_as --version 2>/dev/null | grep GNU > /dev/null; then
+      gas_flag=yes
+    fi
+    ;;
+  *)
+    solaris_as=no
+    ;;
+esac
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $solaris_as" >&5
+$as_echo "$solaris_as" >&6; }
+solaris_as_bool=`if test $solaris_as = yes; then echo 1; else echo 0; fi`
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_SOLARIS_AS $solaris_as_bool
+_ACEOF
+
+
 ORIGINAL_AS_FOR_TARGET=$gcc_cv_as
 
 case "$ORIGINAL_AS_FOR_TARGET" in
@@ -26153,7 +26176,7 @@ esac
 if ${gcc_cv_as_flags+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-   case "$target:$gas_flag" in
+   case "$target:$solaris_as" in
   *-*-darwin*:*)
                         case "$target" in
       i?86-*-*)
@@ -26176,7 +26199,7 @@ else
 	;;
     esac
     ;;
-  *-*-solaris2*:no)
+  *-*-solaris2*:yes)
         case "$target" in
       i?86-*-* | sparc-*-*)
 	gcc_cv_as_flags=-m32
@@ -26854,20 +26877,20 @@ fi
 	    gcc_cv_initfini_array=yes
 	  fi
 	elif test x"$gcc_cv_as" != x -a x"$gcc_cv_ld" != x -a x"$gcc_cv_objdump" != x ; then
-	  case $target:$gas_flag in
-	    *:yes)
-	      sh_flags='"a"'
-	      sh_type='%progbits'
-	      ;;
-	    i?86-*-solaris2*:no | x86_64-*-solaris2*:no)
+	  case $target:$solaris_as in
+	    i?86-*-solaris2*:yes | x86_64-*-solaris2*:yes)
 	      sh_flags='"a"'
 	      sh_type='@progbits'
 	      ;;
-	    sparc*-*-solaris2*:no)
+	    sparc*-*-solaris2*:yes)
 	      sh_flags='#alloc'
 	      sh_type='#progbits'
 	      sh_quote='"'
 	      ;;
+	    *:*)
+	      sh_flags='"a"'
+	      sh_type='%progbits'
+	      ;;
 	  esac
 	  case "$target:$gnu_ld_flag" in
 	    *:yes)
@@ -28040,8 +28063,8 @@ foo:	.long	25
 .word foo(tlsldo)'
 	;;
   i?86-*-* | x86_64-*-*)
-    case "$target:$gas_flag" in
-      i?86-*-solaris2*:no | x86_64-*-solaris2*:no)
+    case "$target:$solaris_as" in
+      i?86-*-solaris2*:yes | x86_64-*-solaris2*:yes)
 	tls_section_flag=t
 
 $as_echo "#define TLS_SECTION_ASM_FLAG 't'" >>confdefs.h
@@ -28291,8 +28314,8 @@ foo:	.long	25
 	.long	foo@TPOFF'
 	;;
   sparc*-*-*)
-    case "$target:$gas_flag" in
-      sparc*-sun-solaris2.*:no)
+    case "$target:$solaris_as" in
+      sparc*-sun-solaris2.*:yes)
 	conftest_s='
 	.section ".tdata",#alloc,#write,#tls'
 	;;
@@ -32544,7 +32567,7 @@ else
     then
 	      if test x$gcc_cv_objdump != x \
 	 && $gcc_cv_objdump -W conftest.o 2>&1 \
-		| grep conftest.s > /dev/null 2>&1; then
+		| grep 'conftest\.s' > /dev/null 2>&1; then
 	gcc_cv_as_working_gdwarf_n_flag=no
       else
 	gcc_cv_as_working_gdwarf_n_flag=yes
diff --git a/gcc/configure.ac b/gcc/configure.ac
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2736,6 +2736,24 @@ gas_flag="$with_gnu_as",
    gas_flag=no
 fi])
 
+AC_MSG_CHECKING(Solaris assembler)
+case $target in
+  *-*-solaris2*)
+    if $gcc_cv_as -V 2>&1 | grep 'Compiler Common.*SunOS' > /dev/null; then
+      solaris_as=yes
+    elif $gcc_cv_as --version 2>/dev/null | grep GNU > /dev/null; then
+      gas_flag=yes
+    fi
+    ;;
+  *)
+    solaris_as=no
+    ;;
+esac
+AC_MSG_RESULT($solaris_as)
+solaris_as_bool=`if test $solaris_as = yes; then echo 1; else echo 0; fi`
+AC_DEFINE_UNQUOTED(HAVE_SOLARIS_AS, $solaris_as_bool,
+	[Define to 1 if using the Solaris assembler.])
+
 ORIGINAL_AS_FOR_TARGET=$gcc_cv_as
 AC_SUBST(ORIGINAL_AS_FOR_TARGET)
 case "$ORIGINAL_AS_FOR_TARGET" in
@@ -3945,8 +3963,8 @@ foo:	.long	25
 .word foo(tlsldo)'
 	;;
   i?86-*-* | x86_64-*-*)
-    case "$target:$gas_flag" in
-      i?86-*-solaris2*:no | x86_64-*-solaris2*:no)
+    case "$target:$solaris_as" in
+      i?86-*-solaris2*:yes | x86_64-*-solaris2*:yes)
 	tls_section_flag=t
 changequote([,])dnl
 	AC_DEFINE(TLS_SECTION_ASM_FLAG, 't',
@@ -4197,8 +4215,8 @@ foo:	.long	25
 	.long	foo@TPOFF'
 	;;
   sparc*-*-*)
-    case "$target:$gas_flag" in
-      sparc*-sun-solaris2.*:no)
+    case "$target:$solaris_as" in
+      sparc*-sun-solaris2.*:yes)
 	conftest_s='
 	.section ".tdata",#alloc,#write,#tls'
 	;;
@@ -5973,7 +5991,7 @@ foo:
      [changequote(,)dnl
       if test x$gcc_cv_objdump != x \
 	 && $gcc_cv_objdump -W conftest.o 2>&1 \
-		| grep conftest.s > /dev/null 2>&1; then
+		| grep 'conftest\.s' > /dev/null 2>&1; then
 	gcc_cv_as_working_gdwarf_n_flag=no
       else
 	gcc_cv_as_working_gdwarf_n_flag=yes

Reply via email to