Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

Danny Smith-4
Hello

According to MS doc's (and comments in binutils/dlltool.c). the suffix
of the internal names of images defaults to ".exe" if the name is
specified by NAME statement in a .def file, and to ".dll" if specified
by a LIBRARY statement. Failing to append a suffix can cause dll
import problems since it is this internal name that is put into the
import lib and used when searching for the libary at load time.  An
example of this problem is at:

https://sourceforge.net/tracker/index.php?func=detail&aid=1401442&group_id=2435&atid=102435
 
This fixes by appending a default suffix, if necessary, when we parse
the .def file.

ChangeLog

2006-02-01  Danny Smith  <[hidden email]>

        * deffilep.y (def_image_name): If the image name does not have a
        suffix, append the default.
        *ld.texinfo: Document NAME, LIBRARY usage in PE-COFF .def files.

Index: deffilep.y
===================================================================
RCS file: /cvs/src/src/ld/deffilep.y,v
retrieving revision 1.20
diff -c -3 -p -r1.20 deffilep.y
*** deffilep.y 12 May 2005 07:32:02 -0000 1.20
--- deffilep.y 31 Jan 2006 22:02:00 -0000
*************** def_image_name (const char *name, int ba
*** 654,660 ****
   def_filename, linenumber, is_dll ? "LIBRARY" : "NAME", name);
    if (def->name)
      free (def->name);
!   def->name = xstrdup (image_name);
    def->base_address = base;
    def->is_dll = is_dll;
  }
--- 654,669 ----
   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)
!     {
!        int len = strlen (image_name);
!        def->name = xmalloc (len + 5);
!        memcpy (def->name, image_name, len);
!        memcpy (def->name + len, is_dll ? ".dll\0" : ".exe\0", 5);    
!     }
!   else
!     def->name = xstrdup (image_name);
    def->base_address = base;
    def->is_dll = is_dll;
  }

Send instant messages to your online friends http://au.messenger.yahoo.com 
Reply | Threaded
Open this post in threaded view
|

Re: Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

Danny Smith-4

--- Danny Smith <[hidden email]> wrote:

> Hello
The last message omitted the doco part of the patch. Sorry.  Here it is again:

Hello

According to MS doc's (and comments in binutils/dlltool.c). the suffix
of the internal names of images defaults to ".exe" if the name is
specified by NAME statement in a .def file, and to ".dll" if specified
by a LIBRARY statement. Failing to append a suffix so can cause dll
import problems since it is this internal name that is put into the
import lib and used when searching for the libary at load time.  An
example of this problem is at:

https://sourceforge.net/tracker/index.php?func=detail&aid=1401442&group_id=2435&atid=102435
 
This fixes by appending a default suffix, if necessary, when we parse
the .def file.

ChangeLog

2006-02-01  Danny Smith  <[hidden email]>

        * deffilep.y (def_image_name): If the image name does not have a
        suffix, append the default.
        *ld.texinfo: Document NAME, LIBRARY usage in PE-COFF .def files.

Index: deffilep.y
===================================================================
RCS file: /cvs/src/src/ld/deffilep.y,v
retrieving revision 1.20
diff -c -3 -p -r1.20 deffilep.y
*** deffilep.y 12 May 2005 07:32:02 -0000 1.20
--- deffilep.y 1 Feb 2006 00:33:46 -0000
*************** def_image_name (const char *name, int ba
*** 654,660 ****
   def_filename, linenumber, is_dll ? "LIBRARY" : "NAME", name);
    if (def->name)
      free (def->name);
!   def->name = xstrdup (image_name);
    def->base_address = base;
    def->is_dll = is_dll;
  }
--- 654,669 ----
   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)
!     {
!        int len = strlen (image_name);
!        def->name = xmalloc (len + 5);
!        memcpy (def->name, image_name, len);
!        memcpy (def->name + len, is_dll ? ".dll\0" : ".exe\0", 5);    
!     }
!   else
!     def->name = xstrdup (image_name);
    def->base_address = base;
    def->is_dll = is_dll;
  }
Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.155
diff -c -3 -p -r1.155 ld.texinfo
*** ld.texinfo 31 Jan 2006 22:13:41 -0000 1.155
--- ld.texinfo 1 Feb 2006 00:34:08 -0000
*************** by "forwarding" to another module and tr
*** 5598,5603 ****
--- 5598,5619 ----
  @code{afoo} exported from the DLL @samp{abc.dll}. The final symbol
  @code{var1} is declared to be a data object.
 
+ The optional @code{LIBRARY <name>} command indicates the @emph{internal}
+ name of the output DLL. If @samp{<name>} does not include a suffix,
+ the default library suffix, @samp{.DLL} is appended.
+
+ When the .DEF file is used to build an application. rather than a
+ library, the @code{NAME <name>} command shoud be used instead of
+ @code{LIBRARY}. If @samp{<name>} does not include a suffix, the default
+ executable suffix, @samp{.EXE} is appended.
+
+ With either @code{LIBRARY <name>} or @code{NAME <name>} the optional
+ specification @code{BASE = <number>} may be used to specify a
+ 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:
 
  @example

Send instant messages to your online friends http://au.messenger.yahoo.com 
Reply | Threaded
Open this post in threaded view
|

Re: Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

Christopher Faylor
On Wed, Feb 01, 2006 at 01:40:28PM +1300, Danny Smith wrote:
>ChangeLog
>
>2006-02-01  Danny Smith  <[hidden email]>
>
> * deffilep.y (def_image_name): If the image name does not have a
> suffix, append the default.
> *ld.texinfo: Document NAME, LIBRARY usage in PE-COFF .def files.

Just a minor nit.

>!        memcpy (def->name + len, is_dll ? ".dll\0" : ".exe\0", 5);    

I don't see any reason for an explicit \0 in the above case.  That's
a given.  Was this just to make it clear where the fifth character was
coming from in the copy?

Also, on some architectures, I believe that strcpy would be faster
than memcpy for this operation.  Does using memcpy buy us anything here?

cgf
Reply | Threaded
Open this post in threaded view
|

Re: Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

Danny Smith

----- Original Message -----
From: "Christopher Faylor"
Sent: Wednesday, 1 February 2006 15:30


> On Wed, Feb 01, 2006 at 01:40:28PM +1300, Danny Smith wrote:
> >ChangeLog
> >
> >2006-02-01  Danny Smith  <[hidden email]>
> >
> > * deffilep.y (def_image_name): If the image name does not have a
> > suffix, append the default.
> > *ld.texinfo: Document NAME, LIBRARY usage in PE-COFF .def files.
>
> Just a minor nit.
>
> >!        memcpy (def->name + len, is_dll ? ".dll\0" : ".exe\0", 5);    
>
> I don't see any reason for an explicit \0 in the above case.  That's
> a given.  Was this just to make it clear where the fifth character was
> coming from in the copy?

Yes.
>
> Also, on some architectures, I believe that strcpy would be faster
> than memcpy for this operation.

I didn't know that.

  Does using memcpy buy us anything here?

I had just called memcpy in line above, so I called it again
But if strcpy is faster, I'll change to that.

Danny
>
> cgf

Reply | Threaded
Open this post in threaded view
|

Re: Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

Nick Clifton
Hi Danny,

>>Also, on some architectures, I believe that strcpy would be faster
>>than memcpy for this operation.
>
> I didn't know that.
>
>   Does using memcpy buy us anything here?
>
> I had just called memcpy in line above, so I called it again
> But if strcpy is faster, I'll change to that.

Do we really need to be concerned about speed here ?
I think that clarity of code is more important in this case, and so I
would recommend a simpler approach, eg:

   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);
     }

Cheers
   Nick
Reply | Threaded
Open this post in threaded view
|

Re: Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

Danny Smith

----- Original Message -----
From: "Nick Clifton"
Sent: Thursday, 2 February 2006 00:25
> Hi Danny,


> Do we really need to be concerned about speed here ?
> I think that clarity of code is more important in this case, and so I
> would recommend a simpler approach, eg:
>
>    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);
>      }
>
> Cheers
>    Nick
Thanks. Attached patch uses your suggestion above.

Regards
Danny




ChangeLog

2006-02-02  Danny Smith  <[hidden email]>

        * deffilep.y (def_image_name): If the image name does not have
        a suffix, append the default.
        * ld.texinfo: Document NAME, LIBRARY usage in PE-COFF .def files.



.

def_name_suffix.diff (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Patch/PE-COFF: Provide default suffix to NAME or LIBRARY names in .def files

Christopher Faylor
On Thu, Feb 02, 2006 at 09:24:06AM +1300, Danny Smith wrote:

>----- Original Message -----
>From: "Nick Clifton"
>Sent: Thursday, 2 February 2006 00:25
>> Hi Danny,
>
>
>> Do we really need to be concerned about speed here ?
>> I think that clarity of code is more important in this case, and so I
>> would recommend a simpler approach, eg:
>>
>>    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);
>>      }
>>
>
>Thanks. Attached patch uses your suggestion above.

Looks good to me.  Go ahead and check it in.

cgf