public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: "Martin Liška" <mliska@suse.cz>, gcc-patches@gcc.gnu.org
Cc: Richard Biener <richard.guenther@gmail.com>,
	Tom de Vries <tdevries@suse.de>
Subject: Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' (was: [PATCH 1/3] STABS: remove -gstabs and -gxcoff functionality)
Date: Mon, 10 Oct 2022 16:19:35 +0200	[thread overview]
Message-ID: <87fsfviww8.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <10a94ccc-e01b-b98a-0fcb-cd661c10c315@suse.cz>

[-- Attachment #1: Type: text/plain, Size: 8329 bytes --]

Hi!

On 2022-09-01T12:05:23+0200, Martin Liška <mliska@suse.cz> wrote:
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> I've also built all cross compilers.

First: thanks for that: clean up plus "built all cross compilers"!

But yet, I've now tracked down an issue related to these changes,
apparently only visible via the nvptx back end -- and quite
non-obvious...  ;-)

> --- a/gcc/config/nvptx/nvptx.cc
> +++ b/gcc/config/nvptx/nvptx.cc
> @@ -52,7 +52,6 @@
>  #include "tm-preds.h"
>  #include "tm-constrs.h"
>  #include "langhooks.h"
> -#include "dbxout.h"
>  #include "cfgrtl.h"
>  #include "gimple.h"
>  #include "stor-layout.h"

> --- a/gcc/dbxout.cc
> +++ /dev/null
> @@ -1,3936 +0,0 @@
> -/* Output dbx-format symbol table information from GNU compiler.

The "dbx-format symbol table information" stuff indeed is not relevant
anymore, but:

> -/* Record an element in the table of global destructors.  SYMBOL is
> -   a SYMBOL_REF of the function to be called; PRIORITY is a number
> -   between 0 and MAX_INIT_PRIORITY.  */
> -
> -void
> -default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
> -                               int priority ATTRIBUTE_UNUSED)
> -{
> -#if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
> -  /* Tell GNU LD that this is part of the static destructor set.
> -     This will work for any system that uses stabs, most usefully
> -     aout systems.  */
> -  dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
> -  dbxout_stab_value_label (XSTR (symbol, 0));
> -#else
> -  sorry ("global destructors not supported on this target");
> -#endif
> -}
> -
> -/* Likewise for global constructors.  */
> -
> -void
> -default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
> -                                int priority ATTRIBUTE_UNUSED)
> -{
> -#if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
> -  /* Tell GNU LD that this is part of the static destructor set.
> -     This will work for any system that uses stabs, most usefully
> -     aout systems.  */
> -  dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
> -  dbxout_stab_value_label (XSTR (symbol, 0));
> -#else
> -  sorry ("global constructors not supported on this target");
> -#endif
> -}

> --- a/gcc/dbxout.h
> +++ /dev/null
> @@ -1,60 +0,0 @@
> -/* dbxout.h - Various declarations for functions found in dbxout.cc

> -extern void default_stabs_asm_out_destructor (rtx, int);
> -extern void default_stabs_asm_out_constructor (rtx, int);

... these two functions, 'default_stabs_asm_out_constructor',
'default_stabs_asm_out_destructor' (specifically, now their 'sorry'
branches only) used to serve as default 'TARGET_ASM_CONSTRUCTOR',
'TARGET_ASM_DESTRUCTOR' via...

> --- a/gcc/target-def.h
> +++ b/gcc/target-def.h

|  #if !defined(TARGET_ASM_CONSTRUCTOR) && !defined(USE_COLLECT2)
|  # ifdef CTORS_SECTION_ASM_OP
|  #  define TARGET_ASM_CONSTRUCTOR default_ctor_section_asm_out_constructor
>  # else
>  #  ifdef TARGET_ASM_NAMED_SECTION
>  #   define TARGET_ASM_CONSTRUCTOR default_named_section_asm_out_constructor
> -#  else
> -#   define TARGET_ASM_CONSTRUCTOR default_stabs_asm_out_constructor
>  #  endif
>  # endif
>  #endif
> @@ -74,8 +72,6 @@
|  #if !defined(TARGET_ASM_DESTRUCTOR) && !defined(USE_COLLECT2)
|  # ifdef DTORS_SECTION_ASM_OP
|  #  define TARGET_ASM_DESTRUCTOR default_dtor_section_asm_out_destructor
>  # else
>  #  ifdef TARGET_ASM_NAMED_SECTION
>  #   define TARGET_ASM_DESTRUCTOR default_named_section_asm_out_destructor
> -#  else
> -#   define TARGET_ASM_DESTRUCTOR default_stabs_asm_out_destructor
>  #  endif
>  # endif
>  #endif

... this setup here (manually added some more context to the 'diff').

That is, if a back end was not 'USE_COLLECT2', nor manually defined
'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR', or got pointed to the
respective 'default_[...]'  functions due to 'CTORS_SECTION_ASM_OP',
'DTORS_SECTION_ASM_OP', or 'TARGET_ASM_NAMED_SECTION', it got pointed to
'default_stabs_asm_out_constructor', 'default_stabs_asm_out_destructor'.
These would emit 'sorry' for any global constructor/destructor they're
run into.

This is now gone, and thus in such a back end configuration case
'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' don't get defined
anymore, and thus the subsequently following:

    #if !defined(TARGET_HAVE_CTORS_DTORS)
    # if defined(TARGET_ASM_CONSTRUCTOR) && defined(TARGET_ASM_DESTRUCTOR)
    # define TARGET_HAVE_CTORS_DTORS true
    # endif
    #endif

... doesn't define 'TARGET_HAVE_CTORS_DTORS' anymore, and thus per my
understanding, 'gcc/final.cc:rest_of_handle_final':

    if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
        && targetm.have_ctors_dtors)
      targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
                                   decl_init_priority_lookup
                                     (current_function_decl));
    if (DECL_STATIC_DESTRUCTOR (current_function_decl)
        && targetm.have_ctors_dtors)
      targetm.asm_out.destructor (XEXP (DECL_RTL (current_function_decl), 0),
                                  decl_fini_priority_lookup
                                    (current_function_decl));

... simply does nothing anymore for a 'DECL_STATIC_CONSTRUCTOR',
'DECL_STATIC_DESTRUCTOR'.

This, effectively, means that GCC/nvptx now suddenly appears to "support"
global constructors/destructors, which means that a ton of test cases now
erroneously PASS that previously used to FAIL:

    sorry, unimplemented: global constructors not supported on this target

Of course, such support didn't magically happen due to
"STABS: remove -gstabs and -gxcoff functionality", so this is bad.  And,
corresponding execution testing then regularly FAILs (due to the global
constructor/destructor functions never being invoked), for example:

    [-UNSUPPORTED:-]{+PASS:+} gcc.dg/initpri1.c {+(test for excess errors)+}
    {+FAIL: gcc.dg/initpri1.c execution test+}

    [-UNSUPPORTED:-]{+PASS:+} g++.dg/special/conpr-1.C {+(test for excess errors)+}
    {+FAIL: g++.dg/special/conpr-1.C execution test+}

To restore the previous GCC/nvptx behavior, I seek permission to first
push the attached
"Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR'".
For traceability, this simply restores the previous code, stripped down
to the bare minimum.

As a next step, I'd then prepare a patch to re-work this thing, to make
it more obvious what's actually happening there.  (Details to be done.
For example, do we want to continue to have 'sorry' functions called via
'gcc/target-def.h', as done previously?  Or, should that be an '#error'
case there, and the nvptx back end provides its own 'sorry' functions for
'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR'?  Or, emit 'sorry' in
'gcc/final.cc:rest_of_handle_final'?  Or, something else?)


In addition to 'gcc/config/nvptx/nvptx.cc' (as quoted above) three more
files did '#include "dbxout.h"', and thus potentially could use these
'sorry' default functions.

Per my testing of '--target=pdp11-aout' as well as
'--target=powerpc64-darwin', re-introducing '#include "dbxout.h"' is not
relevant for 'gcc/config/pdp11/pdp11.cc' as well as for
'gcc/config/rs6000/rs6000-call.cc' and
'gcc/config/rs6000/rs6000-logue.cc' (for 'TARGET_MACHO' only).

Target pdp11-aout is not affected, because of 'gcc/config.gcc' setting:

    # On a.out targets, we need to use collect2.
    case ${target} in
    *-*-*aout*)
            use_collect2=yes
            ;;
    esac

Target powerpc64-darwin is not affected, because it defines
'TARGET_ASM_NAMED_SECTION'.

I'll thus remove those changes/TODO markers that are still present in the
attached
"Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR'".
With that, OK to push?


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-WIP-Restore-default-sorry-TARGET_ASM_CONSTRUCTOR-TAR.patch --]
[-- Type: text/x-diff, Size: 5943 bytes --]

From a2fd19176bb1d9111ba0826b979ae0cdf50957dc Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sun, 9 Oct 2022 22:39:02 +0200
Subject: [PATCH] [WIP] Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR',
 'TARGET_ASM_DESTRUCTOR'

... that got lost in
commit 7e0db0cdf01e9c885a29cb37415f5bc00d90c029
"STABS: remove -gstabs and -gxcoff functionality".
---
 gcc/Makefile.in                   |  1 +
 gcc/config/nvptx/nvptx.cc         |  1 +
 gcc/config/pdp11/pdp11.cc         |  1 +
 gcc/config/rs6000/rs6000-call.cc  |  4 +++
 gcc/config/rs6000/rs6000-logue.cc |  3 +++
 gcc/dbxout.cc                     | 43 +++++++++++++++++++++++++++++++
 gcc/dbxout.h                      | 25 ++++++++++++++++++
 gcc/target-def.h                  |  4 +++
 8 files changed, 82 insertions(+)
 create mode 100644 gcc/dbxout.cc
 create mode 100644 gcc/dbxout.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 59b67d994415..4808f6770ca1 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1354,6 +1354,7 @@ OBJS = \
 	data-streamer.o \
 	data-streamer-in.o \
 	data-streamer-out.o \
+	dbxout.o \
 	dbgcnt.o \
 	dce.o \
 	ddg.o \
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 2fe120b38730..4cb5d02d40cd 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -52,6 +52,7 @@
 #include "tm-preds.h"
 #include "tm-constrs.h"
 #include "langhooks.h"
+#include "dbxout.h"
 #include "cfgrtl.h"
 #include "gimple.h"
 #include "stor-layout.h"
diff --git a/gcc/config/pdp11/pdp11.cc b/gcc/config/pdp11/pdp11.cc
index 380223439a47..ae73c1f7bb98 100644
--- a/gcc/config/pdp11/pdp11.cc
+++ b/gcc/config/pdp11/pdp11.cc
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "calls.h"
 #include "expr.h"
 #include "builtins.h"
+//TODO #include "dbxout.h"
 #include "explow.h"
 #include "expmed.h"
 
diff --git a/gcc/config/rs6000/rs6000-call.cc b/gcc/config/rs6000/rs6000-call.cc
index ac3cb7e3d362..27971ecd0333 100644
--- a/gcc/config/rs6000/rs6000-call.cc
+++ b/gcc/config/rs6000/rs6000-call.cc
@@ -67,6 +67,10 @@
 
 #include "rs6000-internal.h"
 
+#if TARGET_MACHO
+//TODO #include "dbxout.h" /* dbxout_ */
+#endif
+
 #ifndef TARGET_PROFILE_KERNEL
 #define TARGET_PROFILE_KERNEL 0
 #endif
diff --git a/gcc/config/rs6000/rs6000-logue.cc b/gcc/config/rs6000/rs6000-logue.cc
index a11d020ccd0c..3aa60719f3b8 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -47,6 +47,9 @@
 #include "diagnostic-core.h"
 #include "alias.h"
 #include "rs6000-internal.h"
+#if TARGET_MACHO
+//TODO #include "dbxout.h" /* dbxout_ */
+#endif
 
 static int rs6000_ra_ever_killed (void);
 static void is_altivec_return_reg (rtx, void *);
diff --git a/gcc/dbxout.cc b/gcc/dbxout.cc
new file mode 100644
index 000000000000..161eeb196537
--- /dev/null
+++ b/gcc/dbxout.cc
@@ -0,0 +1,43 @@
+/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "diagnostic-core.h"
+#include "dbxout.h"
+
+/* Record an element in the table of global destructors.  SYMBOL is
+   a SYMBOL_REF of the function to be called; PRIORITY is a number
+   between 0 and MAX_INIT_PRIORITY.  */
+
+void
+default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
+				  int priority ATTRIBUTE_UNUSED)
+{
+  sorry ("global destructors not supported on this target");
+}
+
+/* Likewise for global constructors.  */
+
+void
+default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
+				   int priority ATTRIBUTE_UNUSED)
+{
+  sorry ("global constructors not supported on this target");
+}
diff --git a/gcc/dbxout.h b/gcc/dbxout.h
new file mode 100644
index 000000000000..ad0b538cabf1
--- /dev/null
+++ b/gcc/dbxout.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 1998-2022 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_DBXOUT_H
+#define GCC_DBXOUT_H
+
+extern void default_stabs_asm_out_destructor (rtx, int);
+extern void default_stabs_asm_out_constructor (rtx, int);
+
+#endif /* GCC_DBXOUT_H */
diff --git a/gcc/target-def.h b/gcc/target-def.h
index f81f8fe3bb39..1c4aa2963dc4 100644
--- a/gcc/target-def.h
+++ b/gcc/target-def.h
@@ -62,6 +62,8 @@
 # else
 #  ifdef TARGET_ASM_NAMED_SECTION
 #   define TARGET_ASM_CONSTRUCTOR default_named_section_asm_out_constructor
+#  else
+#   define TARGET_ASM_CONSTRUCTOR default_stabs_asm_out_constructor
 #  endif
 # endif
 #endif
@@ -72,6 +74,8 @@
 # else
 #  ifdef TARGET_ASM_NAMED_SECTION
 #   define TARGET_ASM_DESTRUCTOR default_named_section_asm_out_destructor
+#  else
+#   define TARGET_ASM_DESTRUCTOR default_stabs_asm_out_destructor
 #  endif
 # endif
 #endif
-- 
2.35.1


  parent reply	other threads:[~2022-10-10 14:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01 10:05 [PATCH 1/3] STABS: remove -gstabs and -gxcoff functionality Martin Liška
2022-09-01 10:05 ` Martin Liška
2022-09-01 11:18 ` Richard Biener
2022-09-02  7:00   ` Martin Liška
2022-09-02  8:54     ` Richard Biener
2022-09-05  7:59       ` Martin Liška
2022-09-05  9:05         ` Richard Biener
2022-09-14 12:19 ` [COMMITTED] Fix unused variable warning (was: [PATCH 1/3] STABS: remove -gstabs and -gxcoff functionality) Jan-Benedict Glaw
2022-09-14 13:20   ` Martin Liška
2022-10-10 14:19 ` Thomas Schwinge [this message]
2022-10-10 14:23   ` Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' " Tom de Vries
2022-10-11  6:40     ` Richard Biener
2022-11-04  9:12       ` Better integrate default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' (was: Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR') Thomas Schwinge
2022-10-12  9:21   ` Restore default 'sorry' 'TARGET_ASM_CONSTRUCTOR', 'TARGET_ASM_DESTRUCTOR' (was: [PATCH 1/3] STABS: remove -gstabs and -gxcoff functionality) Martin Liška
2022-11-04  9:04     ` Thomas Schwinge
2022-11-04  9:07       ` Thomas Schwinge
2022-11-04  9:32 ` [PATCH 1/3] STABS: remove -gstabs and -gxcoff functionality Thomas Schwinge
2022-11-10 14:02   ` Martin Liška
2022-11-10 14:12     ` Michael Matz
2022-11-10 14:13       ` Martin Liška

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsfviww8.fsf@euler.schwinge.homeip.net \
    --to=thomas@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    --cc=richard.guenther@gmail.com \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).