From patchwork Tue Mar 3 14:44:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Egeyar Bagcioglu X-Patchwork-Id: 1248518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520550-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=Dzc+6vwg; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=dZboc4Oy; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48X2pV2Z2sz9sR4 for ; Wed, 4 Mar 2020 03:41:38 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=EW1TxfCnzeLp58ga1G4hV7TThVzZcf5ToyjqloLed5DDxe0eZ++6y CJWlO3A33LIVgTTZKBABvz/019/0WOZbZdWcgZ4MZYtDdrOc26wwce5rdod4UsLx h3XG91uO/GYod5xiom26zLO/IOzBQUW9X/jL5hYY6ahzP9Y+urVIhA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=AT2uLyHzaG/0Zd+xZmxcEcyJqTE=; b=Dzc+6vwgHAdwRW2cQe7u BH3dZVMXvILNRttMm3GuPdoEf6Jro2aqrJ+AhhzYzJbGng/wwHP7EmUxYu2V9gGF U4FfaJgcZAkRFt2muRJugPU0J128m0iJJtQ88J0vNnSipDmGXndwMD0KPYgiaIBZ FX0dFZiJ/nUMMaJ1AfmocRY= Received: (qmail 120103 invoked by alias); 3 Mar 2020 16:41:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 120024 invoked by uid 89); 3 Mar 2020 16:41:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=$args, H*r:8.13.8 X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 16:41:08 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 023GNRZK065951; Tue, 3 Mar 2020 16:41:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=shzWU0AjiVnzKUUozE2ajjjNawch1ORnfHVUFfi63nA=; b=dZboc4OyRetF9SiVhSk3uc7r87FlqUFyK8l8S8PldhXobTTEeKT3QHHXY00KMQmmoKDw N7gDbQ5xD089dSy53IlBWsy6jon9+VdlSiMj4fPrztI41iQ4PncXu04inZBTexxSLjVg 8GQkvEQ4kcQq9izMfVcuSvPMHq058DzajXqs+PhZYjC0e/EkXXG0WtP0UhLvVwW/2Gi/ gx/nXWCfA5V0FhZrqEcJs6Jx7M4ba5w8mVhOpfhNxnSc29qF6IcE+GsTisNYzoxm30SC S4DI17vtqBnsZD2bF0ZWuf507NO29+/zsM8wgpG/E6wtRAbbAuAbxWwXUhpsCCXjWDy7 gQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2yghn34ae7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:06 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 023GNH7r029969; Tue, 3 Mar 2020 16:41:06 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2yg1rmf8g6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:05 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 023Gf4EM022303; Tue, 3 Mar 2020 16:41:04 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:04 -0800 From: Egeyar Bagcioglu To: gcc-patches@gcc.gnu.org, mliska@suse.cz, segher@kernel.crashing.org Cc: Egeyar Bagcioglu Subject: [PATCH v2 1/3] Introduce dg-require-target-object-format Date: Tue, 3 Mar 2020 15:44:18 +0100 Message-Id: <1583246660-6390-2-git-send-email-egeyar.bagcioglu@oracle.com> In-Reply-To: <1583246660-6390-1-git-send-email-egeyar.bagcioglu@oracle.com> References: <1583246660-6390-1-git-send-email-egeyar.bagcioglu@oracle.com> X-IsSubscribed: yes gcc/testsuite/: 2020-02-27 Egeyar Bagcioglu * lib/target-supports-dg.exp (dg-require-target-object-format): New. --- gcc/testsuite/lib/target-supports-dg.exp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gcc/testsuite/lib/target-supports-dg.exp b/gcc/testsuite/lib/target-supports-dg.exp index 2a21424..9678a66 100644 --- a/gcc/testsuite/lib/target-supports-dg.exp +++ b/gcc/testsuite/lib/target-supports-dg.exp @@ -164,6 +164,17 @@ proc dg-require-dll { args } { set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] } +# If this target does not produce the given object format skip this test. + +proc dg-require-target-object-format { args } { + if [string equal [gcc_target_object_format] [lindex $args 1] ] { + return + } + + upvar dg-do-what dg-do-what + set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] +} + # If this host does not support an ASCII locale, skip this test. proc dg-require-ascii-locale { args } { From patchwork Tue Mar 3 14:44:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Egeyar Bagcioglu X-Patchwork-Id: 1248521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520551-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=qKNbZcPP; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=XB3AYpTb; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48X2pk1Y5sz9sR4 for ; Wed, 4 Mar 2020 03:41:49 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=sKr3Kgqdn9iguWgnb3MDZnkC3b9pfezkuYPxlzOnVaKLamnPOrRsK JkkFal7ZlOVXsoYetAHYDii3q2KuVf6IXvIsbvGtFLNc3gEE0mUOSWt7WpDs61Al UnOzmNAushN8rZEpqCUOUnANGHer8mrX3rh26ftfDmf+wyVMxAms/c= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=rHZjd96ys2E5EdhgTny2bN/m1L0=; b=qKNbZcPP2F+7Uirpi21B 0Sj8DlWB+og3vwkk/9kzBR/nJOTdHP4/w1Y0tF6A00nG1lSjgGOeJxzgG1WqXqvE qK/bKxRD+TXt77Y5EN/Na1fTIuO+2tt1KuKHkeBf59KYfFHfP7rbkm+7P1lcSkKe T5R0e0E2ZgQ0Fe4xsXp7oVA= Received: (qmail 120435 invoked by alias); 3 Mar 2020 16:41:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 120361 invoked by uid 89); 3 Mar 2020 16:41:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=fprofilearcs, fprofile-arcs, need 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:08 +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 023GOdvL043799; Tue, 3 Mar 2020 16:41:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=iTcB/eqXFyzXQ+BkS9A6o0jD3uC+ezFT7kGxmVHmDgk=; b=XB3AYpTb5jcSLeVZhs5nthwoRTehxbTIfzDIXYzaGKCzG2a9XrYMiQPR9JWcGinA76aq ssy3MC/Fl487C/UAdBq39wYSrg7qF1VUG4i4ttny2ai25FusvFPiT647d4EzvAJ7z/3m Kex3Va21UpIj31qIrJo2IwNGBMbBgwlXOxAsD+VIOReChTkkAUySD+IifWiz6stLIJ0+ eTSFHqECfpeJsqiVlKb3RrLYoCkTMLAmbxKqFi9Vz4CIHCqlN/pYVpXd4drqfXrc5AY+ wxbGlPNEfP+tCFyOWnfIf9i/9+/ruUdWWaVUvmrmIUiJ3nEzQ2HbUIyAahfQyKyUJSy8 sA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2yffwqrff2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:06 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 023GN6e7145083; Tue, 3 Mar 2020 16:41:06 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2yg1em5bd9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:05 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 023Gf45X004032; Tue, 3 Mar 2020 16:41:04 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:04 -0800 From: Egeyar Bagcioglu To: gcc-patches@gcc.gnu.org, mliska@suse.cz, segher@kernel.crashing.org Cc: Egeyar Bagcioglu Subject: [PATCH v2 2/3] Introduce the gcc option --record-gcc-command-line Date: Tue, 3 Mar 2020 15:44:19 +0100 Message-Id: <1583246660-6390-3-git-send-email-egeyar.bagcioglu@oracle.com> In-Reply-To: <1583246660-6390-1-git-send-email-egeyar.bagcioglu@oracle.com> References: <1583246660-6390-1-git-send-email-egeyar.bagcioglu@oracle.com> X-IsSubscribed: yes gcc: 2020-02-27 Egeyar Bagcioglu * common.opt (--record-gcc-command-line): New option. * config/elfos.h (TARGET_ASM_RECORD_GCC_COMMAND_LINE): Define as elf_record_gcc_command_line. * doc/tm.texi: Regenerate. * doc/tm.texi.in (TARGET_ASM_RECORD_GCC_COMMAND_LINE): Introduce. (TARGET_ASM_RECORD_GCC_COMMAND_LINE_SECTION): Likewise. * gcc.c (_gcc_argc): New static variable. (_gcc_argv): Likewise. (record_gcc_command_line_spec_function): New function. (cc1_options): Handle --record-gcc-command-line. (static_spec_functions): Add record_gcc_command_line_spec_function with pseudo name record-gcc-command-line. (driver::main): Call set_commandline. (driver::set_commandline): Declare. * gcc.h (driver::set_commandline): Declare. * target.def (record_gcc_command_line): A new hook. (record_gcc_command_line_section): A new hookpod. * target.h (elf_record_gcc_command_line): Declare. * toplev.c (init_asm_output): Check for gcc_command_line_file and call record_gcc_command_line if necessary. * varasm.c: Include "version.h". (elf_record_gcc_command_line): Define. gcc/testsuite: 2020-02-27 Egeyar Bagcioglu * c-c++-common/record-gcc-command-line.c: New. --- 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/toplev.c | 13 +++++++ gcc/varasm.c | 40 +++++++++++++++++++++ 11 files changed, 171 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/record-gcc-command-line.c diff --git a/gcc/common.opt b/gcc/common.opt index fa9da50..1bacded 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -391,6 +391,10 @@ Driver Alias(print-sysroot-headers-suffix) -profile Common Alias(p) +-record-gcc-command-line +Common NoDriverArg Separate Var(gcc_command_line_file) +Record the command line making this gcc call in the produced object file. + -save-temps Driver Alias(save-temps) diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h index 74a3eaf..1d5f447 100644 --- a/gcc/config/elfos.h +++ b/gcc/config/elfos.h @@ -462,6 +462,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #undef TARGET_ASM_RECORD_GCC_SWITCHES #define TARGET_ASM_RECORD_GCC_SWITCHES elf_record_gcc_switches +/* Allow the use of the --record-gcc-command-line switch via the + elf_record_gcc_command_line function defined in varasm.c. */ +#undef TARGET_ASM_RECORD_GCC_COMMAND_LINE +#define TARGET_ASM_RECORD_GCC_COMMAND_LINE elf_record_gcc_command_line + /* A C statement (sans semicolon) to output to the stdio stream STREAM any text necessary for declaring the name of an external symbol named NAME which is referenced in this compilation but not defined. diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 19985ad..0a8ef03 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -8113,6 +8113,28 @@ ELF implementation of the @code{TARGET_ASM_RECORD_GCC_SWITCHES} target hook. @end deftypevr +@deftypefn {Target Hook} int TARGET_ASM_RECORD_GCC_COMMAND_LINE () +Provides the target with the ability to record the command line that +has been passed to the compiler driver. The @var{gcc_command_line_file} +variable specifies the intermediate file that holds the command line. + +The return value must be zero. Other return values may be supported +in the future. + +By default this hook is set to NULL, but an example implementation, +@var{elf_record_gcc_command_line}, is provided for ELF based targets. +it records the command line as ASCII text inside a new, mergable string +section in the assembler output file. The name of the new section is +provided by the @code{TARGET_ASM_RECORD_GCC_COMMAND_LINE_SECTION} +target hook. +@end deftypefn + +@deftypevr {Target Hook} {const char *} TARGET_ASM_RECORD_GCC_COMMAND_LINE_SECTION +This is the name of the section that will be created by the example +ELF implementation of the @code{TARGET_ASM_RECORD_GCC_COMMAND_LINE} +target hook. +@end deftypevr + @need 2000 @node Data Output @subsection Output of Data diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 1a16150..174840b 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -5192,6 +5192,10 @@ It must not be modified by command-line option processing. @hook TARGET_ASM_RECORD_GCC_SWITCHES_SECTION +@hook TARGET_ASM_RECORD_GCC_COMMAND_LINE + +@hook TARGET_ASM_RECORD_GCC_COMMAND_LINE_SECTION + @need 2000 @node Data Output @subsection Output of Data diff --git a/gcc/gcc.c b/gcc/gcc.c index 9f790db..3a9d6bf 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 int _gcc_argc; +static const char **_gcc_argv; + /* Linker suffix passed to -fuse-ld=... */ static const char *use_ld; @@ -408,6 +413,7 @@ static const char *replace_extension_spec_func (int, const char **); static const char *greater_than_spec_func (int, const char **); static const char *debug_level_greater_than_spec_func (int, const char **); static const char *find_fortran_preinclude_file (int, const char **); +static const char *record_gcc_command_line_spec_function (int, const char **); static char *convert_white_space (char *); /* The Specs Language @@ -1157,6 +1163,7 @@ static const char *cc1_options = %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\ %{fsyntax-only:-o %j} %{-param*}\ %{coverage:-fprofile-arcs -ftest-coverage}\ + %{-record-gcc-command-line:--record-gcc-command-line %:record-gcc-command-line(%g.cmdline) %<-record-gcc-command-line}\ %{fprofile-arcs|fprofile-generate*|coverage:\ %{!fprofile-update=single:\ %{pthread:-fprofile-update=prefer-atomic}}}"; @@ -1648,6 +1655,7 @@ static const struct spec_function static_spec_functions[] = { "gt", greater_than_spec_func }, { "debug-level-gt", debug_level_greater_than_spec_func }, { "fortran-preinclude-file", find_fortran_preinclude_file}, + { "record-gcc-command-line", record_gcc_command_line_spec_function}, #ifdef EXTRA_SPEC_FUNCTIONS EXTRA_SPEC_FUNCTIONS #endif @@ -7387,6 +7395,7 @@ driver::main (int argc, char **argv) set_progname (argv[0]); expand_at_files (&argc, &argv); + set_commandline (argc, const_cast (argv)); decode_argv (argc, const_cast (argv)); global_initializations (); build_multilib_strings (); @@ -7430,6 +7439,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 +{ + _gcc_argc = argc; + _gcc_argv = argv; +} + /* Expand any @ files within the command-line args, setting at_file_supplied if any were expanded. */ @@ -10070,6 +10088,29 @@ find_fortran_preinclude_file (int argc, const char **argv) return result; } +/* The option --record-gcc-command-line saves the command line options given to + gcc into the created object file. Those options are passed to the backends via + an intermediate file whose name is generated while the spec is evaluated. This + function takes that filename as an argument, writes to it, and returns it as a + single string. */ + +static const char * +record_gcc_command_line_spec_function(int argc ATTRIBUTE_UNUSED, const char **argv) +{ + const char *filename = argv[0]; + FILE *out = fopen (filename, "w"); + if (!out) + error ("cannot open %s: %m", filename); + + fprintf (out, "%s", _gcc_argv[0]); + for (int i = 1; i < _gcc_argc; i += 1) + { + fprintf (out, " %s", _gcc_argv[i]); + } + + fclose (out); + return filename; +} /* Insert backslash before spaces in ORIG (usually a file path), to avoid being broken by spec parser. diff --git a/gcc/gcc.h b/gcc/gcc.h index 70d8f08..cde77fb 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 b5e82ff..4608119 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -801,6 +801,36 @@ ELF implementation of the @code{TARGET_ASM_RECORD_GCC_SWITCHES} target\n\ hook.", const char *, ".GCC.command.line") +/* Output a record of the command line that have been passed to gcc. */ +DEFHOOK +(record_gcc_command_line, + "Provides the target with the ability to record the command line that\n\ +has been passed to the compiler driver. The @var{gcc_command_line_file}\n\ +variable specifies the intermediate file that holds the command line.\n\ +\n\ +The return value must be zero. Other return values may be supported\n\ +in the future.\n\ +\n\ +By default this hook is set to NULL, but an example implementation,\n\ +@var{elf_record_gcc_command_line}, is provided for ELF based targets.\n\ +it records the command line as ASCII text inside a new, mergable string\n\ +section in the assembler output file. The name of the new section is\n\ +provided by the @code{TARGET_ASM_RECORD_GCC_COMMAND_LINE_SECTION}\n\ +target hook.", + int, (), + NULL) + +/* The name of the section that the example ELF implementation of + record_gcc_switches will use to store the information. Target + specific versions of record_gcc_switches may or may not use + this information. */ +DEFHOOKPOD +(record_gcc_command_line_section, + "This is the name of the section that will be created by the example\n\ +ELF implementation of the @code{TARGET_ASM_RECORD_GCC_COMMAND_LINE}\n\ +target hook.", + const char *, ".GCC.command.line") + /* Output the definition of a section anchor. */ DEFHOOK (output_anchor, diff --git a/gcc/target.h b/gcc/target.h index 2f47c57..66f7064 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -101,6 +101,9 @@ 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 *); +/* An example implementation for ELF targets. Defined in varasm.c */ +extern int elf_record_gcc_command_line (); + /* Some places still assume that all pointer or address modes are the standard Pmode and ptr_mode. These optimizations become invalid if the target actually supports multiple different modes. For now, diff --git a/gcc/testsuite/c-c++-common/record-gcc-command-line.c b/gcc/testsuite/c-c++-common/record-gcc-command-line.c new file mode 100644 index 0000000..2fdce4f --- /dev/null +++ b/gcc/testsuite/c-c++-common/record-gcc-command-line.c @@ -0,0 +1,8 @@ +/* Test the option "--record-gcc-command-line". + { dg-do compile } + { dg-require-target-object-format "elf" } + { dg-options "-O2 -g --record-gcc-command-line" } */ + +int main () { return 0; } + +/* { dg-final { scan-assembler "-O2 -g --record-gcc-command-line"} } */ diff --git a/gcc/toplev.c b/gcc/toplev.c index 4c8be50..d588a3d 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -868,6 +868,19 @@ init_asm_output (const char *name) { targetm.asm_out.file_start (); + if (gcc_command_line_file) + { + if (targetm.asm_out.record_gcc_command_line) + { + /* Record the command line. */ + targetm.asm_out.record_gcc_command_line (); + } + else + inform (UNKNOWN_LOCATION, + "--record-gcc-command-line is not supported by " + "the current target"); + } + if (flag_record_gcc_switches) { if (targetm.asm_out.record_gcc_switches) diff --git a/gcc/varasm.c b/gcc/varasm.c index dc6da6c..9c8e477 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" @@ -7844,6 +7845,45 @@ elf_record_gcc_switches (print_switch_type type, const char * name) return 0; } +/* This function provides a possible implementation of the + TARGET_ASM_RECORD_GCC_COMMAND_LINE target hook for ELF targets. When + triggered by --record-gcc-command-line it creates a new mergeable + string section in the assembler output file called + TARGET_ASM_RECORD_GCC_COMMAND_LINE_SECTION which contains the command line + in ASCII format. */ + +int +elf_record_gcc_command_line () +{ + char cmdline[256]; + section *sec; + sec = get_section (targetm.asm_out.record_gcc_command_line_section, + SECTION_DEBUG | SECTION_MERGE + | SECTION_STRINGS | (SECTION_ENTSIZE & 1), + NULL); + switch_to_section (sec); + + ASM_OUTPUT_ASCII (asm_out_file, version_string, strlen(version_string)); + + FILE *out_stream = fopen (gcc_command_line_file, "r"); + if (!out_stream) + error ("cannot open %s: %m", gcc_command_line_file); + + ASM_OUTPUT_ASCII (asm_out_file, " : ", 3); + ssize_t cmdline_length; + while ((cmdline_length = fread (cmdline, 1, 256, out_stream))) + ASM_OUTPUT_ASCII (asm_out_file, cmdline, cmdline_length); + + fclose (out_stream); + + /* End the line. */ + cmdline[0] = 0; + ASM_OUTPUT_ASCII (asm_out_file, cmdline, 1); + + /* The return value is currently ignored by the caller, but must be 0. */ + return 0; +} + /* Emit text to declare externally defined symbols. It is needed to properly support non-default visibility. */ void From patchwork Tue Mar 3 14:44:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Egeyar Bagcioglu X-Patchwork-Id: 1248517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520549-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=szvQUfJI; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=dmrsH7Rf; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48X2pG42Lcz9sR4 for ; Wed, 4 Mar 2020 03:41:26 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=w+ZNGyb3rnRuBnrtSDfc6Lx1DxIhT4j8iHZz2N/Q4Q6ne90QDW7my SCxNRqNlaJCSIba/MqaKEN5RezJQmKDfygsbuMtja+O5P6NxmgaGMD8CnN1+hZSV rVoX0RUsyHvfrs0Onlv0J6/xEu3i7xlpEotjswLsSw5ypGPM1Dow3U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=Z1zo7tHLKsarYxyL6CcvCGA8dd8=; b=szvQUfJIJsKeSuTDwtvt 8q9f4SPQ9dyXbkFHh55X3fJESn1JWEUDM6OLajKTN+fUhKHhL6z9sTtWFiTp3Itn V1kJNjU+vwU6ZOd1jcz4lD4kdk3j3CzcW8yLlelK0J2SUDXH6dP7UjPZRfhgoOpQ u+I/FI4XM2ARecPtOwS0uWo= Received: (qmail 120092 invoked by alias); 3 Mar 2020 16:41:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 120030 invoked by uid 89); 3 Mar 2020 16:41:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy= X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 16:41:08 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 023GNRrZ065955; Tue, 3 Mar 2020 16:41:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=0Jz9LsnPsVLsFs7TrDn3Niq6xGDlByIWRrILN8sJIbw=; b=dmrsH7Rfyno+f6MbCPuzexW3GQV4vr6+nXLcpMtKUrqD3niKhP1JQGiX/nBfw12Y2CFd 8M92TnNSGbAfTKIp79DXui2ZyQkE04aklEvmOx/LrVw6pummtMvFnLx+n3K6KyKsL9lm UbKsPHz3VIRMwJrk80uUTseheIlwT2uq6J/acOI4HRXnKoQodfudNxQX6e7dbz9fKWfB cOwevRrtglmCpmDQSQn72ZHeSakffd4y8wbKndhIIDOi2ZhvQAZW8cNc+eXIsr0XRI0i BcNFHQYnJ17uY4f9iYwOUCkH27nAkzXVt080oQHvTUaF6eMA2PHVfoCfAp6mQXF0jR6z KQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2yghn34ae2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:06 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 023GNCJV029267; Tue, 3 Mar 2020 16:41:05 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2yg1rmf8ga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Mar 2020 16:41:05 +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 023Gf5cR002928; Tue, 3 Mar 2020 16:41:05 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:04 -0800 From: Egeyar Bagcioglu To: gcc-patches@gcc.gnu.org, mliska@suse.cz, segher@kernel.crashing.org Cc: Egeyar Bagcioglu Subject: [PATCH v2 3/3] Keep .GCC.command.line sections of LTO objetcs. Date: Tue, 3 Mar 2020 15:44:20 +0100 Message-Id: <1583246660-6390-4-git-send-email-egeyar.bagcioglu@oracle.com> In-Reply-To: <1583246660-6390-1-git-send-email-egeyar.bagcioglu@oracle.com> References: <1583246660-6390-1-git-send-email-egeyar.bagcioglu@oracle.com> X-IsSubscribed: yes This patch is for .GCC.command.line sections in LTO objects to be copied into the final objects as in the following example: [egeyar@localhost lto]$ gcc -flto -O3 demo.c -c -g --record-gcc-command-line [egeyar@localhost lto]$ gcc -flto -O2 demo2.c -c -g --record-gcc-command-line -DFORTIFY=2 [egeyar@localhost lto]$ gcc demo.o demo2.o -o a.out [egeyar@localhost lto]$ readelf -p .GCC.command.line a.out String dump of section '.GCC.command.line': [ 0] 10.0.1 20200227 (experimental) : gcc -flto -O3 demo.c -c -g --record-gcc-command-line [ 56] 10.0.1 20200227 (experimental) : gcc -flto -O2 demo2.c -c -g --record-gcc-command-line -DFORTIFY=2 Regards Egeyar libiberty: 2020-02-27 Egeyar Bagcioglu * simple-object.c (handle_lto_debug_sections): Name ".GCC.command.line" among debug sections to be copied over from lto objects. --- libiberty/simple-object.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c index d9c648a..3b3ca9c 100644 --- a/libiberty/simple-object.c +++ b/libiberty/simple-object.c @@ -298,6 +298,9 @@ handle_lto_debug_sections (const char *name, int rename) COMDAT sections in objects produced by GCC. */ else if (strcmp (name, ".comment") == 0) return strcpy (newname, name); + /* Copy over .GCC.command.line section under the same name if present. */ + else if (strcmp (name, ".GCC.command.line") == 0) + return strcpy (newname, name); free (newname); return NULL; }