From patchwork Wed Oct 12 04:51:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 119145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D1861B6F64 for ; Wed, 12 Oct 2011 15:52:02 +1100 (EST) Received: (qmail 14597 invoked by alias); 12 Oct 2011 04:51:57 -0000 Received: (qmail 14579 invoked by uid 22791); 12 Oct 2011 04:51:55 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Oct 2011 04:51:39 +0000 Received: from wpaz17.hot.corp.google.com (wpaz17.hot.corp.google.com [172.24.198.81]) by smtp-out.google.com with ESMTP id p9C4pbp0015136 for ; Tue, 11 Oct 2011 21:51:37 -0700 Received: from vcbfl17 (vcbfl17.prod.google.com [10.220.204.81]) by wpaz17.hot.corp.google.com with ESMTP id p9C4lqiD010371 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 11 Oct 2011 21:51:36 -0700 Received: by vcbfl17 with SMTP id fl17so364584vcb.7 for ; Tue, 11 Oct 2011 21:51:35 -0700 (PDT) Received: by 10.151.157.21 with SMTP id j21mr12577481ybo.89.1318395095898; Tue, 11 Oct 2011 21:51:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.151.157.21 with SMTP id j21mr12577469ybo.89.1318395095751; Tue, 11 Oct 2011 21:51:35 -0700 (PDT) Received: by 10.151.107.3 with HTTP; Tue, 11 Oct 2011 21:51:35 -0700 (PDT) In-Reply-To: References: <20111008114155.GP19412@tyan-ft48-01.lab.bos.redhat.com> <20111009092840.GR19412@tyan-ft48-01.lab.bos.redhat.com> Date: Wed, 12 Oct 2011 12:51:35 +0800 Message-ID: Subject: Re: [google] record compiler options to .note sections From: Dehao Chen To: Cary Coutant Cc: Xinliang David Li , Jakub Jelinek , gcc-patches@gcc.gnu.org, Rong Xu X-System-Of-Record: true X-IsSubscribed: yes 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 Attached is the new patch. Bootstrapped on x86_64, no regressions. gcc/ChangeLog.google-4_6: 2011-10-08 Dehao Chen Add a flag (-frecord-gcc-switches-in-elf) to record compiler command line options to .gnu.switches.text sections of the object file. * coverage.c (write_opts_to_asm): Write the options to .gnu.switches.text sections. * common.opt: Ditto. * opts.h: Ditto. gcc/c-family/ChangeLog.google-4_6: 2011-10-08 Dehao Chen * c-opts.c (c_common_parse_file): Write the options to .gnu.switches.text sections. gcc/testsuite/ChangeLog.google-4_6: 2011-10-08 Dehao Chen * gcc.dg/record-gcc-switches-in-elf-1.c: New test. cselib.o : cselib.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ $(REGS_H) hard-reg-set.h $(FLAGS_H) insn-config.h $(RECOG_H) \ $(EMIT_RTL_H) $(DIAGNOSTIC_CORE_H) output.h $(FUNCTION_H) $(TREE_PASS_H) \ On Wed, Oct 12, 2011 at 2:12 AM, Cary Coutant wrote: >> How about .gnu.switches.text.quote_paths? > > Sounds good to me. > > -cary > Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 179836) +++ gcc/doc/invoke.texi (working copy) @@ -391,6 +391,7 @@ -fpmu-profile-generate=@var{pmuoption} @gol -fpmu-profile-use=@var{pmuoption} @gol -freciprocal-math -fregmove -frename-registers -freorder-blocks @gol +-frecord-gcc-switches-in-elf@gol -freorder-blocks-and-partition -freorder-functions @gol -frerun-cse-after-loop -freschedule-modulo-scheduled-loops @gol -fripa -fripa-disallow-asm-modules -fripa-disallow-opt-mismatch @gol @@ -8170,6 +8171,11 @@ number of times it is called. The params variable "note-cgraph-section-edge-threshold" can be used to only list edges above a certain threshold. + +@item -frecord-gcc-switches-in-elf +@opindex frecord-gcc-switches-in-elf +Record the command line options in the .gnu.switches.text elf section for sample +based LIPO to do module grouping. @end table The following options control compiler behavior regarding floating Index: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 179836) +++ gcc/c-family/c-opts.c (working copy) @@ -1109,6 +1109,8 @@ for (;;) { c_finish_options (); + if (flag_record_gcc_switches_in_elf && i == 0) + write_opts_to_asm (); pch_init (); set_lipo_c_parsing_context (parse_in, i, verbose); push_file_scope (); Index: gcc/testsuite/gcc.dg/record-gcc-switches-in-elf-1.c =================================================================== --- gcc/testsuite/gcc.dg/record-gcc-switches-in-elf-1.c (revision 0) +++ gcc/testsuite/gcc.dg/record-gcc-switches-in-elf-1.c (revision 0) @@ -0,0 +1,16 @@ +/* { dg-do compile} */ +/* { dg-options "-frecord-gcc-switches-in-elf -Dtest -dA" } */ + +void foobar(int); + +void +foo (void) +{ + int i; + for (i = 0; i < 100; i++) + { + foobar(i); + } +} + +/* { dg-final { scan-assembler-times "Dtest" 1 } } */ Index: gcc/opts.h =================================================================== --- gcc/opts.h (revision 179836) +++ gcc/opts.h (working copy) @@ -381,4 +381,5 @@ extern void set_struct_debug_option (struct gcc_options *opts, location_t loc, const char *value); +extern void write_opts_to_asm (void); #endif Index: gcc/coverage.c =================================================================== --- gcc/coverage.c (revision 179836) +++ gcc/coverage.c (working copy) @@ -55,6 +55,7 @@ #include "diagnostic-core.h" #include "intl.h" #include "l-ipo.h" +#include "dwarf2asm.h" #include "gcov-io.h" #include "gcov-io.c" @@ -2146,4 +2147,69 @@ return 0; } +/* Write command line options to the .note section. */ + +void +write_opts_to_asm (void) +{ + size_t i; + cpp_dir *quote_paths, *bracket_paths, *pdir; + struct str_list *pdef, *pinc; + int num_quote_paths = 0; + int num_bracket_paths = 0; + + get_include_chains ("e_paths, &bracket_paths); + + /* Write quote_paths to ASM section. */ + switch_to_section (get_section (".gnu.switches.text.quote_paths", + SECTION_DEBUG, NULL)); + for (pdir = quote_paths; pdir; pdir = pdir->next) + { + if (pdir == bracket_paths) + break; + num_quote_paths++; + } + dw2_asm_output_nstring (in_fnames[0], (size_t)-1, NULL); + dw2_asm_output_data_uleb128 (num_quote_paths, NULL); + for (pdir = quote_paths; pdir; pdir = pdir->next) + { + if (pdir == bracket_paths) + break; + dw2_asm_output_nstring (pdir->name, (size_t)-1, NULL); + } + + /* Write bracket_paths to ASM section. */ + switch_to_section (get_section (".gnu.switches.text.bracket_paths", + SECTION_DEBUG, NULL)); + for (pdir = bracket_paths; pdir; pdir = pdir->next) + num_bracket_paths++; + dw2_asm_output_nstring (in_fnames[0], (size_t)-1, NULL); + dw2_asm_output_data_uleb128 (num_bracket_paths, NULL); + for (pdir = bracket_paths; pdir; pdir = pdir->next) + dw2_asm_output_nstring (pdir->name, (size_t)-1, NULL); + + /* Write cpp_defines to ASM section. */ + switch_to_section (get_section (".gnu.switches.text.cpp_defines", + SECTION_DEBUG, NULL)); + dw2_asm_output_nstring (in_fnames[0], (size_t)-1, NULL); + dw2_asm_output_data_uleb128 (num_cpp_defines, NULL); + for (pdef = cpp_defines_head; pdef; pdef = pdef->next) + dw2_asm_output_nstring (pdef->str, (size_t)-1, NULL); + + /* Write cpp_includes to ASM section. */ + switch_to_section (get_section (".gnu.switches.text.cpp_includes", + SECTION_DEBUG, NULL)); + dw2_asm_output_nstring (in_fnames[0], (size_t)-1, NULL); + dw2_asm_output_data_uleb128 (num_cpp_includes, NULL); + for (pinc = cpp_includes_head; pinc; pinc = pinc->next) + dw2_asm_output_nstring (pinc->str, (size_t)-1, NULL); + + /* Write cl_args to ASM section. */ + switch_to_section (get_section (".gnu.switches.text.cl_args", + SECTION_DEBUG, NULL)); + dw2_asm_output_nstring (in_fnames[0], (size_t)-1, NULL); + dw2_asm_output_data_uleb128 (num_lipo_cl_args, NULL); + for (i = 0; i < num_lipo_cl_args; i++) + dw2_asm_output_nstring (lipo_cl_args[i], (size_t)-1, NULL); +} #include "gt-coverage.h" Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 179836) +++ gcc/common.opt (working copy) @@ -1697,6 +1697,14 @@ Common Report Var(flag_record_gcc_switches) Record gcc command line switches in the object file. +; This option differs from frecord-gcc-switches in the way that it +; divide the command line options into several categories. And the +; section is not mergable so that linker can save gcc switches for +; each module. +frecord-gcc-switches-in-elf +Common Report Var(flag_record_gcc_switches_in_elf) +Record the compiler optimizations in a .gnu.switches.text section. + freg-struct-return Common Report Var(flag_pcc_struct_return,0) Optimization Return small aggregates in registers Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 179836) +++ gcc/Makefile.in (working copy) @@ -3071,7 +3071,7 @@ $(TM_H) $(RTL_H) $(TREE_H) $(FLAGS_H) output.h $(REGS_H) $(EXPR_H) \ $(FUNCTION_H) $(BASIC_BLOCK_H) toplev.h $(DIAGNOSTIC_CORE_H) $(GGC_H) langhooks.h $(COVERAGE_H) \ $(HASHTAB_H) tree-iterator.h $(CGRAPH_H) $(TREE_PASS_H) gcov-io.c $(TM_P_H) \ - opts.h $(TREE_FLOW_H) $(DIAGNOSTIC_CORE_H) intl.h gt-coverage.h l-ipo.h + opts.h $(TREE_FLOW_H) $(DIAGNOSTIC_CORE_H) intl.h gt-coverage.h l-ipo.h dwarf2asm.h