On 3/3/20 3:44 PM, Egeyar Bagcioglu wrote:
Hello,

Hi.


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.

Great, thanks for working on that.
Based on the mentioned disadvantages of -frecord-gcc-switches, where each 
option entry is put into a mergeable section and
so one can't disambiguate in between multiple command line options, I would 
suggest to replace -frecord-gcc-switches
functionality with what --record-gcc-command-line does. Moreover, looking at 
clang:
https://reviews.llvm.org/D54487, their current implementation of 
-frecord-gcc-switches does the very same:

$ clang main.c -frecord-gcc-switches -c
$ readelf -p .GCC.command.line main.o

String dump of section '.GCC.command.line':
  [     1]  /usr/bin/clang-9.0.1 main.c -frecord-command-line -c

One additional advantage is that driver options also catch macros (like 
-D_FORTIFY_SOURCE), which
is also what clang does.
It's question to Nick who originally implemented the option. Nick, are you fine 
with that?
If I'm correct you're using the annobin plugin and this can help you to replace 
it?


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.

One small nit: I would not send in 3 parts, as the first and last one are just 
one hunks.

Martin


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


Reply via email to