2010-01-11 Tristan Gingold <gingold@adacore.com>
authorTristan Gingold <gingold@adacore.com>
Mon, 11 Jan 2010 15:39:41 +0000 (15:39 +0000)
committerTristan Gingold <gingold@adacore.com>
Mon, 11 Jan 2010 15:39:41 +0000 (15:39 +0000)
* mach-o.h (bfd_mach_o_backend_data): Add arch field.
(bfd_mach_o_set_arch_mach): New prototype.
* mach-o.c (bfd_mach_o_mkobject): Define with bfd_mach_o_gen_mkobject.
(bfd_mach_o_set_arch_mach): New function.
(bfd_mach_o_gen_mkobject): New function.
Set TARGET_ARCHITECTURE for the generic back-ends.
* mach-o-target.c (bfd_mach_o_set_arch_mach): Remove define.
Check that TARGET_ARCHITECTURE is defined.
Add TARGET_ARCHITECTURE in TARGET_NAME_BACKEND structure.
* mach-o-i386.c (TARGET_ARCHITECTURE): Define.

bfd/ChangeLog
bfd/mach-o-i386.c
bfd/mach-o-target.c
bfd/mach-o.c
bfd/mach-o.h

index aaf318611fac8ff927a7f624c49849f1fb41991a..22b26ab97efe0dd470c4c05af71bedff768da96c 100644 (file)
@@ -1,3 +1,16 @@
+2010-01-11  Tristan Gingold  <gingold@adacore.com>
+
+       * mach-o.h (bfd_mach_o_backend_data): Add arch field.
+       (bfd_mach_o_set_arch_mach): New prototype.
+       * mach-o.c (bfd_mach_o_mkobject): Define with bfd_mach_o_gen_mkobject.
+       (bfd_mach_o_set_arch_mach): New function.
+       (bfd_mach_o_gen_mkobject): New function.
+       Set TARGET_ARCHITECTURE for the generic back-ends.
+       * mach-o-target.c (bfd_mach_o_set_arch_mach): Remove define.
+       Check that TARGET_ARCHITECTURE is defined.
+       Add TARGET_ARCHITECTURE in TARGET_NAME_BACKEND structure.
+       * mach-o-i386.c (TARGET_ARCHITECTURE): Define.
+
 2010-01-11  Tristan Gingold  <gingold@adacore.com>
 
         * archive.c (bfd_slurp_armap): Also check for Mach-O sorted armap.
index 53de64e826c86c4f335986f62234b0709b79fad4..e46cbc6f57ed45929a990e515e4276fc1dff24ff 100644 (file)
@@ -288,6 +288,7 @@ bfd_mach_o_i386_print_thread (bfd *abfd, bfd_mach_o_thread_flavour *thread,
 
 #define TARGET_NAME            mach_o_i386_vec
 #define TARGET_STRING          "mach-o-i386"
+#define TARGET_ARCHITECTURE    bfd_arch_i386
 #define TARGET_BIG_ENDIAN      0
 #define TARGET_ARCHIVE                 0
 #include "mach-o-target.c"
index 2a30b2ed1f611325ed49c1cc8b1d82667e4130eb..8edf547a3850e6b61f8dfdb9206515e801c1da3c 100644 (file)
@@ -57,7 +57,6 @@
   _bfd_generic_copy_link_hash_symbol_type
 #define bfd_mach_o_bfd_final_link                     _bfd_generic_final_link
 #define bfd_mach_o_bfd_link_split_section             _bfd_generic_link_split_section
-#define bfd_mach_o_set_arch_mach                      bfd_default_set_arch_mach
 #define bfd_mach_o_bfd_merge_private_bfd_data         _bfd_generic_bfd_merge_private_bfd_data
 #define bfd_mach_o_bfd_set_private_flags              _bfd_generic_bfd_set_private_flags
 #define bfd_mach_o_get_section_contents               _bfd_generic_get_section_contents
 #error TARGET_STRING must be defined
 #endif /* TARGET_STRING */
 
+#ifndef TARGET_ARCHITECTURE
+#error TARGET_ARCHITECTURE must be defined
+#endif /* TARGET_ARCHITECTURE */
+
 #ifndef TARGET_BIG_ENDIAN
 #error TARGET_BIG_ENDIAN must be defined
 #endif /* TARGET_BIG_ENDIAN */
 
 static const bfd_mach_o_backend_data TARGET_NAME_BACKEND =
 {
+  TARGET_ARCHITECTURE,
   bfd_mach_o_swap_reloc_in,
   bfd_mach_o_swap_reloc_out,
   bfd_mach_o_print_thread
index ae86c4e77a89ee38082155bf4a5c55fb68f255e5..abfd7c1b4d78a95e78f68ffe1fc1a57508df429d 100644 (file)
@@ -29,7 +29,7 @@
 
 #define bfd_mach_o_object_p bfd_mach_o_gen_object_p
 #define bfd_mach_o_core_p bfd_mach_o_gen_core_p
-#define bfd_mach_o_mkobject bfd_false
+#define bfd_mach_o_mkobject bfd_mach_o_gen_mkobject
 
 #define FILE_ALIGN(off, algn) \
   (((off) + ((file_ptr) 1 << (algn)) - 1) & ((file_ptr) -1 << (algn)))
@@ -2672,6 +2672,23 @@ bfd_mach_o_scan_start_address (bfd *abfd)
   return 0;
 }
 
+bfd_boolean
+bfd_mach_o_set_arch_mach (bfd *abfd,
+                          enum bfd_architecture arch,
+                          unsigned long machine)
+{
+  bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+
+  /* If this isn't the right architecture for this backend, and this
+     isn't the generic backend, fail.  */
+  if (arch != bed->arch
+      && arch != bfd_arch_unknown
+      && bed->arch != bfd_arch_unknown)
+    return FALSE;
+
+  return bfd_default_set_arch_mach (abfd, arch, machine);
+}
+
 int
 bfd_mach_o_scan (bfd *abfd,
                 bfd_mach_o_header *header,
@@ -2771,6 +2788,24 @@ bfd_mach_o_mkobject_init (bfd *abfd)
   return TRUE;
 }
 
+static bfd_boolean
+bfd_mach_o_gen_mkobject (bfd *abfd)
+{
+  bfd_mach_o_data_struct *mdata;
+
+  if (!bfd_mach_o_mkobject_init (abfd))
+    return FALSE;
+
+  mdata = bfd_mach_o_get_data (abfd);
+  mdata->header.magic = BFD_MACH_O_MH_MAGIC;
+  mdata->header.cputype = 0;
+  mdata->header.cpusubtype = 0;
+  mdata->header.byteorder = abfd->xvec->byteorder;
+  mdata->header.version = 1;
+
+  return TRUE;
+}
+
 const bfd_target *
 bfd_mach_o_header_p (bfd *abfd,
                      bfd_mach_o_filetype filetype,
@@ -3960,17 +3995,20 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
 
 #define TARGET_NAME            mach_o_be_vec
 #define TARGET_STRING          "mach-o-be"
+#define TARGET_ARCHITECTURE    bfd_arch_unknown
 #define TARGET_BIG_ENDIAN      1
 #define TARGET_ARCHIVE                 0
 #include "mach-o-target.c"
 
 #undef TARGET_NAME
 #undef TARGET_STRING
+#undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
 
 #define TARGET_NAME            mach_o_le_vec
 #define TARGET_STRING          "mach-o-le"
+#define TARGET_ARCHITECTURE    bfd_arch_unknown
 #define TARGET_BIG_ENDIAN      0
 #define TARGET_ARCHIVE                 0
 
@@ -3978,11 +4016,13 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
 
 #undef TARGET_NAME
 #undef TARGET_STRING
+#undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
 
 #define TARGET_NAME            mach_o_fat_vec
 #define TARGET_STRING          "mach-o-fat"
+#define TARGET_ARCHITECTURE    bfd_arch_unknown
 #define TARGET_BIG_ENDIAN      1
 #define TARGET_ARCHIVE                 1
 
@@ -3990,5 +4030,6 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
 
 #undef TARGET_NAME
 #undef TARGET_STRING
+#undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
index 62f7709fc7d3765403a93e1cd3ab234d6668363d..bdd76321a16daaf9cb6a9576479c5dd9527a1fa7 100644 (file)
@@ -845,6 +845,7 @@ bfd_mach_o_data_struct;
 /* Target specific routines.  */
 typedef struct bfd_mach_o_backend_data
 {
+  enum bfd_architecture arch;
   bfd_boolean (*_bfd_mach_o_swap_reloc_in)(arelent *, bfd_mach_o_reloc_info *);
   bfd_boolean (*_bfd_mach_o_swap_reloc_out)(arelent *, bfd_mach_o_reloc_info *);
   bfd_boolean (*_bfd_mach_o_print_thread)(bfd *, bfd_mach_o_thread_flavour *,
@@ -865,6 +866,8 @@ const bfd_target *bfd_mach_o_object_p (bfd *);
 const bfd_target *bfd_mach_o_core_p (bfd *);
 const bfd_target *bfd_mach_o_archive_p (bfd *);
 bfd *bfd_mach_o_openr_next_archived_file (bfd *, bfd *);
+bfd_boolean bfd_mach_o_set_arch_mach (bfd *, enum bfd_architecture,
+                                      unsigned long);
 int bfd_mach_o_lookup_section (bfd *, asection *, bfd_mach_o_load_command **, bfd_mach_o_section **);
 int bfd_mach_o_lookup_command (bfd *, bfd_mach_o_load_command_type, bfd_mach_o_load_command **);
 bfd_boolean bfd_mach_o_write_contents (bfd *);