Lazarus

Free Pascal => General => Topic started by: 440bx on July 12, 2018, 06:36:36 am

Title: Library name in PE executable exports directory
Post by: 440bx on July 12, 2018, 06:36:36 am
Hello,

Though rare, an executable can export functions and/or data.  Borland/Embarcadero executables are known for that. 

When FPC finds an "exports" clause, it adds ".dll" to the executable's name, resulting in a mismatch between the name of the executable and the library name in the PE file's export directory.  This can cause problems.

For instance, if you have a program named "myprogram" which results in an executable named "myprogram.exe" and, it exports one or more of its functions, the library name in the exports directory will be "myprogram.dll" instead of what it should be: "myprogram.exe"  (without quotes, of course.)

If FPC is explicitly told the extension to use using the {$EXTENSION 'exe'} directive, then the library name ends up being "myprogram.exe.dll".  No matter what, it insists on appending a ".dll".    A mismatch in the library name and the actual filename can cause problems when using GetProcAddress to retrieve the addresses of the exported functions/data.

It shouldn't blindly append ".dll" to the name and, if an extension is specifically stated then it should definitely respect that.

Fortunately, the number of people affected will be few and far between but still, the library/executable name should be set correctly.

As Borland figured out long ago, exporting a few key items from an executable can be invaluable for a debugger that knows what to do with those imported "items".

Title: Re: Library name in PE executable exports directory
Post by: marcov on July 12, 2018, 10:55:14 am
Please file a bug.
Title: Re: Library name in PE executable exports directory
Post by: 440bx on July 12, 2018, 11:32:54 am
Please file a bug.
Done!
TinyPortal © 2005-2018