This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: [PATCH] Mach-O: Remove ambiguity of mach-o-le and mach-o-x86-64


Hi,

On Fri, Dec 16, 2011 at 5:28 PM, Tristan Gingold <gingold@adacore.com> wrote:
>
> On Dec 15, 2011, at 7:26 PM, shinichiro hamaji wrote:
>
>> Hi,
>>
>> When we use objdump for x86-64 mach-o files without explicit -b flag,
>> it says "File format is ambiguous" because there are two matching
>> formats (mach-o-le and mach-o-x86-64). It's especially not useful when
>> we run objdump for a fat binary which contains x86-64. Actually, I
>> couldn't find any way to dump contents of x86-64 part of a fat binary.
>> It seems i386 is OK as i386 mach-o doesn't match mach-o-le. This tiny
>> patch does the same thing for x86-64:
>> http://shinh.skr.jp/t/mach-o-64-le.patch
>
> How did you configure binutils ? ?It worked for me.

Ah, I've forgot to notice I'm using binutils from linux, where the
bfd_default_vector[0] is elf64. I guess it work for you because you
are working on Mac? I could confirm it just worked on Mac.

>
> I think it would be better to use the match_priority field.

Got it. I've found this field while investigating the matching
algorithm in format.c, but I didn't use it because 1) I thought it is
used only by binary.c due to lack of my grep-fu (I was clearly wrong
here. ELF is using this field at least) and 2) mach-o.c is already
using this way for i386.

I've rewritten my patch using match_priority field:
http://shinh.skr.jp/t/mach-o-64-le-2.patch

I removed the special handling for i386 as I think it's unnecessary
anymore. Of course, I'm happy to revert this change if we still should
have it. I ran objdump -S and objdump -x on linux and mac for
mach-o-i386, mach-o-x86-64, and mach-o-fat with my patch. Their
outputs look good to me.

Thanks!

bfd/
2011-12-16  Shinichiro Hamaji  <shinichiro.hamaji@gmail.com>

	* mach-o-i386.c (TARGET_PRIORITY): Define as 0 (top priority)
	* mach-o-target.c (TARGET_NAME): Use TARGET_PRIORITY
	* mach-o-x86-64.c (TARGET_PRIORITY): Define as 0 (top priority)
	* mach-o.c (bfd_mach_o_header_p): Remove special handling for
	mach-o-i386.
	(TARGET_PRIORITY) Set 1 for mach-o-be and mach-o-le, and set 0 for
	mach-o-fat.
diff --git a/bfd/mach-o-i386.c b/bfd/mach-o-i386.c
index c5e3884..3dadcb8 100644
--- a/bfd/mach-o-i386.c
+++ b/bfd/mach-o-i386.c
@@ -347,4 +347,5 @@ const mach_o_segment_name_xlat
mach_o_i386_segsec_names_xlat[] =
 #define TARGET_ARCHITECTURE	bfd_arch_i386
 #define TARGET_BIG_ENDIAN 	0
 #define TARGET_ARCHIVE 		0
+#define TARGET_PRIORITY		0
 #include "mach-o-target.c"
diff --git a/bfd/mach-o-target.c b/bfd/mach-o-target.c
index c91584c..4aeb920 100644
--- a/bfd/mach-o-target.c
+++ b/bfd/mach-o-target.c
@@ -118,7 +118,7 @@ const bfd_target TARGET_NAME =
   '_',				/* symbol_leading_char.  */
   ' ',				/* ar_pad_char.  */
   16,				/* ar_max_namelen.  */
-  0,				/* match priority.  */
+  TARGET_PRIORITY,	/* match priority.  */

 #if TARGET_BIG_ENDIAN
   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
diff --git a/bfd/mach-o-x86-64.c b/bfd/mach-o-x86-64.c
index 1bc3bf8..c86efb7 100644
--- a/bfd/mach-o-x86-64.c
+++ b/bfd/mach-o-x86-64.c
@@ -294,4 +294,5 @@ bfd_mach_o_x86_64_bfd_reloc_name_lookup (bfd *abfd
ATTRIBUTE_UNUSED,
 #define TARGET_ARCHITECTURE	bfd_arch_i386
 #define TARGET_BIG_ENDIAN 	0
 #define TARGET_ARCHIVE 		0
+#define TARGET_PRIORITY		0
 #include "mach-o-target.c"
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index 325cf61..dca8601 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -3261,17 +3261,6 @@ bfd_mach_o_header_p (bfd *abfd,
       if (header.cputype != cputype)
         goto wrong;
     }
-  else
-    {
-      switch (header.cputype)
-        {
-        case BFD_MACH_O_CPU_TYPE_I386:
-          /* Handled by mach-o-i386 */
-          goto wrong;
-        default:
-          break;
-        }
-    }
   if (filetype)
     {
       if (header.filetype != filetype)
@@ -3802,6 +3791,7 @@ bfd_boolean bfd_mach_o_free_cached_info (bfd *abfd)
 #define TARGET_ARCHITECTURE	bfd_arch_unknown
 #define TARGET_BIG_ENDIAN 	1
 #define TARGET_ARCHIVE 		0
+#define TARGET_PRIORITY		1
 #include "mach-o-target.c"

 #undef TARGET_NAME
@@ -3809,12 +3799,14 @@ bfd_boolean bfd_mach_o_free_cached_info (bfd *abfd)
 #undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
+#undef TARGET_PRIORITY

 #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
+#define TARGET_PRIORITY		1

 #include "mach-o-target.c"

@@ -3823,6 +3815,7 @@ bfd_boolean bfd_mach_o_free_cached_info (bfd *abfd)
 #undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
+#undef TARGET_PRIORITY

 /* Not yet handled: creating an archive.  */
 #define bfd_mach_o_mkarchive                      _bfd_noarchive_mkarchive
@@ -3844,6 +3837,7 @@ bfd_boolean bfd_mach_o_free_cached_info (bfd *abfd)
 #define TARGET_ARCHITECTURE	bfd_arch_unknown
 #define TARGET_BIG_ENDIAN 	1
 #define TARGET_ARCHIVE 		1
+#define TARGET_PRIORITY		0

 #include "mach-o-target.c"

@@ -3852,3 +3846,4 @@ bfd_boolean bfd_mach_o_free_cached_info (bfd *abfd)
 #undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
+#undef TARGET_PRIORITY


>
> Tristan.
>
>>
>> bfd/
>> 2011-12-16 ?Shinichiro Hamaji ?<shinichiro.hamaji@gmail.com>
>>
>> ? ? ? * mach-o.c (bfd_mach_o_header_p): Don't handle x86-64 mach-o
>> ? ? ? when cputype is not specified. This case should be handled by
>> ? ? ? mach-o-x86-64.c.
>> diff --git a/bfd/mach-o.c b/bfd/mach-o.c
>> index 325cf61..a455b09 100644
>> --- a/bfd/mach-o.c
>> +++ b/bfd/mach-o.c
>> @@ -3266,7 +3266,8 @@ bfd_mach_o_header_p (bfd *abfd,
>> ? ? ? switch (header.cputype)
>> ? ? ? ? {
>> ? ? ? ? case BFD_MACH_O_CPU_TYPE_I386:
>> - ? ? ? ? ?/* Handled by mach-o-i386 */
>> + ? ? ? ?case BFD_MACH_O_CPU_TYPE_X86_64:
>> + ? ? ? ? ?/* Handled by mach-o-i386 or mach-o-x86-64 */
>> ? ? ? ? ? goto wrong;
>> ? ? ? ? default:
>> ? ? ? ? ? break;
>


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