Re: [google] record compiler options to .note sections
ok. David On Tue, Oct 11, 2011 at 9:51 PM, Dehao Chen wrote: > 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. > > 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 (
Re: [google] record compiler options to .note sections
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. 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", +
Re: [google] record compiler options to .note sections
> How about .gnu.switches.text.quote_paths? Sounds good to me. -cary
Re: [google] record compiler options to .note sections
How about .gnu.switches.text.quote_paths? Thanks, Dehao On Tue, Oct 11, 2011 at 8:42 AM, Cary Coutant wrote: >> Ok for google branches. >> >> 1) document the difference of this option with -grecord-gcc-switches >> (this one only record codegen related options, and recorded in debug >> section), and with -frecord-gcc-switches? >> 2) may be better to use option name: -frecord-gcc-switches-in-object > > Sections whose name begins with ".note" are usually SHT_NOTE sections, > and have a specific format. It might be better to choose different > names (like Sri was asked to do with callgraph annotations). > > -cary >
Re: [google] record compiler options to .note sections
> Ok for google branches. > > 1) document the difference of this option with -grecord-gcc-switches > (this one only record codegen related options, and recorded in debug > section), and with -frecord-gcc-switches? > 2) may be better to use option name: -frecord-gcc-switches-in-object Sections whose name begins with ".note" are usually SHT_NOTE sections, and have a specific format. It might be better to choose different names (like Sri was asked to do with callgraph annotations). -cary
Re: [google] record compiler options to .note sections
Ok for google branches. 1) document the difference of this option with -grecord-gcc-switches (this one only record codegen related options, and recorded in debug section), and with -frecord-gcc-switches? 2) may be better to use option name: -frecord-gcc-switches-in-object thanks, David On Sun, Oct 9, 2011 at 6:16 PM, Dehao Chen wrote: > On Sun, Oct 9, 2011 at 5:28 PM, Jakub Jelinek wrote: >> On Sun, Oct 09, 2011 at 09:18:25AM +0800, Dehao Chen wrote: >>> Unfortunately -frecord-gcc-switches cannot serve our purpose because >>> the recorded switches are mergable, i.e. the linker will merge all >>> options to a set of strings. However, object files may have distinct >>> compile options. We want to preserve every object file's compile >>> options when doing LIPO build. >> >> And -grecord-gcc-switches? That one, although it is mergeable, still >> preserves every object files's compile options. > > I tried -grecord-gcc-switches, but looks like it's not recording > options that I want. > > e.g. the following two commands output the same assembly code, while > the former should record one more options. > > gcc -g3 -grecord-gcc-switches a.c -Dabcdefgh -Dxy -I/usr/ -S > gcc -g3 -grecord-gcc-switches a.c -Dabcdefgh -Dxy -S > > Thanks, > Dehao > >> >> Jakub >> >
Re: [google] record compiler options to .note sections
On Sun, Oct 9, 2011 at 5:28 PM, Jakub Jelinek wrote: > On Sun, Oct 09, 2011 at 09:18:25AM +0800, Dehao Chen wrote: >> Unfortunately -frecord-gcc-switches cannot serve our purpose because >> the recorded switches are mergable, i.e. the linker will merge all >> options to a set of strings. However, object files may have distinct >> compile options. We want to preserve every object file's compile >> options when doing LIPO build. > > And -grecord-gcc-switches? That one, although it is mergeable, still > preserves every object files's compile options. I tried -grecord-gcc-switches, but looks like it's not recording options that I want. e.g. the following two commands output the same assembly code, while the former should record one more options. gcc -g3 -grecord-gcc-switches a.c -Dabcdefgh -Dxy -I/usr/ -S gcc -g3 -grecord-gcc-switches a.c -Dabcdefgh -Dxy -S Thanks, Dehao > > Jakub >
Re: [google] record compiler options to .note sections
On Sun, Oct 09, 2011 at 09:18:25AM +0800, Dehao Chen wrote: > Unfortunately -frecord-gcc-switches cannot serve our purpose because > the recorded switches are mergable, i.e. the linker will merge all > options to a set of strings. However, object files may have distinct > compile options. We want to preserve every object file's compile > options when doing LIPO build. And -grecord-gcc-switches? That one, although it is mergeable, still preserves every object files's compile options. Jakub
Re: [google] record compiler options to .note sections
Unfortunately -frecord-gcc-switches cannot serve our purpose because the recorded switches are mergable, i.e. the linker will merge all options to a set of strings. However, object files may have distinct compile options. We want to preserve every object file's compile options when doing LIPO build. Thanks, Dehao On Sat, Oct 8, 2011 at 7:41 PM, Jakub Jelinek wrote: > On Sat, Oct 08, 2011 at 06:43:47PM +0800, Dehao Chen wrote: >> This patch records the compiler command-line flags to a .note section, >> which could be used by FDO/LIPO. >> >> Bootstrapped on x86_64, no regressions. >> >> Is it ok for google/gcc-4_6 and google/main branches? > > Why yet another record switches option? Isn't -grecord-gcc-switches > good enough for you (or -frecord-gcc-switches)? > > Jakub >
Re: [google] record compiler options to .note sections
On Sat, Oct 08, 2011 at 06:43:47PM +0800, Dehao Chen wrote: > This patch records the compiler command-line flags to a .note section, > which could be used by FDO/LIPO. > > Bootstrapped on x86_64, no regressions. > > Is it ok for google/gcc-4_6 and google/main branches? Why yet another record switches option? Isn't -grecord-gcc-switches good enough for you (or -frecord-gcc-switches)? Jakub