[PATCH v3] ld/PE: Handle MS style import libraries for files named *.exe too

Martin Storsjö martin@martin.st
Fri Nov 22 12:11:45 GMT 2024


On Thu, 21 Nov 2024, Jan Beulich wrote:

> On 21.11.2024 13:21, Martin Storsjö wrote:
>> On Thu, 21 Nov 2024, Jan Beulich wrote:
>>
>>> On 19.11.2024 14:27, Martin Storsjö wrote:
>>>> When handling MS style import libraries (also called short import
>>>> libraries, or ILF), we need to detect the kind of library.
>>>>
>>>> So far, this has been done by looking at the member file names
>>>> in the import library - in an MS style import library, all the
>>>> member files for a specific library have the same member file
>>>> name - the name of the runtime module to link against. Usually
>>>> this is a DLL - thus we do a case insensitive comparison and
>>>> check if the suffix is .dll.
>>>>
>>>> However, an .exe can also export symbols which can be linked
>>>> against in the same way. In particular, if linking against
>>>> WDK (Windows Driver Kit) import libraries, e.g. wdmsec.lib, the
>>>> import libraries can provide imports for ntoskrnl.exe.
>>>>
>>>> Instead of specifically checking for *.dll (and *.exe, etc),
>>>> invert the condition and skip archive members named *.o and *.obj.
>>>> For any remaining archive members, that do contain .idata
>>>> sections, apply the renaming. (The renaming is also mostly
>>>> harmless if applied where it isn't needed; if archive members
>>>> already have unique file names, their relative ordering should
>>>> remain intact except for very contrieved cases.)
>>>
>>> Okay. Just one nit on comment text:
>>>
>>>> --- a/ld/emultempl/pe.em
>>>> +++ b/ld/emultempl/pe.em
>>>> @@ -1747,13 +1747,28 @@ gld${EMULATION_NAME}_after_open (void)
>>>>
>>>>  	    /* Microsoft import libraries may contain archive members for
>>>>  	       one or more DLLs, together with static object files.
>>>> -	       Inspect all members that are named *.dll - check whether
>>>> -	       they contain .idata sections. Do the renaming of all
>>>> -	       archive members that seem to be Microsoft style import
>>>> -	       objects.  */
>>>> +	       The head and sentinels are regular COFF object files,
>>>> +	       while the thunks are special ILF files that get synthesized
>>>> +	       by bfd into COFF object files.
>>>> +
>>>> +	       As Microsoft import libraries can be for a module with
>>>> +	       almost any file name (*.dll, *.exe, etc), we can't easily
>>>> +	       know which archive members to inspect.
>>>> +
>>>> +	       Inspect all members unless ones named *.o or *.obj (which
>>>
>>> While I'm not a native speaker, I think this wants to be either "Inspect
>>> all members, except ones ..." or "Inspect all members unless named ...".
>>
>> Oh, indeed, yes.
>>
>> Ok to push with that changed?
>
> Yes.

Thanks, this is pushed now.

// Martin


More information about the Binutils mailing list