From: rguenth Date: Fri, 30 Oct 2009 15:58:57 +0000 (+0000) Subject: 2009-10-30 Richard Guenther X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=f5a023c5da2de25e6ee5c583c44825de7bf1a87c;hp=81c308357d5c93761ae9e190978f14ac0d4b5287 2009-10-30 Richard Guenther PR lto/41858 * lto-streamer.h (struct lto_file_decl_data): Remove fd member. lto/ * lto.c (lto_file_read): Do not set file_data->fd. (lto_read_section_data): Use a single-entry file-descriptor cache. Do not check the result of xmalloc. (free_section_data): Do not use file_data->fd. (lto_read_all_file_options): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@153758 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7b0892390e3..fb1fccedef8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2009-10-30 Richard Guenther + + PR lto/41858 + * lto-streamer.h (struct lto_file_decl_data): Remove fd member. + 2009-10-30 Nathan Sidwell * target-def.h (TARGET_ASM_TTYPE): Correct typo of TARGET_ARM_TTYPE. diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h index de1ee080b84..c3880b61efa 100644 --- a/gcc/lto-streamer.h +++ b/gcc/lto-streamer.h @@ -555,10 +555,6 @@ struct lto_file_decl_data /* Nonzero if this file should be recompiled with LTRANS. */ unsigned needs_ltrans_p : 1; - /* If the file is open, this is the fd of the mapped section. This - is -1 if the file has not yet been opened. */ - int fd; - /* Hash table maps lto-related section names to location in file. */ htab_t section_hash_table; diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index d6c3325846d..0d464ec232e 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,12 @@ +2009-10-30 Richard Guenther + + PR lto/41858 + * lto.c (lto_file_read): Do not set file_data->fd. + (lto_read_section_data): Use a single-entry file-descriptor cache. + Do not check the result of xmalloc. + (free_section_data): Do not use file_data->fd. + (lto_read_all_file_options): Likewise. + 2009-10-22 Richard Guenther * lto.c (lto_fixup_jump_functions): Remove. diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index 54fde65c69a..d8c49cf729f 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -334,7 +334,6 @@ lto_file_read (lto_file *file, FILE *resolution_file) file_data = XCNEW (struct lto_file_decl_data); file_data->file_name = file->filename; - file_data->fd = -1; file_data->section_hash_table = lto_elf_build_section_table (file); file_data->renaming_hash_table = lto_create_renaming_table (); @@ -363,17 +362,33 @@ lto_read_section_data (struct lto_file_decl_data *file_data, intptr_t offset, size_t len) { char *result; + static int fd = -1; + static char *fd_name; #if LTO_MMAP_IO intptr_t computed_len; intptr_t computed_offset; intptr_t diff; #endif - if (file_data->fd == -1) - file_data->fd = open (file_data->file_name, O_RDONLY); - - if (file_data->fd == -1) - return NULL; + /* Keep a single-entry file-descriptor cache. The last file we + touched will get closed at exit. + ??? Eventually we want to add a more sophisticated larger cache + or rather fix function body streaming to not stream them in + practically random order. */ + if (fd != -1 + && strcmp (fd_name, file_data->file_name) != 0) + { + free (fd_name); + close (fd); + fd = -1; + } + if (fd == -1) + { + fd_name = xstrdup (file_data->file_name); + fd = open (file_data->file_name, O_RDONLY); + if (fd == -1) + return NULL; + } #if LTO_MMAP_IO if (!page_mask) @@ -387,26 +402,17 @@ lto_read_section_data (struct lto_file_decl_data *file_data, computed_len = len + diff; result = (char *) mmap (NULL, computed_len, PROT_READ, MAP_PRIVATE, - file_data->fd, computed_offset); + fd, computed_offset); if (result == MAP_FAILED) - { - close (file_data->fd); - return NULL; - } + return NULL; return result + diff; #else result = (char *) xmalloc (len); - if (result == NULL) - { - close (file_data->fd); - return NULL; - } - if (lseek (file_data->fd, offset, SEEK_SET) != offset - || read (file_data->fd, result, len) != (ssize_t) len) + if (lseek (fd, offset, SEEK_SET) != offset + || read (fd, result, len) != (ssize_t) len) { free (result); - close (file_data->fd); return NULL; } @@ -449,7 +455,7 @@ get_section_data (struct lto_file_decl_data *file_data, starts at OFFSET and has LEN bytes. */ static void -free_section_data (struct lto_file_decl_data *file_data, +free_section_data (struct lto_file_decl_data *file_data ATTRIBUTE_UNUSED, enum lto_section_type section_type ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED, const char *offset, size_t len ATTRIBUTE_UNUSED) @@ -460,9 +466,6 @@ free_section_data (struct lto_file_decl_data *file_data, intptr_t diff; #endif - if (file_data->fd == -1) - return; - #if LTO_MMAP_IO computed_offset = ((intptr_t) offset) & page_mask; diff = (intptr_t) offset - computed_offset; @@ -1712,15 +1715,12 @@ lto_read_all_file_options (void) file_data = XCNEW (struct lto_file_decl_data); file_data->file_name = file->filename; - file_data->fd = -1; file_data->section_hash_table = lto_elf_build_section_table (file); lto_read_file_options (file_data); lto_elf_file_close (file); htab_delete (file_data->section_hash_table); - if (file_data->fd != -1) - close (file_data->fd); free (file_data); }