[PATCH] ld: pe-dll: Fix MS link.exe linking against two ld generated import libraries

Nick Clifton nickc@redhat.com
Tue Jan 11 15:45:58 GMT 2022


Hi Martin,

> MS link.exe can successfully link against import libraries generated
> by ld (via the --out-implib option). However, if linking against more
> than one such import library at a time, then MS link.exe produces
> intermixed import tables for those DLL files.
> 
> MS link.exe seems to sort the individual object files in the import
> library based on their member names, without taking library
> boundaries into consideration. E.g. when both libfoo.a and libbar.a
> contain object files named d000.o, d001.o, d002.o, MS link.exe orders
> them as libfoo.a(d000.o) libbar.a(d000.o) libfoo.a(d001.o) libbar.a(d001.o)
> etc. This breaks the implicit assumption that these object files need
> to be grouped tightly together within one import library.
> 
> This has not been an issue when MS link.exe links against import
> libraries produced by dlltool, as the object files there use a
> pseudorandom prefix (based on the dlltool process ID).
> 
> Thus this avoids needing to regenerate import libraries with dlltool, if
> linking a DLL which is going to be linked against by MS link.exe.
> 

Patch approved and applied.  Thanks for fixing this problem.

Cheers
   Nick



More information about the Binutils mailing list