From: "Martin Liška" <mliska@suse.cz>
To: Egeyar Bagcioglu <egeyar.bagcioglu@oracle.com>,
Jakub Jelinek <jakub@redhat.com>
Cc: Richard Biener <richard.guenther@gmail.com>,
GCC Patches <gcc-patches@gcc.gnu.org>,
nickc@redhat.com
Subject: Re: [PATCH v2 3/3] Keep .GCC.command.line sections of LTO objetcs.
Date: Thu, 05 Mar 2020 08:54:00 -0000 [thread overview]
Message-ID: <63cd2ac4-bd04-929d-98c3-2762da882e9c@suse.cz> (raw)
In-Reply-To: <648767d6-68ff-cb3c-811b-c20ee2202b41@oracle.com>
[-- Attachment #1: Type: text/plain, Size: 180 bytes --]
Hi.
I'm sending the updated patch based on Egeyar's work.
It utilizes a new environmental variable and uses the currently
existing -frecord-gcc-switches option.
Thoughts?
Martin
[-- Attachment #2: 0001-Change-semantics-of-frecord-gcc-switches.patch --]
[-- Type: text/x-patch, Size: 12651 bytes --]
From 9436d12e7a540691c6f2d6e2db4730a138e5c458 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 5 Mar 2020 09:39:17 +0100
Subject: [PATCH] Change semantics of -frecord-gcc-switches.
gcc/ChangeLog:
2020-03-05 Martin Liska <mliska@suse.cz>
Egeyar Bagcioglu <egeyar.bagcioglu@oracle.com>
* common.opt: Make flag_record_gcc_switches also
a driver option.
* doc/tm.texi: Regenerate.
* gcc.c (set_driver_command_line_envvar): New.
(driver_handle_option): Handle OPT_frecord_gcc_switches
and export command line into a ENV variable.
(driver::main): Save command line.
(driver::set_commandline): New.
* gcc.h (set_commandline): New.
* target.def: Simplify documentation by removal
of unused enum values.
* target.h (elf_record_gcc_switches): Change function type.
* toplev.c (init_asm_output): Update call.
* varasm.c (elf_record_gcc_switches): Record GCC version
string and content of GCC_DRIVER_COMMAND_LINE.
---
gcc/common.opt | 2 +-
gcc/doc/tm.texi | 37 ++-----------------------------------
gcc/gcc.c | 41 +++++++++++++++++++++++++++++++++++++++++
gcc/gcc.h | 1 +
gcc/target.def | 37 ++-----------------------------------
gcc/target.h | 2 +-
gcc/toplev.c | 11 +----------
gcc/varasm.c | 46 ++++++++++------------------------------------
8 files changed, 59 insertions(+), 118 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index fa9da505fc2..60ca5a521c5 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2246,7 +2246,7 @@ Common Joined RejectNegative Var(common_deferred_options) Defer
; records information in the assembler output file as comments, so
; they never reach the object file.
frecord-gcc-switches
-Common Report Var(flag_record_gcc_switches)
+Common Driver Report Var(flag_record_gcc_switches)
Record gcc command line switches in the object file.
freg-struct-return
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 19985adac3e..30c71d60aff 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -8061,43 +8061,10 @@ need to override this if your target has special flags that might be
set via @code{__attribute__}.
@end deftypefn
-@deftypefn {Target Hook} int TARGET_ASM_RECORD_GCC_SWITCHES (print_switch_type @var{type}, const char *@var{text})
+@deftypefn {Target Hook} void TARGET_ASM_RECORD_GCC_SWITCHES (void)
Provides the target with the ability to record the gcc command line
switches that have been passed to the compiler, and options that are
-enabled. The @var{type} argument specifies what is being recorded.
-It can take the following values:
-
-@table @gcctabopt
-@item SWITCH_TYPE_PASSED
-@var{text} is a command line switch that has been set by the user.
-
-@item SWITCH_TYPE_ENABLED
-@var{text} is an option which has been enabled. This might be as a
-direct result of a command line switch, or because it is enabled by
-default or because it has been enabled as a side effect of a different
-command line switch. For example, the @option{-O2} switch enables
-various different individual optimization passes.
-
-@item SWITCH_TYPE_DESCRIPTIVE
-@var{text} is either NULL or some descriptive text which should be
-ignored. If @var{text} is NULL then it is being used to warn the
-target hook that either recording is starting or ending. The first
-time @var{type} is SWITCH_TYPE_DESCRIPTIVE and @var{text} is NULL, the
-warning is for start up and the second time the warning is for
-wind down. This feature is to allow the target hook to make any
-necessary preparations before it starts to record switches and to
-perform any necessary tidying up after it has finished recording
-switches.
-
-@item SWITCH_TYPE_LINE_START
-This option can be ignored by this target hook.
-
-@item SWITCH_TYPE_LINE_END
-This option can be ignored by this target hook.
-@end table
-
-The hook's return value must be zero. Other return values may be
-supported in the future.
+enabled.
By default this hook is set to NULL, but an example implementation is
provided for ELF based targets. Called @var{elf_record_gcc_switches},
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 9f790db0daf..673ba2935f9 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -235,6 +235,11 @@ static int verbose_only_flag;
static int print_subprocess_help;
+/* argc and argv used to call gcc. Necessary for
+ --record-gcc-command-line option. */
+static unsigned int driver_gcc_argc;
+static const char **driver_gcc_argv;
+
/* Linker suffix passed to -fuse-ld=... */
static const char *use_ld;
@@ -3724,6 +3729,28 @@ set_source_date_epoch_envvar ()
setenv ("SOURCE_DATE_EPOCH", source_date_epoch, 0);
}
+/* Set GCC_DRIVER_COMMAND_LINE enviromental variable that is later
+ used by -frecord-gcc-switches option. */
+
+static void
+set_driver_command_line_envvar ()
+{
+ unsigned int length = 0;
+ for (unsigned int i = 0; i < driver_gcc_argc; i++)
+ length += strlen (driver_gcc_argv[i]) + 1;
+
+ char *buffer = (char *)xmalloc (length);
+ char *ptr = buffer;
+ for (unsigned int i = 0; i < driver_gcc_argc; i++)
+ {
+ unsigned l = sprintf (ptr, i == 0 ? "%s" : " %s", driver_gcc_argv[i]);
+ ptr += l;
+ }
+
+ setenv ("GCC_DRIVER_COMMAND_LINE", buffer, 0);
+ free (buffer);
+}
+
/* Handle an option DECODED that is unknown to the option-processing
machinery. */
@@ -4289,6 +4316,10 @@ driver_handle_option (struct gcc_options *opts,
handle_foffload_option (arg);
break;
+ case OPT_frecord_gcc_switches:
+ set_driver_command_line_envvar ();
+ break;
+
default:
/* Various driver options need no special processing at this
point, having been handled in a prescan above or being
@@ -7387,6 +7418,7 @@ driver::main (int argc, char **argv)
set_progname (argv[0]);
expand_at_files (&argc, &argv);
+ set_commandline (argc, const_cast <const char **> (argv));
decode_argv (argc, const_cast <const char **> (argv));
global_initializations ();
build_multilib_strings ();
@@ -7430,6 +7462,15 @@ driver::set_progname (const char *argv0) const
xmalloc_set_program_name (progname);
}
+/* Keep command line for --record-gcc-command-line. */
+
+void
+driver::set_commandline (int argc, const char **argv) const
+{
+ driver_gcc_argc = argc;
+ driver_gcc_argv = argv;
+}
+
/* Expand any @ files within the command-line args,
setting at_file_supplied if any were expanded. */
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 70d8f08f059..cde77fbaad7 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -37,6 +37,7 @@ class driver
private:
void set_progname (const char *argv0) const;
+ void set_commandline (int argc, const char **argv) const;
void expand_at_files (int *argc, char ***argv) const;
void decode_argv (int argc, const char **argv);
void global_initializations ();
diff --git a/gcc/target.def b/gcc/target.def
index b5e82ff826e..9cb9dab60ab 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -746,40 +746,7 @@ DEFHOOK
(record_gcc_switches,
"Provides the target with the ability to record the gcc command line\n\
switches that have been passed to the compiler, and options that are\n\
-enabled. The @var{type} argument specifies what is being recorded.\n\
-It can take the following values:\n\
-\n\
-@table @gcctabopt\n\
-@item SWITCH_TYPE_PASSED\n\
-@var{text} is a command line switch that has been set by the user.\n\
-\n\
-@item SWITCH_TYPE_ENABLED\n\
-@var{text} is an option which has been enabled. This might be as a\n\
-direct result of a command line switch, or because it is enabled by\n\
-default or because it has been enabled as a side effect of a different\n\
-command line switch. For example, the @option{-O2} switch enables\n\
-various different individual optimization passes.\n\
-\n\
-@item SWITCH_TYPE_DESCRIPTIVE\n\
-@var{text} is either NULL or some descriptive text which should be\n\
-ignored. If @var{text} is NULL then it is being used to warn the\n\
-target hook that either recording is starting or ending. The first\n\
-time @var{type} is SWITCH_TYPE_DESCRIPTIVE and @var{text} is NULL, the\n\
-warning is for start up and the second time the warning is for\n\
-wind down. This feature is to allow the target hook to make any\n\
-necessary preparations before it starts to record switches and to\n\
-perform any necessary tidying up after it has finished recording\n\
-switches.\n\
-\n\
-@item SWITCH_TYPE_LINE_START\n\
-This option can be ignored by this target hook.\n\
-\n\
-@item SWITCH_TYPE_LINE_END\n\
-This option can be ignored by this target hook.\n\
-@end table\n\
-\n\
-The hook's return value must be zero. Other return values may be\n\
-supported in the future.\n\
+enabled.\n\
\n\
By default this hook is set to NULL, but an example implementation is\n\
provided for ELF based targets. Called @var{elf_record_gcc_switches},\n\
@@ -787,7 +754,7 @@ it records the switches as ASCII text inside a new, string mergeable\n\
section in the assembler output file. The name of the new section is\n\
provided by the @code{TARGET_ASM_RECORD_GCC_SWITCHES_SECTION} target\n\
hook.",
- int, (print_switch_type type, const char *text),
+ void, (void),
NULL)
/* The name of the section that the example ELF implementation of
diff --git a/gcc/target.h b/gcc/target.h
index 2f47c577d00..f01ce812c60 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -99,7 +99,7 @@ extern unsigned HOST_WIDE_INT by_pieces_ninsns (unsigned HOST_WIDE_INT,
typedef int (* print_switch_fn_type) (print_switch_type, const char *);
/* An example implementation for ELF targets. Defined in varasm.c */
-extern int elf_record_gcc_switches (print_switch_type type, const char *);
+extern void elf_record_gcc_switches (void);
/* Some places still assume that all pointer or address modes are the
standard Pmode and ptr_mode. These optimizations become invalid if
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 4c8be502c71..9df9d630e16 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -871,16 +871,7 @@ init_asm_output (const char *name)
if (flag_record_gcc_switches)
{
if (targetm.asm_out.record_gcc_switches)
- {
- /* Let the target know that we are about to start recording. */
- targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
- NULL);
- /* Now record the switches. */
- print_switch_values (targetm.asm_out.record_gcc_switches);
- /* Let the target know that the recording is over. */
- targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
- NULL);
- }
+ targetm.asm_out.record_gcc_switches ();
else
inform (UNKNOWN_LOCATION,
"%<-frecord-gcc-switches%> is not supported by "
diff --git a/gcc/varasm.c b/gcc/varasm.c
index dc6da6c0b5b..0dfb243adad 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see
#include "fold-const.h"
#include "stor-layout.h"
#include "varasm.h"
+#include "version.h"
#include "flags.h"
#include "stmt.h"
#include "expr.h"
@@ -7803,45 +7804,18 @@ output_object_blocks (void)
we want to emit NUL strings terminators into the object file we have to use
ASM_OUTPUT_SKIP. */
-int
-elf_record_gcc_switches (print_switch_type type, const char * name)
+void
+elf_record_gcc_switches ()
{
- switch (type)
- {
- case SWITCH_TYPE_PASSED:
- ASM_OUTPUT_ASCII (asm_out_file, name, strlen (name));
- ASM_OUTPUT_SKIP (asm_out_file, HOST_WIDE_INT_1U);
- break;
-
- case SWITCH_TYPE_DESCRIPTIVE:
- if (name == NULL)
- {
- /* Distinguish between invocations where name is NULL. */
- static bool started = false;
-
- if (!started)
- {
- section * sec;
-
- sec = get_section (targetm.asm_out.record_gcc_switches_section,
- SECTION_DEBUG
- | SECTION_MERGE
- | SECTION_STRINGS
- | (SECTION_ENTSIZE & 1),
- NULL);
- switch_to_section (sec);
- started = true;
- }
- }
+ section *sec = get_section (targetm.asm_out.record_gcc_switches_section,
+ SECTION_DEBUG | SECTION_MERGE
+ | SECTION_STRINGS | (SECTION_ENTSIZE & 1), NULL);
+ switch_to_section (sec);
- default:
- break;
- }
+ ASM_OUTPUT_ASCII (asm_out_file, version_string, strlen (version_string));
- /* The return value is currently ignored by the caller, but must be 0.
- For -fverbose-asm the return value would be the number of characters
- emitted into the assembler file. */
- return 0;
+ const char *cmdline = getenv ("GCC_DRIVER_COMMAND_LINE");
+ ASM_OUTPUT_ASCII (asm_out_file, cmdline, strlen (cmdline) + 1);
}
/* Emit text to declare externally defined symbols. It is needed to
--
2.25.1
next prev parent reply other threads:[~2020-03-05 8:54 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 16:41 [PATCH v2 0/3] Introduce a new GCC option, --record-gcc-command-line Egeyar Bagcioglu
2020-03-03 16:41 ` [PATCH v2 2/3] Introduce the gcc option --record-gcc-command-line Egeyar Bagcioglu
2020-03-03 16:41 ` [PATCH v2 1/3] Introduce dg-require-target-object-format Egeyar Bagcioglu
2020-03-03 16:41 ` [PATCH v2 3/3] Keep .GCC.command.line sections of LTO objetcs Egeyar Bagcioglu
2020-03-04 9:01 ` Richard Biener
2020-03-04 15:26 ` Egeyar Bagcioglu
2020-03-04 17:23 ` Martin Liška
2020-03-04 17:33 ` Jakub Jelinek
2020-03-04 17:42 ` Martin Liška
2020-03-04 17:47 ` Jakub Jelinek
2020-03-04 22:43 ` Egeyar Bagcioglu
2020-03-05 8:54 ` Martin Liška [this message]
2020-03-05 13:17 ` Egeyar Bagcioglu
2020-03-17 13:53 ` [stage1][PATCH] Change semantics of -frecord-gcc-switches and add -frecord-gcc-switches-format Martin Liška
2020-03-17 18:43 ` Egeyar Bagcioglu
2020-03-18 9:05 ` Martin Liška
2020-04-03 18:15 ` Egeyar Bagcioglu
2020-04-06 7:09 ` Martin Liška
2020-05-15 9:58 ` Martin Liška
2020-06-02 9:16 ` Martin Liška
2020-06-16 12:49 ` Martin Liška
2020-07-21 16:24 ` Qing Zhao
2020-07-23 10:07 ` Martin Liška
2020-07-23 15:01 ` Qing Zhao
2020-07-24 13:43 ` Martin Liška
2020-09-25 14:55 ` Martin Liška
2020-09-25 19:36 ` Qing Zhao
2020-10-27 10:56 ` Martin Liška
2020-11-10 20:53 ` Qing Zhao
2020-11-13 16:19 ` Jose E. Marchesi
2020-11-16 10:29 ` Martin Liška
2020-11-16 17:03 ` Qing Zhao
2020-11-20 9:49 ` Richard Biener
2020-11-23 8:59 ` Martin Liška
2020-11-23 11:00 ` Richard Biener
2020-11-23 13:02 ` Martin Liška
2020-11-23 14:52 ` Martin Liška
2020-11-25 13:48 ` Richard Biener
2020-11-26 13:55 ` Martin Liška
2020-12-02 10:46 ` Martin Liška
2020-12-03 13:12 ` Richard Biener
2020-12-04 8:08 ` Martin Liška
2020-12-04 9:03 ` Richard Biener
2020-12-04 13:30 ` Martin Liška
2020-12-04 13:34 ` Jakub Jelinek
2020-12-04 13:50 ` Richard Biener
2020-12-15 8:01 ` [PATCH 1/2] Remove Report keyword for options Martin Liška
2020-12-15 8:02 ` [PATCH 2/2] opts: Remove all usages of Report keyword Martin Liška
2020-12-15 19:43 ` Jeff Law
2020-12-15 21:21 ` Martin Liška
2020-12-15 19:42 ` [PATCH 1/2] Remove Report keyword for options Jeff Law
2020-12-16 11:46 ` Martin Liška
2021-01-06 14:21 ` [stage1][PATCH] Change semantics of -frecord-gcc-switches and add -frecord-gcc-switches-format Martin Liška
2021-01-14 9:03 ` Martin Liška
2021-01-22 13:33 ` Martin Liška
2021-01-29 13:35 ` Martin Liška
2021-02-05 9:34 ` [PATCH] " Martin Liška
2021-02-16 21:17 ` Qing Zhao
2021-02-18 9:18 ` Martin Liška
2021-03-01 12:07 ` Martin Liška
2021-03-12 12:39 ` Martin Liška
2021-01-15 19:14 ` [stage1][PATCH] " Alexandre Oliva
2021-01-18 9:03 ` Martin Liška
2020-03-04 19:39 ` [PATCH v2 3/3] Keep .GCC.command.line sections of LTO objetcs Egeyar Bagcioglu
2020-03-05 7:40 ` Richard Biener
2020-03-04 15:34 ` Andreas Schwab
2020-03-04 15:58 ` Egeyar Bagcioglu
2020-03-03 17:43 ` [PATCH v2 0/3] Introduce a new GCC option, --record-gcc-command-line Egeyar Bagcioglu
2020-03-03 22:57 ` Joseph Myers
2020-03-04 0:18 ` Fangrui Song
2020-03-04 16:28 ` Egeyar Bagcioglu
2020-03-04 16:51 ` Egeyar Bagcioglu
2020-03-05 7:36 ` Richard Biener
2020-03-05 13:43 ` Egeyar Bagcioglu
2020-03-04 9:07 ` 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=63cd2ac4-bd04-929d-98c3-2762da882e9c@suse.cz \
--to=mliska@suse.cz \
--cc=egeyar.bagcioglu@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=nickc@redhat.com \
--cc=richard.guenther@gmail.com \
/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).