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 ld/dlltool - .def file format error


------------------------------------------------------------------------
--------
Stefan Kowski wrote on  Mon, 27 Mar 2006 17:21:22 +0200 (CEST) 

http://lists.gnu.org/archive/html/bug-binutils/2006-03/msg00147.html

> 
>
------------------------------------------------------------------------
--------
> 
> platform: Windows, MinGW 3.4.2
> 
> Hi,
> 
> we found a problem with the .def file syntax in the GNU utilities.
> 
> Situation:
> 
> Currently, we are modifying out build system to support the gcc
compiler.
> Linking some shared libraries, we found that the executables cannot be
> executed because Windows reports an error, saying that the executable
is
> corrupt (it shows an error popup dialog). The same executable works
fine if
> the library is linked statically.
> 
> As we had a look at the import descriptor table of the executable
(using
> Microsofts DUMPBIN tool), we found the the shared library function had
an
> empty library name in the table, causing the error.
> 
> The reason was that we did not specify a library name in the .def file
we
> using to link the shared library.
> 
> Our .def file content:
> 
>    LIBRARY
>    EXPORTS
>       <function> @1
> 
> This file has been used successfully with Microsoft Visual Studio
because
> the library name after 'LIBRARY' is optional. If it is not specified,
the
> output name of the library will be used automatically.
> (see http://msdn2.microsoft.com/en-us/library/30fw19zw(vs.80).aspx)
> 
> Without having the library name, gcc/ld will link the library, but it
cannot
> be used because the import library is not correct, making the
executable
> using it corrupt because of the empty library name.
> 
> Our suggestion: use the output name of the library if there is no name
> specified in the .def file, to get the same behaviour as the Microsoft
LINK
> tool.
> 
> Why do we leave out the library name: this is because we use a version
> information in the library name (e.g. mylib40.dll). If we had a
library
> name in the .def file, we would have to patch the .def file each time
the
> version number changes. As the Microsoft linker automatically uses the
> dll output name, it works quite fine.
> 
> I hope you can use this suggestion to improve the linker. Feel free to
ask
> if you have any questions.
> 
> Best regards,
> Stefan Kowski
>


Hello Stefan,

I think that this would indeed be an improvement. In addition to the
reasons you give, it would be nice to be able to specify something like

LIBRARY BASE=0x070000000

so that the internal library name is the same as the output filename
(which is the usual secenario anyway) but we are able to specify base
address in the DEF file.

Here is the patch that fixes:

2006-03-31  Danny Smith  <dannysmith@users.sourceforge.net>

	* deffilep.y (def_image_name): If LIBRARY or NAME statement
	specifies an empty string, retain the name specified on command
	line.
	* ld.texinfo: Document above. 


Index: src/ld/deffilep.y
===================================================================
RCS file: /cvs/src/src/ld/deffilep.y,v
retrieving revision 1.21
diff -c -3 -p -r1.21 deffilep.y
*** src/ld/deffilep.y	1 Feb 2006 21:28:29 -0000	1.21
--- src/ld/deffilep.y	31 Mar 2006 05:18:37 -0000
*************** def_file_add_directive (def_file *my_def
*** 648,669 ****
  static void
  def_image_name (const char *name, int base, int is_dll)
  {
!   const char* image_name = lbasename (name);
!   if (image_name != name)
!     einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
! 	  def_filename, linenumber, is_dll ? "LIBRARY" : "NAME", name);
!   if (def->name)
!     free (def->name);
!   /* Append the default suffix, if none specified.  */ 
!    if (strchr (image_name, '.') == 0)
!      {
!         const char * suffix = is_dll ? ".dll" : ".exe";
! 
!         def->name = xmalloc (strlen (image_name) + strlen (suffix) +
1);
!         sprintf (def->name, "%s%s", image_name, suffix);
!      }
    else
!     def->name = xstrdup (image_name);
    def->base_address = base;
    def->is_dll = is_dll;
  }
--- 648,679 ----
  static void
  def_image_name (const char *name, int base, int is_dll)
  {
!   if (*name == 0)
!     /* A LIBRARY or NAME statement without a name:  Nothing to do.
!        We retain the output filename specified on command line.  */
!     ;
    else
!     {
!       const char* image_name = lbasename (name);
!       if (image_name != name)
! 	einfo ("%s:%d: Warning: path components stripped from %s,
'%s'\n",
! 	       def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
! 	       name);
!       if (def->name)
! 	free (def->name);
!       /* Append the default suffix, if none specified.  */ 
!       if (strchr (image_name, '.') == 0)
! 	{
! 	  const char * suffix = is_dll ? ".dll" : ".exe";
! 
! 	  def->name = xmalloc (strlen (image_name) + strlen (suffix) +
1);
! 	  sprintf (def->name, "%s%s", image_name, suffix);
!         }
!       else
! 	def->name = xstrdup (image_name);
!     }
! 
!   /* Honor a BASE address statement, even if LIBRARY string is empty.
*/
    def->base_address = base;
    def->is_dll = is_dll;
  }
Index: src/ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.157
diff -c -3 -p -r1.157 ld.texinfo
*** src/ld/ld.texinfo	3 Mar 2006 09:31:59 -0000	1.157
--- src/ld/ld.texinfo	31 Mar 2006 05:18:57 -0000
*************** specification @code{BASE = <number>} may
*** 5618,5624 ****
  non-default base address for the image. 
  
  If neither @code{LIBRARY <name>} nor  @code{NAME <name>} is specified,
! the internal name is the same as the filename specified on the command
line. 
  
  The complete specification of an export symbol is:
  
--- 5618,5625 ----
  non-default base address for the image. 
  
  If neither @code{LIBRARY <name>} nor  @code{NAME <name>} is specified,
! or they specify an empty string, the internal name is the same as the
! filename specified on the command line.
  
  The complete specification of an export symbol is:
  


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