From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119686 invoked by alias); 3 Mar 2020 16:41:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 119677 invoked by uid 89); 3 Mar 2020 16:41:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_3,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=H*r:8.14.4, submission, cc1plus X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 16:41:05 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 023GOdRT043840; Tue, 3 Mar 2020 16:41:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2020-01-29; bh=Q0neQsTZNf7c+BcsvQMTfcwy0HhvadX7JXqQ2nXEPXE=; b=nGTNdS1zEHRTzh9sikOW2tC6jPTVWBzRLbzeZQxmb/FoA0KJUnsT9VVbn8oWYCjxLuWD 2cK2cy3oS27Y2PEL7sY9arDZLmR5YdhxRPK9QkOiZ0nUgMlta6jVDqwE6pUCiKIlhX25 a+UPgOoYa02Y+8UUVIA0u1ZHflGMfQqkc0NhwRM6OhzuA5XdOOIC8bZZCwHV+2qBmqZ9 VCR3+g7nbzh3kuEFE24k7Kidk91JOlxo0xwTJQOTqa3YrqO9hSnYQXuzM5WgnL4ul13k Nez5aGs/hZdS5gPmcZ3C7AGN27aHpHOkIETnkuTT5KZQAFQweTDw+2EEpvxEw35hZSHp yA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2yffwqrfen-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:03 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 023GNW27142310; Tue, 3 Mar 2020 16:41:03 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2yg1gxt7um-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:03 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 023Gf1wq002867; Tue, 3 Mar 2020 16:41:01 GMT Received: from localhost.us.oracle.com (/10.211.14.224) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Mar 2020 08:41:00 -0800 From: Egeyar Bagcioglu To: gcc-patches@gcc.gnu.org, mliska@suse.cz, segher@kernel.crashing.org Cc: Egeyar Bagcioglu Subject: [PATCH v2 0/3] Introduce a new GCC option, --record-gcc-command-line Date: Tue, 03 Mar 2020 16:41:00 -0000 Message-Id: <1583246660-6390-1-git-send-email-egeyar.bagcioglu@oracle.com> X-IsSubscribed: yes X-SW-Source: 2020-03/txt/msg00137.txt 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 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