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]

[Patch] Add --identify-ms option to dlltool


As it happens, the import libraries created by the microsoft tools are a
bit different than those created by binutils. During a discussion of
this on the libtool list, I put together this enhancement.  However, I'm
not sure if it is appropriate for binutils; after all, it isn't as if ld
can USE ms-supplied import libraries.

Comments?

--
Chuck

2009-01-07  Charles Wilson  <...>

	* binutils/dlltool.c: Add new global variable
        identify_ms.
	(identify_process_section_p): search for alternate
	section when --identify-ms.
	(identify_search_section): Add additional conditions
	to excludes candidate sections from consideration.
	(usage): Added --identify-ms.
	(long_options): Added --identify-ms.
	(main): Handle --identify-ms option.
	* binutils/doc/binutils.texi: Document
	--identify-ms option.
	* binutils/NEWS: Document --identify and
	--identify-ms options.
? binutils/dlltool.c.debug
Index: binutils/NEWS
===================================================================
RCS file: /cvs/src/src/binutils/NEWS,v
retrieving revision 1.72
diff -u -r1.72 NEWS
--- binutils/NEWS	4 Dec 2008 10:29:15 -0000	1.72
+++ binutils/NEWS	7 Jan 2009 06:25:12 -0000
@@ -1,5 +1,11 @@
 -*- text -*-
 
+* Added --identify-ms switch to cause --identify <implib> to 
+  work properly with MS-generated import libraries.
+
+* Added --identify <implib> option to dlltool, which determines the
+  name of the DLL associated with the specified <implib>.
+
 * Support for PowerPC booke64 instructions has been removed.  The assembler no
   longer accepts -mbooke32 or -mbooke64 and the disassembler no longer accepts
   -Mbooke32 or -Mbooke64.  Instead, -mbooke and -Mbooke should be used.
Index: binutils/dlltool.c
===================================================================
RCS file: /cvs/src/src/binutils/dlltool.c,v
retrieving revision 1.86
diff -u -r1.86 dlltool.c
--- binutils/dlltool.c	25 Nov 2008 08:48:49 -0000	1.86
+++ binutils/dlltool.c	7 Jan 2009 06:25:14 -0000
@@ -354,6 +354,7 @@
 static char *imp_name;
 static char *identify_imp_name;
 static char *identify_dll_name;
+static bfd_boolean identify_ms;
 static char *head_label;
 static char *imp_name_lab;
 static char *dll_name;
@@ -3037,7 +3038,8 @@
 /* identify_process_section_p
 
    This predicate returns true if section->name
-   is .idata$7 (.idata$6 on PPC).
+   matches the desired value. By default, this is
+   .idata$7 (.idata$6 on PPC, or when --identify-ms)
 */   
 static bfd_boolean
 identify_process_section_p (asection * section)
@@ -3049,8 +3051,12 @@
 #else
   ".idata$7";
 #endif
+  static const char * MS_SECTION_NAME = ".idata$6";
 
-  if (strcmp (SECTION_NAME, section->name) == 0)
+  const char * section_name =
+    (identify_ms ? MS_SECTION_NAME : SECTION_NAME);
+  
+  if (strcmp (section_name, section->name) == 0)
     return TRUE;
   return FALSE;
 }
@@ -3080,6 +3086,20 @@
   if (! identify_process_section_p (section))
     return;
 
+  /* binutils import libs seem distinguish the .idata$7 section
+     that contains the DLL name from other .idata$7 sections by
+     the absence of the SEC_RELOC flag
+  */
+  if (!identify_ms && ((section->flags & SEC_RELOC) == SEC_RELOC))
+    return;
+
+  /* MS import libs seem to distinguish the .idata$6 section
+     that contains the DLL name from other .idata$6 sections
+     by the presence of the SEC_DATA flag
+  */
+  if (identify_ms && ((section->flags & SEC_DATA) == 0))
+    return;
+
   if ((datasize = bfd_section_size (abfd, section)) == 0)
     return;
 
@@ -3367,6 +3387,7 @@
   fprintf (file, _("   -n --no-delete            Keep temp files (repeat for extra preservation).\n"));
   fprintf (file, _("   -t --temp-prefix <prefix> Use <prefix> to construct temp file names.\n"));
   fprintf (file, _("   -I --identify <implib>    Report the name of the DLL associated with <implib>.\n"));
+  fprintf (file, _("      --identify-ms          Modify the behavior of -I to work with MS implibs.\n"));
   fprintf (file, _("   -v --verbose              Be verbose.\n"));
   fprintf (file, _("   -V --version              Display the program version.\n"));
   fprintf (file, _("   -h --help                 Display this information.\n"));
@@ -3386,6 +3407,7 @@
 #define OPTION_EXCLUDE_SYMS		(OPTION_NO_EXPORT_ALL_SYMS + 1)
 #define OPTION_NO_DEFAULT_EXCLUDES	(OPTION_EXCLUDE_SYMS + 1)
 #define OPTION_ADD_STDCALL_UNDERSCORE	(OPTION_NO_DEFAULT_EXCLUDES + 1)
+#define OPTION_IDENTIFY_MS		(OPTION_ADD_STDCALL_UNDERSCORE + 1)
 
 static const struct option long_options[] =
 {
@@ -3408,6 +3430,7 @@
   {"add-stdcall-alias", no_argument, NULL, 'A'},
   {"ext-prefix-alias", required_argument, NULL, 'p'},
   {"identify", required_argument, NULL, 'I'},
+  {"identify-ms", no_argument, NULL, OPTION_IDENTIFY_MS},
   {"verbose", no_argument, NULL, 'v'},
   {"version", no_argument, NULL, 'V'},
   {"help", no_argument, NULL, 'h'},
@@ -3470,6 +3493,9 @@
 	case OPTION_ADD_STDCALL_UNDERSCORE:
 	  add_stdcall_underscore = 1;
 	  break;
+	case OPTION_IDENTIFY_MS:
+	  identify_ms = 1;
+	  break;
 	case 'x':
 	  no_idata4 = 1;
 	  break;
Index: binutils/doc/binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.135
diff -u -r1.135 binutils.texi
--- binutils/doc/binutils.texi	23 Dec 2008 09:01:46 -0000	1.135
+++ binutils/doc/binutils.texi	7 Jan 2009 06:25:17 -0000
@@ -3370,7 +3370,8 @@
         [@option{-k}|@option{--kill-at}] [@option{-A}|@option{--add-stdcall-alias}]
         [@option{-p}|@option{--ext-prefix-alias} @var{prefix}]
         [@option{-x}|@option{--no-idata4}] [@option{-c}|@option{--no-idata5}]
-        [@option{-I}|@option{--identify} @var{library-file-name}] [@option{-i}|@option{--interwork}]
+        [@option{-I}|@option{--identify} @var{library-file-name}] [@option{--identify-ms}]
+        [@option{-I}[@option{-i}|@option{--interwork}]
         [@option{-n}|@option{--nodelete}] [@option{-t}|@option{--temp-prefix} @var{prefix}]
         [@option{-v}|@option{--verbose}]
         [@option{-h}|@option{--help}] [@option{-V}|@option{--version}]
@@ -3599,6 +3600,11 @@
 actually an import library, or (rarely) if the import library somehow
 specifies more than one associated DLL.
 
+@item --identify-ms
+Modifies the behavior of the @option{--identify} @var{filename}, such
+that @var{filename} is interpreted as an import library generated by
+a certain proprietary vendor's compiler.
+
 @item -i
 @itemx --interwork
 Specifies that @command{dlltool} should mark the objects in the library

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