This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [lto] add direct-to-ELF serialization to lto1


Ollie Wild wrote:
+ obs->block_size = 1024;
Does it make sense to #define or --param this number?

This number is pretty harmless. I store the data for the output streams in a set of blocks that are linked together. Since i have no idea how much data will be generated, i use an adaptive algorithm. 1024 is the size of the first block. Each subsequent block doubles in size.

This would not be something that you would want to use if you knew the size of the section you were going to copy to the output, but for data sections generated on the fly, this is pretty good.

This isn't my code.  It's just cut-and-pasted from Kenny's
lto_output_1_stream.  I think a discussion of how this algorithm could
be improved is worthwhile, but let's make it a separate discussion.


+ /* This is some bogus wrapper code for development testing. It will be
+ replaced once some basic WPA partitioning logic is implemented. To use
+ this pass "-flto -fsyntax-only" to the lto1 invocation. */
+ if (flag_generate_lto)
+ {
+ lto_file *file;
+
+ file = lto_elf_file_open ("bogus.lto.o", /*writable=*/true);
+ if (!file)
+ fatal_error ("lto_elf_file_open() failed");
+ lto_set_current_out_file (file);
+ }
+
I'm confused by this hunk. What are you testing here? It also
seems that it will trigger with just -flto. Where does
-fsyntax-only come to play?

I'm verifying that I can create an ELF file and populate it with the LTO sections that would normally be written to the assembly output. The LTO langhooks will barf if we don't open a file first.

Strictly speaking, -fsyntax-only isn't required.  It is, however,
useful, as it suppresses the generation of assembly code.  When the
final code is in place, -fpartition will implicitly enable
-fsyntax-only and -flto.  This is the same mechanism gcj uses when
generating bytecode.


I've resolved the other formatting issues and reverted to a langhooks-based approach. Since the output blocks need to be saved until the ELF file is actually written, I've modified the old write_section_data hook to take a block argument and renamed it append_data (to avoid the suggesting that data is actually being written at this point). This was done in the old patch as well but was obscured by the fact that the langhooks were being removed.

Updated patch attached.

Ollie


2008-06-27 Ollie Wild <aaw@google.com>


        * lto-elf.c (lto-section-out.h): New include.
        (struct lto_elf_file): Remove bits member.  Add scn, shstrtab_stream,
        and data members.
        (cached_file_attrs): New static variable.
        (lto_elf_get_shdr, lto_elf_free_shdr): Remove elf_file parameter.
        Use cached_file_attrs for checking bits.
        (lto_elf_build_section_table): Remove elf_file argument from
        lto_elf_get_shdr and lto_elf_free_shdr calls.
        (DEFINE_INIT_SHDR): New macro.
        (init_shdr32, init_shdr64): New functions defined via the
        DEFINE_INIT_SHDR macro.
        (lto_elf_begin_section_with_type): New function.
        (lto_elf_begin_section): New function.
        (lto_elf_append_data): New function.
        (lto_elf_end_section): New function.
        (DEFINE_VALIDATE_EHDR): New macro.
        (validate_ehdr32, validate_ehdr64): New functions defined via the
        DEFINE_VALIDATE_EHDR macro.
        (validate_file): New function.
        (DEFINE_INIT_EHDR): New macro.
        (init_ehdr32, init_ehdr64): New functions defined via the
        DEFINE_INIT_EHDR macro.
        (init_ehdr): New function.
        (lto_elf_file_open): Add support for writable files.  Move some
        validation logic to validate_file.
        (lto_elf_file_close): Add support for writable files.  Write file data
        and free data blocks.
        (current_out_file): New static variable.
        (lto_set_current_out_file): New function.
        (lto_get_current_out_file): New function.
        * lto.c (lto_main): Add writable argument to lto_elf_file_open calls.
        Add temporary initialization for testing ELF serialization.
        * lto.h (lto-section-out.h): New include.
        (struct lto_file_struct): Slight modification to comment.
        (lto_elf_file_open): Add writable parameter.
        (lto_elf_begin_section): New function declaration.
        (lto_elf_append_data): New function declaration.
        (lto_elf_end_section): New function declaration.
        (lto_set_current_out_file, lto_get_current_out_file): New function
        declarations.
        * lto-lang.c (LANG_HOOKS_BEGIN_SECTION): Set as lto_elf_begin_section.
        (LANG_HOOKS_APPEND_DATA): Set as lto_elf_append_data.
        (LANG_HOOKS_END_SECTION): Set as lto_elf_end_section.
        * Make-lang.in (LTO_H): Add lto-section-out.h.

2008-06-27 Ollie Wild <aaw@google.com>

* lto-section-out.h (lto_begin_section): New function declaration.
(lto_end_section): New function declaration.
(lto_output_data_stream): New function declaration.
* lto-section-out.c (lto_begin_section): New function.
(lto_end_section): New function.
(lto_write_stream): Modify lang_hooks call. Remove free.
(append_block): New function.
(lto_output_1_stream): Replace block allocation with call to
append_block.
(lto_output_data_stream): New function.
(lto_destroy_simple_output_block): Add header_stream. Replace
lang_hook calls with lto-section functions.
(write_global_references): Add ref_stream. Replace lang_hooks call
with lto-section calls.
(produce_asm_for_decls): Add header_stream. Replace lang_hook calls
with lto-section calls.
* lto-function-out.c (langhooks.h): Remove include.
(produce_asm): Add header_stream. Replace lang_hook calls with
lto-section calls.
* langhooks.h (struct lang_hooks_for_lto): Rename write_section_data
to append_data. Add a block parameter.
* langhooks-def.h (lhd_append_data): Rename from
lhd_write_section_data. Add a new parameter.
(lhd_write_section_data): Rename to lhd_append_data.
(LANG_HOOKS_APPEND_DATA): Rename from LANG_HOOKS_WRITE_SECTION_DATA.
Change lhd_write_section_data to lhd_append_data.
(LANG_HOOKS_WRITE_SECTION_DATA): Rename to LANG_HOOKS_APPEND_DATA.
(LANG_HOOKS_LTO): Change LANG_HOOKS_WRITE_SECTION-DATA to
LANG_HOOKS_APPEND_DATA.
* langhooks.c (lhd_append_data): Rename from lhd_write_section_data.
Add a block parameter.
(lhd_write_section_data): Rename to lhd_append_data.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]