idata allegedly missing (Win32)

Jan Beulich jbeulich@suse.com
Fri May 2 06:11:05 GMT 2025


On 01.05.2025 09:06, Paul Edwards wrote:
> On Thu, May 1, 2025 at 4:58 PM Paul Edwards <mutazilah@gmail.com> wrote:
>> So using this:
>>
>> https://sourceforge.net/p/pdos/gitcode/ci/master/tree/pdpclib/makefile.std
>>
>> and the tools provided by http://pdos.org/pdos.zip
>>
>> I am able to produce Win32 executables successfully
>> using pdld (ie not related to binutils):
>>
>>
>> Here it is running on my Windows 2000 system:
>>
>> D:\devel\pdos\pdpclib>pdmake -f makefile.std
>>
>> ...
>>
>> pdas --oformat coff -o dllcrt.obj dllcrt.s
>> rm -f dllcrt.s
>> as86 -o winsupa.obj -f coff winsupa.asm
>> rm -f temp.lib
>> xar r temp.lib stdio.obj string.obj stdlib.obj winsupa.obj
>> xar r temp.lib start.obj time.obj errno.obj assert.obj signal.obj
>> xar r temp.lib locale.obj ctype.obj setjmp.obj math.obj
>> xar s temp.lib
>> pdld -s --no-insert-timestamp -o msvcrt.dll --shared --out-implib
>> msvcrt.lib dllcrt.obj temp.lib
>> ../src/kernel32.lib
>> rm -f temp.lib
>> pdld -s -nostdlib --no-insert-timestamp -o pdptest.exe w32start.obj
>> pdptest.obj msvcrt.lib winsupa.obj setjmp.obj
>>
>> D:\devel\pdos\pdpclib>pdptest abc def
>> welcome to pdptest
>> main function is at 00401234
>> allocating 10 bytes
>> m1 is 003F2C80
>> allocating 20 bytes
>> m2 is 003F2C98
>> stack is around 0022FF80
>> printing arguments
>> argc = 3
>> arg 0 is <pdptest>
>> arg 1 is <abc>
>> arg 2 is <def>
>>
>> D:\devel\pdos\pdpclib>
>>
>>
>> And that does everything I want, so I'm fine.
>>
>> However, someone substituted this final link:
>>
>> pdld -s -nostdlib --no-insert-timestamp -o pdptest.exe w32start.obj
>> pdptest.obj msvcrt.lib winsupa.obj setjmp.obj
>>
>> with ld (ie binutils) from mingw - versions 2.38 and 2.42 were tried,
>> and that produced an executable that didn't work (no output
>> produced).
>>
>> A bug report was made to the pdld author in case they had
>> produced an invalid library (either kernel32.lib or msvcrt.lib)
>> that was causing binutils to choke.
>>
>> The pdld author insists that his archives are fine, and he
>> took a guess at what was wrong with binutils. So I am
>> reporting that guess in case anyone is interested.
>>
>>
>> I compared the .idata sections in the executables (see attached
>> pdldhd.txt and gnuldhd.txt and search for "Start of .idata" or the
>> attached screenshot).
>> 
>> It seems that GNU LD pdptest.exe is missing Import Directory Table
>> (https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#the-idata-section)
>> - the 20 bytes 28500000 00000000 00000000 F2500000 58500000.
>>
>> My guess is that GNU LD is expecting some undocumented archive member
>> to provide the Import Directory Table instead of doing it on its own
>> like PDLD does.

Afaik it uses MSVC libraries just fine; I'd guess that even if the pdld
generated ones were indeed fine, they have some (subtle) difference to
the MSVC ones. Hence the request above.

>> And he notes that gnu ld apparently silently fails instead of
>> giving an error. So I assume you don't think that is appropriate
>> behavior. If you don't want libraries produced by other tools
>> to be used - fine, but at least produce an error message when
>> someone provides a "bad" library. ie don't silently produce a
>> bad executable that fails without explanation.

Well, yes, that would be best. Given some of the internals of the linker
work here, that simply may not be feasible here without risking to emit
false warnings.

>> The way he has worded that suggests to me that there is
>> some wiggle room - maybe there is some documentation
>> to say that an archive contains an "import directory table"
>> and he just doesn't know where that documentation is.

Afaict it's generally the linker who's expected to instantiate that.
Iirc there are library variants generated by the GNU tools where this
is in the library itself, but as said - in order to be able to consume
MSVC-generated ones, the linker has to also be able to instantiate it
itself.

>> I still consider it to be a bug if the archive is violating the
>> documentation and ld silently produces an invalid
>> executable, but YMMV.
>>
>>
>> I'm not affected because I don't mix and match pdld and ld,
>> and nor does he, and nor do most people, so normally
>> no-one cares.
>>
>> But I care enough to document the issue publicly in case
>> it helps someone else in a similar situation.
>>
>> I have placed what I have access to at:
>>
>> http://pdos.org/ldidata.zip

I'll see about taking a look, but it may take a while for me to get to
that.

Jan

>> That has the msvcrt.lib that is potentially choking binutils.
>> And it has a doit.bat with the command to produce
>> pdptest.exe with pdld - and the working pdptest.exe.
>> I don't have mingw installed so can't reproduce the
>> non-working executable myself. If you really need that
>> done, I can ask someone to do it for me. I also provided
>> the mentioned screenshot and text files. I'll also attach
>> the screenshot to this message.
>>
>> Thanks. Paul.



More information about the Binutils mailing list