OSDN Git Service

ChangeLog:
authorsteven <steven@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 May 2010 21:37:43 +0000 (21:37 +0000)
committerMasaki Muranaka <monaka@monami-software.com>
Sun, 23 May 2010 05:03:05 +0000 (14:03 +0900)
* configure.ac (--enable-lto): Add x86_64-apple-darwin* as
a platform that supports LTO.
* configure: Regenerate.

gcc/ChangeLog:
* config.gcc (i[34567]86-*-darwin*, x86_64-*-darwin*): Add
lto-macho as lto_binary_reader.
* target.h (struct gcc_target): New hooks lto_start and lto_end.
* target-def.h (TARGET_ASM_LTO_START, TARGET_ASM_LTO_END): Define.
* cgraphunit.c (ipa_passes): Wrap LTO assembler output generation
in lto_start and lto_end calls.
(is_elf_or_coff): Rename to maybe_lto_object_file.  Add Mach-O
magic numbers.
(scan_prog_file): Update is_elf_or_coff call.
* doc/tm.text (TARGET_ASM_LTO_START, TARGET_ASM_LTO_END): Document.

* collect2.c (main): Fix enum comparison.

* config/darwin-protos.h (darwin_asm_lto_start, darwin_asm_lto_end):
Add prototypes.
* darwin9.h (LINK_COMMAND_SPEC): Pass -flto and -fwhopr to the linker.
* darwin.h (LINK_COMMAND_SPEC): Likewise.  Define TARGET_ASM_LTO_START
and TARGET_ASM_LTO_END.
* darwin.c: Include obstack.h and lto-streamer.h.
(lto_section_names_offset, lto_section_names_obstack,
lto_asm_out_file, lto_asm_out_name, saved_asm_out_file): New static
global variables.
(LTO_SEGMENT_NAME, LTO_NAMES_SECTION): New defines.
(darwin_asm_lto_start): New function.  Redirect output to asm_out_file
to a temporary file.
(darwin_asm_lto_end): New function.  Restore asm_out_file.
(darwin_asm_named_section): For LTO sections, replace the name with
the offset of the section name in a string table, and build this
table.
(darwin_file_start): Initialize global vars for LTO support.
(darwin_file_end): If output to asm_out_file was redirected, append it
to the proper asm_out_file here.  Add the section names section.

lto/ChangeLog:
* lto.h (struct lto_file_struct): Document offset member.
* lto-endian.h: New file.
* lto-macho.h: New file.
* lto-macho.c: New file.
* Make-lang.in: Add rule for lto-macho.o.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159173 138bc75d-0d04-0410-961f-82ee72b054a4

13 files changed:
ChangeLog
configure
configure.ac
gcc/ChangeLog
gcc/cgraphunit.c
gcc/collect2.c
gcc/config.gcc
gcc/config/darwin.c
gcc/doc/tm.texi
gcc/lto/ChangeLog
gcc/lto/Make-lang.in
gcc/target-def.h
gcc/target.h

index a78216d..ee64b58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-05-07  Steven Bosscher  <steven@gcc.gnu.org>
+
+       * configure.ac (--enable-lto): Add x86_64-apple-darwin* as
+       a platform that supports LTO.
+       * configure: Regenerate.
+
 2010-05-05  Sebastian Pop  <sebastian.pop@amd.com>
 
        * configure.ac: Allow all the versions greater than 0.10 of PPL.
index cfec344..6fc9b0f 100755 (executable)
--- a/configure
+++ b/configure
@@ -6686,6 +6686,7 @@ else
   # -flto it won't be needed until after installation anyway.
     case $target in
       *-cygwin*|*-mingw*) ;;
+      x86_64-apple-darwin*) ;;
       *) if test x"$enable_lto" = x"yes"; then
        as_fn_error "LTO support is not enabled for this target." "$LINENO" 5
         fi
index f3ef304..9204574 100644 (file)
@@ -1803,6 +1803,7 @@ fi],[if test x"$default_enable_lto" = x"yes" ; then
   # -flto it won't be needed until after installation anyway.
     case $target in
       *-cygwin*|*-mingw*) ;;
+      x86_64-apple-darwin*) ;;
       *) if test x"$enable_lto" = x"yes"; then
        AC_MSG_ERROR([LTO support is not enabled for this target.])
         fi
index 2fd92d9..d44a020 100644 (file)
@@ -1,5 +1,40 @@
 2010-05-07  Steven Bosscher  <steven@gcc.gnu.org>
 
+       * config.gcc (i[34567]86-*-darwin*, x86_64-*-darwin*): Add
+       lto-macho as lto_binary_reader.
+       * target.h (struct gcc_target): New hooks lto_start and lto_end.
+       * target-def.h (TARGET_ASM_LTO_START, TARGET_ASM_LTO_END): Define.
+       * cgraphunit.c (ipa_passes): Wrap LTO assembler output generation
+       in lto_start and lto_end calls.
+       (is_elf_or_coff): Rename to maybe_lto_object_file.  Add Mach-O
+       magic numbers.
+       (scan_prog_file): Update is_elf_or_coff call.
+       * doc/tm.text (TARGET_ASM_LTO_START, TARGET_ASM_LTO_END): Document.
+
+       * collect2.c (main): Fix enum comparison.
+
+       * config/darwin-protos.h (darwin_asm_lto_start, darwin_asm_lto_end):
+       Add prototypes.
+       * darwin9.h (LINK_COMMAND_SPEC): Pass -flto and -fwhopr to the linker.
+       * darwin.h (LINK_COMMAND_SPEC): Likewise.  Define TARGET_ASM_LTO_START
+       and TARGET_ASM_LTO_END.
+       * darwin.c: Include obstack.h and lto-streamer.h.
+       (lto_section_names_offset, lto_section_names_obstack,
+       lto_asm_out_file, lto_asm_out_name, saved_asm_out_file): New static
+       global variables.
+       (LTO_SEGMENT_NAME, LTO_NAMES_SECTION): New defines.
+       (darwin_asm_lto_start): New function.  Redirect output to asm_out_file
+       to a temporary file.
+       (darwin_asm_lto_end): New function.  Restore asm_out_file.
+       (darwin_asm_named_section): For LTO sections, replace the name with
+       the offset of the section name in a string table, and build this
+       table.
+       (darwin_file_start): Initialize global vars for LTO support.
+       (darwin_file_end): If output to asm_out_file was redirected, append it
+       to the proper asm_out_file here.  Add the section names section.
+
+2010-05-07  Steven Bosscher  <steven@gcc.gnu.org>
+
        * c-pragma.c (pending_weak_d, pending_weak): New.
        (pending_weaks): Change the type to VEC((pending_weak,gc) *.
        (maybe_apply_pragma_weak, maybe_apply_pending_pragma_weaks,
index cd67f2a..cacb90c 100644 (file)
@@ -1866,11 +1866,19 @@ ipa_passes (void)
       execute_ipa_summary_passes
        ((struct ipa_opt_pass_d *) all_regular_ipa_passes);
     }
+
+  /* Some targets need to handle LTO assembler output specially.  */
+  if (flag_generate_lto)
+    targetm.asm_out.lto_start ();
+
   execute_ipa_summary_passes ((struct ipa_opt_pass_d *) all_lto_gen_passes);
 
   if (!in_lto_p)
     ipa_write_summaries ();
 
+  if (flag_generate_lto)
+    targetm.asm_out.lto_end ();
+
   if (!flag_ltrans)
     execute_ipa_pass_list (all_regular_ipa_passes);
   invoke_plugin_callbacks (PLUGIN_ALL_IPA_PASSES_END, NULL);
index 99d9be4..6582185 100644 (file)
@@ -1817,7 +1817,7 @@ main (int argc, char **argv)
        if (export_file != 0 && export_file[0])
          maybe_unlink (export_file);
 #endif
-       if (lto_mode)
+       if (lto_mode != LTO_MODE_NONE)
          maybe_run_lto_and_relink (ld1_argv, object_lst, object, false);
 
        maybe_unlink (c_file);
@@ -2563,16 +2563,23 @@ write_aix_file (FILE *stream, struct id *list)
 \f
 #ifdef OBJECT_FORMAT_NONE
 
-/* Check to make sure the file is an ELF file.  LTO objects must
-   be in ELF format.  */
+/* Check to make sure the file is an LTO object file.  */
 
 static bool
-is_elf_or_coff (const char *prog_name)
+maybe_lto_object_file (const char *prog_name)
 {
   FILE *f;
-  char buf[4];
-  static char magic[4] = { 0x7f, 'E', 'L', 'F' };
-  static char coffmag[2] = { 0x4c, 0x01 };
+  unsigned char buf[4];
+  int i;
+
+  static unsigned char elfmagic[4] = { 0x7f, 'E', 'L', 'F' };
+  static unsigned char coffmagic[2] = { 0x4c, 0x01 };
+  static unsigned char machomagic[4][4] = {
+    { 0xcf, 0xfa, 0xed, 0xfe },
+    { 0xce, 0xfa, 0xed, 0xfe },
+    { 0xfe, 0xed, 0xfa, 0xcf },
+    { 0xfe, 0xed, 0xfa, 0xce }
+  };
 
   f = fopen (prog_name, "rb");
   if (f == NULL)
@@ -2580,8 +2587,15 @@ is_elf_or_coff (const char *prog_name)
   if (fread (buf, sizeof (buf), 1, f) != 1)
     buf[0] = 0;
   fclose (f);
-  return memcmp (buf, magic, sizeof (magic)) == 0
-       || memcmp (buf, coffmag, sizeof (coffmag)) == 0;
+
+  if (memcmp (buf, elfmagic, sizeof (elfmagic)) == 0
+      || memcmp (buf, coffmagic, sizeof (coffmagic)) == 0)
+    return true;
+  for (i = 0; i < 4; i++)
+    if (memcmp (buf, machomagic[i], sizeof (machomagic[i])) == 0)
+      return true;
+
+  return false;
 }
 
 /* Generic version to scan the name list of the loaded program for
@@ -2611,7 +2625,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
   /* LTO objects must be in a known format.  This check prevents
      us from accepting an archive containing LTO objects, which
      gcc cannnot currently handle.  */
-  if (which_pass == PASS_LTOINFO && !is_elf_or_coff (prog_name))
+  if (which_pass == PASS_LTOINFO && !maybe_lto_object_file (prog_name))
     return;
 
   /* If we do not have an `nm', complain.  */
index e46cd73..5ea1b4d 100644 (file)
@@ -1077,11 +1077,13 @@ i[34567]86-*-darwin*)
        # support.
        with_cpu=${with_cpu:-generic}
        tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm"
+       lto_binary_reader=lto-macho
        ;;
 x86_64-*-darwin*)
        with_cpu=${with_cpu:-generic}
        tmake_file="${tmake_file} t-darwin ${cpu_type}/t-darwin64 t-slibgcc-darwin i386/t-crtpc i386/t-crtfm"
        tm_file="${tm_file} ${cpu_type}/darwin64.h"
+       lto_binary_reader=lto-macho
        ;;
 i[34567]86-*-elf*)
        tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h"
index eba0329..93f7bab 100644 (file)
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "rtl.h"
 #include "regs.h"
 #include "hard-reg-set.h"
+#include "real.h"
 #include "insn-config.h"
 #include "conditions.h"
 #include "insn-flags.h"
@@ -1459,9 +1460,8 @@ darwin_asm_named_section (const char *name,
       obstack_grow (&lto_section_names_obstack, "\\0\"\n", 4);
 
       /* Output the dummy section name.  */
-      fprintf (asm_out_file, "\t# %s\n", name);
-      fprintf (asm_out_file, "\t.section %s,__%08X,regular,debug\n",
-              LTO_SEGMENT_NAME, lto_section_names_offset);
+      fprintf (asm_out_file, "\t.section %s,__%08X,regular,debug\t# %s\n",
+              LTO_SEGMENT_NAME, lto_section_names_offset, name);
 
       /* Update the offset for the next section name.  Make sure we stay
         within reasonable length.  */  
index 7eb49d6..96fc62c 100644 (file)
@@ -7184,6 +7184,18 @@ need to do other things in that hook, have your hook function call
 this function.
 @end deftypefun
 
+@deftypefn {Target Hook} void TARGET_ASM_LTO_START (void)
+Output to @code{asm_out_file} any text which the assembler expects
+to find at the start of an LTO section.  The default is to output
+nothing.
+@end deftypefn
+
+@deftypefn {Target Hook} void TARGET_ASM_LTO_END (void)
+Output to @code{asm_out_file} any text which the assembler expects
+to find at the end of an LTO section.  The default is to output
+nothing.
+@end deftypefn
+
 @deftypefn {Target Hook} void TARGET_ASM_CODE_END (void)
 Output to @code{asm_out_file} any text which is needed before emitting
 unwind info and debug info at the end of a file.  Some targets emit
index 2496d66..b7f0b7e 100644 (file)
@@ -1,3 +1,11 @@
+2010-05-07  Steven Bosscher  <steven@gcc.gnu.org>
+
+       * lto.h (struct lto_file_struct): Document offset member.
+       * lto-endian.h: New file.
+       * lto-macho.h: New file.
+       * lto-macho.c: New file.
+       * Make-lang.in: Add rule for lto-macho.o.
+
 2010-05-07  Richard Guenther <rguenther@suse.de>
 
        PR lto/43857
index 7963bf0..1496449 100644 (file)
@@ -91,3 +91,6 @@ lto/lto-elf.o: lto/lto-elf.c $(CONFIG_H) coretypes.h $(SYSTEM_H) \
 lto/lto-coff.o: lto/lto-coff.c $(CONFIG_H) coretypes.h $(SYSTEM_H) \
        toplev.h $(LTO_H) $(TM_H) $(LIBIBERTY_H) $(GGC_H) $(LTO_STREAMER_H) \
        lto/lto-coff.h
+lto/lto-macho.o: lto/lto-macho.c $(CONFIG_H) coretypes.h $(SYSTEM_H) \
+       toplev.h $(LTO_H) $(TM_H) $(LIBIBERTY_H) $(GGC_H) $(LTO_STREAMER_H) \
+       lto/lto-macho.h lto/lto-endian.h
index 1f60e52..72cf930 100644 (file)
 #define TARGET_ASM_FILE_END hook_void_void
 #endif
 
+#ifndef TARGET_ASM_LTO_START
+#define TARGET_ASM_LTO_START hook_void_void
+#endif
+
+#ifndef TARGET_ASM_LTO_END
+#define TARGET_ASM_LTO_END hook_void_void
+#endif
+
 #ifndef TARGET_ASM_CODE_END
 #define TARGET_ASM_CODE_END hook_void_void
 #endif
                         TARGET_ASM_CAN_OUTPUT_MI_THUNK,         \
                         TARGET_ASM_FILE_START,                  \
                         TARGET_ASM_FILE_END,                   \
+                        TARGET_ASM_LTO_START,                  \
+                        TARGET_ASM_LTO_END,                    \
                         TARGET_ASM_CODE_END,                   \
                        TARGET_ASM_EXTERNAL_LIBCALL,            \
                         TARGET_ASM_MARK_DECL_PRESERVED,                \
index 2f99a4f..2c9ab85 100644 (file)
@@ -238,6 +238,14 @@ struct gcc_target
        translation unit.  */
     void (*file_end) (void);
 
+    /* Output any boilerplate text needed at the beginning of an
+       LTO output stream.  */
+    void (*lto_start) (void);
+
+    /* Output any boilerplate text needed at the end of an
+       LTO output stream.  */
+    void (*lto_end) (void);
+
     /* Output any boilerplace text needed at the end of a
        translation unit before debug and unwind info is emitted.  */
     void (*code_end) (void);