public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Introduce a new GCC option, --record-gcc-command-line
@ 2020-03-03 16:41 Egeyar Bagcioglu
  2020-03-03 16:41 ` [PATCH v2 3/3] Keep .GCC.command.line sections of LTO objetcs Egeyar Bagcioglu
                   ` (5 more replies)
  0 siblings, 6 replies; 75+ messages in thread
From: Egeyar Bagcioglu @ 2020-03-03 16:41 UTC (permalink / raw)
  To: gcc-patches, mliska, segher; +Cc: Egeyar Bagcioglu

Hello,

I would like to propose the second version of the patches which introduce a compile option --record-gcc-command-line. When passed to gcc, it saves the command line invoking gcc into the produced object file. The option makes it trivial to trace back with which command a file was compiled and by which version of the gcc. It helps with debugging, reproducing bugs and repeating the build process.

The reviews addressed in this version include indentation changes, error handling and corner case coverage pointed out by Segher Boessenkool in the first two patches; while the new third patch is another corner case (lto) coverage requested by Martin Liska.

Although we discussed after the submission of the first version that there are several other options performing similar tasks, I believe we established that there is still a need for this specific functionality. Therefore, I am skipping in this email the comparison between this option and the existing options with similarities.

This functionality operates as the following: It saves gcc's argv into a temporary file, and passes --record-gcc-command-line <tempfilename> to cc1 or cc1plus. The functionality of the backend is implemented via a hook. This patch includes an example implementation of the hook for elf targets: elf_record_gcc_command_line function. This function reads the given file and writes gcc's version and the command line into a mergeable string section, .GCC.command.line. It creates one entry per invocation. By doing so, it makes it clear which options were used together in a single gcc invocation, even after linking.

Here is an *example usage* of the option:
[egeyar@localhost save-commandline]$ gcc main.c --record-gcc-command-line
[egeyar@localhost save-commandline]$ readelf -p .GCC.command.line a.out

String dump of section '.GCC.command.line':
  [     0]  10.0.1 20200227 (experimental) : gcc main.c --record-gcc-command-line


The following is a *second example* calling g++ with -save-temps and a repetition of options, where --save-temps saves the intermediate file, main.cmdline in this case. You can see that the options are recorded unprocessed:

[egeyar@localhost save-commandline]$ g++ main.c -save-temps --record-gcc-command-line -O0 -O2 -O3 -DFORTIFY=2 --record-gcc-command-line
[egeyar@localhost save-commandline]$ readelf -p .GCC.command.line a.out

String dump of section '.GCC.command.line':
  [     0]  10.0.1 20200227 (experimental) : g++ main.c -save-temps --record-gcc-command-line -O0 -O2 -O3 -DFORTIFY=2 --record-gcc-command-line


The first patch of this three-patch-series only extends the testsuite machinery, while the second patch implements the functionality and adds a test case for it. The third patch that alters libiberty is to make sure the .GCC.command.line section in LTO objects survive the linking and appear in the linked object.

In addition to the new test case, I built binutils as my test case after passing this option to CFLAGS. The added .GCC.command.line section of ld.bfd listed many compile commands as expected. Tested on x86_64-pc-linux-gnu.

Please review the patches, let me know what you think and apply if appropriate.

Regards
Egeyar

Egeyar Bagcioglu (3):
  Introduce dg-require-target-object-format
  Introduce the gcc option --record-gcc-command-line
  Keep .GCC.command.line sections of LTO objetcs.

 gcc/common.opt                                     |  4 +++
 gcc/config/elfos.h                                 |  5 +++
 gcc/doc/tm.texi                                    | 22 ++++++++++++
 gcc/doc/tm.texi.in                                 |  4 +++
 gcc/gcc.c                                          | 41 ++++++++++++++++++++++
 gcc/gcc.h                                          |  1 +
 gcc/target.def                                     | 30 ++++++++++++++++
 gcc/target.h                                       |  3 ++
 .../c-c++-common/record-gcc-command-line.c         |  8 +++++
 gcc/testsuite/lib/target-supports-dg.exp           | 11 ++++++
 gcc/toplev.c                                       | 13 +++++++
 gcc/varasm.c                                       | 40 +++++++++++++++++++++
 libiberty/simple-object.c                          |  3 ++
 13 files changed, 185 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/record-gcc-command-line.c

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2021-03-12 12:39 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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
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 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 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

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).