[PATCH] ld/PE: Handle MS style import libraries for files named *.exe too
Martin Storsjö
martin@martin.st
Wed Nov 6 09:31:11 GMT 2024
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.
Thus extend the preexisting check from checking for the .dll
suffix to also checking for .exe. While this isn't entirely
complete and scalable (in theory, such libraries could have
any suffix), this should cover a larger majority of them.
This doesn't conflict with the regular long import libraries that
GNU tools generate, where each member file has a name ending with
.o.
---
ld/emultempl/pe.em | 3 ++-
ld/emultempl/pep.em | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 869ffd3f623..ee4cb80d617 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -1753,7 +1753,8 @@ gld${EMULATION_NAME}_after_open (void)
objects. */
pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
- if (pnt != NULL && (fileext_cmp (pnt + 1, "dll") == 0))
+ if (pnt != NULL && (fileext_cmp (pnt + 1, "dll") == 0 ||
+ fileext_cmp (pnt + 1, "exe") == 0))
{
int idata2 = 0, reloc_count = 0, idata = 0;
asection *sec;
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index c225d052fb8..9c5f7a49329 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -1736,7 +1736,8 @@ gld${EMULATION_NAME}_after_open (void)
objects. */
pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
- if (pnt != NULL && (fileext_cmp (pnt + 1, "dll") == 0))
+ if (pnt != NULL && (fileext_cmp (pnt + 1, "dll") == 0 ||
+ fileext_cmp (pnt + 1, "exe") == 0))
{
int idata2 = 0, reloc_count = 0, idata = 0;
asection *sec;
--
2.34.1
More information about the Binutils
mailing list