public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: fix 32-bit mingw DLL symbol export bug
@ 2023-12-26 14:24 Oleg Tolmatcev
  2024-01-16 20:40 ` Oleg Tolmatcev
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Tolmatcev @ 2023-12-26 14:24 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 896 bytes --]

Hello,

I think there's a bug in ld on 32-bit Windows.Here is a tiny project
for reproducing the problem. https://github.com/oltolm/ld-mingw32-bug

A 32-bit DLL exports two stdcall functions "myfunc" and "myfunc64".
The functions would normally get exported as "myfunc@0" and
"myfunc64@0". The "DEF" file exports them as "myfunc" and "myfunc64"
without the decorations. When you run the executable it shows an error
message saying that it can not find "myfunc64". I think it happens
because the sorting in ld is wrong.

I think it should use the exported names "myfunc" and "myfunc64", but
instead it uses the decorated names "myfunc@0" or "myfunc65@0". The
ordering of functions in the DLL is different depending on which names
you use.

My patch changes ld to use undecorated exported names for sorting and
it seems to fix the problem. When I execute ctest in my project, it
runs successfully.

[-- Attachment #2: 0001-ld-fix-32-bit-mingw-DLL-symbol-export-bug.patch --]
[-- Type: application/octet-stream, Size: 948 bytes --]

From c5ffcde3277e3aec48f0f1f2689fd628b3972d2f Mon Sep 17 00:00:00 2001
From: oltolm <oleg.tolmatcev@gmail.com>
Date: Tue, 26 Dec 2023 14:42:39 +0100
Subject: [PATCH] ld: fix 32-bit mingw DLL symbol export bug

Signed-off-by: oltolm <oleg.tolmatcev@gmail.com>
---
 ld/deffilep.y | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/ld/deffilep.y b/ld/deffilep.y
index 33c8cf35c5..45f90306e3 100644
--- a/ld/deffilep.y
+++ b/ld/deffilep.y
@@ -610,12 +610,11 @@ cmp_export_elem (const def_file_export *e, const char *ex_name,
 {
   int r;
 
-  if ((r = are_names_equal (ex_name, e->name)) != 0)
+  if ((r = are_names_equal (its_name ? its_name : ex_name,
+			    e->its_name ? e->its_name : e->name)) != 0)
     return r;
   if ((r = are_names_equal (in_name, e->internal_name)) != 0)
     return r;
-  if ((r = are_names_equal (its_name, e->its_name)) != 0)
-    return r;
   return (ord - e->ordinal);
 }
 
-- 
2.43.0.windows.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: fix 32-bit mingw DLL symbol export bug
  2023-12-26 14:24 [PATCH] ld: fix 32-bit mingw DLL symbol export bug Oleg Tolmatcev
@ 2024-01-16 20:40 ` Oleg Tolmatcev
  2024-01-19 11:40   ` Nick Clifton
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Tolmatcev @ 2024-01-16 20:40 UTC (permalink / raw)
  To: binutils

Hello,

can I ask about my patch, now that the release is near?

Best regards
Oleg Tolmatcev

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: fix 32-bit mingw DLL symbol export bug
  2024-01-16 20:40 ` Oleg Tolmatcev
@ 2024-01-19 11:40   ` Nick Clifton
  2024-01-19 12:34     ` Oleg Tolmatcev
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Clifton @ 2024-01-19 11:40 UTC (permalink / raw)
  To: Oleg Tolmatcev, binutils

Hi Oleg,

> can I ask about my patch, now that the release is near?

Yes you can.  Please can you point me at the patch ?
I seem to have lost it from my email queue. :-(

Cheers
   Nick



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: fix 32-bit mingw DLL symbol export bug
  2024-01-19 11:40   ` Nick Clifton
@ 2024-01-19 12:34     ` Oleg Tolmatcev
  2024-01-19 15:06       ` Nick Clifton
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Tolmatcev @ 2024-01-19 12:34 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

Am Fr., 19. Jan. 2024 um 12:40 Uhr schrieb Nick Clifton <nickc@redhat.com>:

> Yes you can.  Please can you point me at the patch ?
> I seem to have lost it from my email queue. :-(

Here it is https://sourceware.org/pipermail/binutils/2023-December/131416.html.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: fix 32-bit mingw DLL symbol export bug
  2024-01-19 12:34     ` Oleg Tolmatcev
@ 2024-01-19 15:06       ` Nick Clifton
  2024-01-19 16:07         ` Oleg Tolmatcev
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Clifton @ 2024-01-19 15:06 UTC (permalink / raw)
  To: Oleg Tolmatcev; +Cc: binutils

Hi Oleg,

>> Yes you can.  Please can you point me at the patch ?
>> I seem to have lost it from my email queue. :-(
> 
> Here it is https://sourceware.org/pipermail/binutils/2023-December/131416.html.

Thanks.

I have gone ahead and applied the patch.  I am not an expert
on win32 function call APIs, so I am assuming that your patch
is correct.  If people start to complain, then we will have to
take another look. :-)

Cheers
   Nick



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: fix 32-bit mingw DLL symbol export bug
  2024-01-19 15:06       ` Nick Clifton
@ 2024-01-19 16:07         ` Oleg Tolmatcev
  0 siblings, 0 replies; 6+ messages in thread
From: Oleg Tolmatcev @ 2024-01-19 16:07 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

Am Fr., 19. Jan. 2024 um 16:06 Uhr schrieb Nick Clifton <nickc@redhat.com>:


> I have gone ahead and applied the patch.  I am not an expert
> on win32 function call APIs, so I am assuming that your patch
> is correct.  If people start to complain, then we will have to
> take another look. :-)

Thanks. Can you close this ticket
https://sourceware.org/bugzilla/show_bug.cgi?id=21033? I fixed it in
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6aadf8a04d162feb2afe3c41f5b36534d661d447.

Best regards
Oleg Tolmatcev

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-19 16:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 14:24 [PATCH] ld: fix 32-bit mingw DLL symbol export bug Oleg Tolmatcev
2024-01-16 20:40 ` Oleg Tolmatcev
2024-01-19 11:40   ` Nick Clifton
2024-01-19 12:34     ` Oleg Tolmatcev
2024-01-19 15:06       ` Nick Clifton
2024-01-19 16:07         ` Oleg Tolmatcev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).