As described in PR PR target/67973, newer assemblers on Mac OS X, which
are based on LLVM instead of gas, don't support .stab* directives any
longer.  The following patch detects this situation and tries to fall
back to the older gas-based as if it is still accessible via as -Q.

Tested on x86_64-apple-darwin15.2.0 and as expected the -gstabs* tests
now pass.

However, I'm not really comfortable with this solution.  Initially, I
forgot to wrap the -Q option to as in %{gstabs*:...}, which lead to a
bootstrap failure: the gas- and LLVM-based assemblers differ in a
number of other ways, as can be seen when comparing gcc/auto-host.h:

--- build.llvm-as/gcc/auto-host.h       2015-11-27 10:53:31.000000000 +0100
+++ build.gas/gcc/auto-host.h   2015-12-04 20:25:30.000000000 +0100
@@ -351 +357 @@
-/* #undef HAVE_AS_GDWARF2_DEBUG_FLAG */
+#define HAVE_AS_GDWARF2_DEBUG_FLAG 1
@@ -369 +375 @@
-/* #undef HAVE_AS_GSTABS_DEBUG_FLAG */
+#define HAVE_AS_GSTABS_DEBUG_FLAG 1
@@ -388 +394 @@
-/* #undef HAVE_AS_IX86_FFREEP */
+#define HAVE_AS_IX86_FFREEP 1
@@ -412 +418 @@
-#define HAVE_AS_IX86_INTERUNIT_MOVQ 1
+#define HAVE_AS_IX86_INTERUNIT_MOVQ 0
@@ -424 +430 @@
-#define HAVE_AS_IX86_REP_LOCK_PREFIX 1
+/* #undef HAVE_AS_IX86_REP_LOCK_PREFIX */
@@ -1176 +1182 @@
-#define HAVE_GAS_CFI_PERSONALITY_DIRECTIVE 1
+#define HAVE_GAS_CFI_PERSONALITY_DIRECTIVE 0
@@ -1179 +1185 @@
-#define HAVE_GAS_CFI_SECTIONS_DIRECTIVE 1
+#define HAVE_GAS_CFI_SECTIONS_DIRECTIVE 0
@@ -1183 +1189 @@
-#define HAVE_GAS_DISCRIMINATOR 1
+/* #undef HAVE_GAS_DISCRIMINATOR */
@@ -1298 +1304 @@
-#define HAVE_GNU_AS 0
+#define HAVE_GNU_AS 1

So, we can be pretty certain to hit cases where some file compiles and
assembles without -gstabs, but fails to assemble with -gstabs.  Not
exactly the user experience I prefer.

Given this, I'd rather have us not support stabs at all than via this
half-hearted approach.

What do you think?

        Rainer


2015-12-11  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        PR target/67973
        * configure.ac (gcc_cv_as_stabs_directive): New test.
        (gcc_cv_as_darwin_stabs_Q): New test.
        * configure: Regenerate.
        * config.in: Regenerate.
        * config/darwin.h (DBX_DEBUGGING_INFO): Wrap in
        HAVE_AS_STABS_DIRECTIVE.
        (PREFERRED_DEBUGGING_TYPE): Likewise.
        * config/i386/darwin.h (PREFERRED_DEBUGGING_TYPE): Only include
        DBX_DEBUG if HAVE_AS_STABS_DIRECTIVE.
        (ASM_STABS_Q_SPEC): Define.
        (ASM_SPEC): Use it.

# HG changeset patch
# Parent  7029fd86ac40d7ff34e1c43d729c6bf469416643
Only support -gstabs on Mac OS X if assember supports it (PR target/67973)

diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -400,12 +400,13 @@ extern GTY(()) int darwin_ms_struct;
 
 #define ASM_DEBUG_SPEC  "%{g*:%{!g0:%{!gdwarf*:--gstabs}}}"
 
-/* We still allow output of STABS.  */
-
+/* We still allow output of STABS if the assembler supports it.  */
+#ifdef HAVE_AS_STABS_DIRECTIVE
 #define DBX_DEBUGGING_INFO 1
+#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
+#endif
 
 #define DWARF2_DEBUGGING_INFO 1
-#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
 
 #define DEBUG_FRAME_SECTION	"__DWARF,__debug_frame,regular,debug"
 #define DEBUG_INFO_SECTION	"__DWARF,__debug_info,regular,debug"
diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -111,9 +111,16 @@ extern int darwin_emit_branch_islands;
   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} " \
   DARWIN_CC1_SPEC
 
+/* Pass -Q to assembler if necessary for stabs support.  */
+#ifdef HAVE_AS_DARWIN_STABS_Q
+#define ASM_STABS_Q_SPEC " %{gstabs*:-Q}"
+#else
+#define ASM_STABS_Q_SPEC ""
+#endif
+
 #undef ASM_SPEC
 #define ASM_SPEC "-arch %(darwin_arch) -force_cpusubtype_ALL \
-  %{static}"
+  %{static}" ASM_STABS_Q_SPEC
 
 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
@@ -226,7 +233,11 @@ do {									\
    compiles default to stabs+.  darwin9+ defaults to dwarf-2.  */
 #ifndef DARWIN_PREFER_DWARF
 #undef PREFERRED_DEBUGGING_TYPE
+#ifdef HAVE_AS_STABS_DIRECTIVE
 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
+#else
+#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
+#endif
 #endif
 
 /* Darwin uses the standard DWARF register numbers but the default
diff --git a/gcc/configure.ac b/gcc/configure.ac
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2909,6 +2909,11 @@ AC_DEFINE_UNQUOTED(HAVE_GAS_SHF_MERGE,
   [`if test $gcc_cv_as_shf_merge = yes; then echo 1; else echo 0; fi`],
 [Define 0/1 if your assembler supports marking sections with SHF_MERGE flag.])
 
+gcc_GAS_CHECK_FEATURE([stabs directive], gcc_cv_as_stabs_directive, ,,
+[.stabs "gcc2_compiled.",60,0,0,0],,
+[AC_DEFINE(HAVE_AS_STABS_DIRECTIVE, 1,
+  [Define if your assembler supports .stabs.])])
+
 gcc_GAS_CHECK_FEATURE([COMDAT group support (GNU as)],
  gcc_cv_as_comdat_group,
  [elf,2,16,0], [--fatal-warnings],
@@ -3619,6 +3624,26 @@ AC_DEFINE_UNQUOTED(HAVE_LTO_PLUGIN, $gcc
   [Define to the level of your linker's plugin support.])
 AC_MSG_RESULT($gcc_cv_lto_plugin)
 
+# Target OS-specific assembler checks.
+
+case "$target_os" in
+  darwin*)
+    # If the default assembler doesn't support .stabs, check if the
+    # gas-based one does.
+    if test x$gcc_cv_as_stabs_directive = xno; then
+      gcc_GAS_CHECK_FEATURE([.stabs directive via -Q],
+        gcc_cv_as_darwin_stabs_Q,, [-Q],
+	[.stabs "gcc2_compiled.",60,0,0,0],,
+      [AC_DEFINE(HAVE_AS_STABS_DIRECTIVE, 1,
+        [Define if your assembler supports .stabs.])
+       AC_DEFINE(HAVE_AS_DARWIN_STABS_Q, 1,
+        [Define if your assembler needs -Q to support .stabs.])])
+    fi
+    ;;
+esac
+
+# Target CPU-specific assembler checks.
+
 case "$target" in
   aarch64*-*-*)
     gcc_GAS_CHECK_FEATURE([-mabi option], gcc_cv_as_aarch64_mabi,,
-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

Reply via email to