Re: [Mingw-w64-public] [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

2024-04-16 Thread LIU Hao

在 2024-04-17 05:08, Martin Storsjö 写道:

Thanks, I think this one looks reasonable.



Thanks. Pushed now.

--
Best regards,
LIU Hao



OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

2024-04-16 Thread Martin Storsjö

On Tue, 16 Apr 2024, LIU Hao wrote:


在 2024-04-16 15:30, Martin Storsjö 写道:
I'm not at all familiar with these APIs and DLLs, so I don't quite know 
what the best way forward is. But the fact that the same functions can be 
declared with different calling conventions is indeed a bit of a problem. 
If nobody really are using the files, it's probably ok to just remove them, 
or remove the symbols and leave comments explaining the sitaution.




Well, I think this awkward DEF should be kept for backward compatibility.

An updated patch is attached.


Thanks, I think this one looks reasonable.

// Martin

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

2024-04-16 Thread LIU Hao

在 2024-04-16 15:30, Martin Storsjö 写道:
I'm not at all familiar with these APIs and DLLs, so I don't quite know what the best way forward 
is. But the fact that the same functions can be declared with different calling conventions is 
indeed a bit of a problem. If nobody really are using the files, it's probably ok to just remove 
them, or remove the symbols and leave comments explaining the sitaution.




Well, I think this awkward DEF should be kept for backward compatibility.

An updated patch is attached.


--
Best regards,
LIU Hao

From cf60a31beaccfd85c7bde845b5003e402450b98b Mon Sep 17 00:00:00 2001
From: LIU Hao 
Date: Tue, 16 Apr 2024 22:13:07 +0800
Subject: [PATCH] crt: Fix some symbols with duplicate stdcall suffixes

Some of these functions, such as `ConvertAtJobsToTasks`, are exported with both
undecorated and decorated names, respectively, `ConvertAtJobsToTasks` and
`_ConvertAtJobsToTasks@0`. The decorated names are almost useless for C code
anyway and are removed.

Some other stdcall functions, such as `__fls_getvalue`, are only exported with
decorated names. A new macro `DECORATED_EXPORT()` is introduced for them.

This fixes errors like

   #include 
   #include 

   /* This was `__stdcall` in X3DAUDIO1_2.DLL, and changed to `__cdecl` later.  
*/
   __declspec(dllimport) void __stdcall X3DAudioCalculate(void*, void*, void*, 
UINT, void*);

   int main(void)
 {
   printf("X3DAudioCalculate = %p\n", (void*)(INT_PTR) X3DAudioCalculate);
 }

which used to result in

   test.c:(.text+0xf): undefined reference to `_imp__X3DAudioCalculate@20'

Signed-off-by: LIU Hao 
---
 mingw-w64-crt/def-include/msvcrt-common.def.in |  3 +++
 mingw-w64-crt/lib32/mstask.def | 13 -
 mingw-w64-crt/lib32/msvcr100.def.in|  4 ++--
 mingw-w64-crt/lib32/msvcr90.def.in |  4 ++--
 mingw-w64-crt/lib32/msvcr90d.def.in|  4 ++--
 mingw-w64-crt/lib32/msvcrt20.def.in|  2 +-
 mingw-w64-crt/lib32/t2embed.def| 11 ---
 mingw-w64-crt/lib32/usbd.def   | 12 +++-
 mingw-w64-crt/lib32/x3daudio1_2.def|  6 ++
 9 files changed, 15 insertions(+), 44 deletions(-)

diff --git a/mingw-w64-crt/def-include/msvcrt-common.def.in 
b/mingw-w64-crt/def-include/msvcrt-common.def.in
index 9728b5ab8..975df5da9 100644
--- a/mingw-w64-crt/def-include/msvcrt-common.def.in
+++ b/mingw-w64-crt/def-include/msvcrt-common.def.in
@@ -3,6 +3,9 @@
 #define ADD_UNDERSCORE(symbol) symbol == _ ## symbol
 #define ADD_DOUBLE_UNDERSCORE(symbol) symbol == __ ## symbol
 
+// for __cdecl and __stdcall only
+#define DECORATED_EXPORT(symbol) symbol == _ ## symbol
+
 ADD_DOUBLE_UNDERSCORE(iscsymf)
 ADD_DOUBLE_UNDERSCORE(iscsym)
 ADD_DOUBLE_UNDERSCORE(isascii)
diff --git a/mingw-w64-crt/lib32/mstask.def b/mingw-w64-crt/lib32/mstask.def
index 2cc5298e7..ba8f873a0 100644
--- a/mingw-w64-crt/lib32/mstask.def
+++ b/mingw-w64-crt/lib32/mstask.def
@@ -18,16 +18,3 @@ SAGetNSAccountInformation@12
 SASetAccountInformation@20
 SASetNSAccountInformation@12
 SetNetScheduleAccountInformation@12
-_ConvertAtJobsToTasks@0@0
-_DllCanUnloadNow@0@0
-_DllGetClassObject@12@12
-_GetNetScheduleAccountInformation@12@12
-_NetrJobAdd@12@12
-_NetrJobDel@12@12
-_NetrJobEnum@20@20
-_NetrJobGetInfo@12@12
-_SAGetAccountInformation@16@16
-_SAGetNSAccountInformation@12@12
-_SASetAccountInformation@20@20
-_SASetNSAccountInformation@12@12
-_SetNetScheduleAccountInformation@12@12
diff --git a/mingw-w64-crt/lib32/msvcr100.def.in 
b/mingw-w64-crt/lib32/msvcr100.def.in
index e2e0e18c7..00d99124b 100644
--- a/mingw-w64-crt/lib32/msvcr100.def.in
+++ b/mingw-w64-crt/lib32/msvcr100.def.in
@@ -626,8 +626,8 @@ __daylight
 __dllonexit
 __doserrno
 __dstbias
-___fls_getvalue@4@4
-___fls_setvalue@8@8
+DECORATED_EXPORT(__fls_getvalue@4)
+DECORATED_EXPORT(__fls_setvalue@8)
 __fpecode
 __free_locale
 __get_current_locale
diff --git a/mingw-w64-crt/lib32/msvcr90.def.in 
b/mingw-w64-crt/lib32/msvcr90.def.in
index 4424adfe5..c5a70d3e9 100644
--- a/mingw-w64-crt/lib32/msvcr90.def.in
+++ b/mingw-w64-crt/lib32/msvcr90.def.in
@@ -230,8 +230,8 @@ __daylight
 __dllonexit
 __doserrno
 __dstbias
-___fls_getvalue@4@4
-___fls_setvalue@8@8
+DECORATED_EXPORT(__fls_getvalue@4)
+DECORATED_EXPORT(__fls_setvalue@8)
 __fpecode
 __free_locale
 __get_app_type
diff --git a/mingw-w64-crt/lib32/msvcr90d.def.in 
b/mingw-w64-crt/lib32/msvcr90d.def.in
index 2835301f0..ba7dffa1c 100644
--- a/mingw-w64-crt/lib32/msvcr90d.def.in
+++ b/mingw-w64-crt/lib32/msvcr90d.def.in
@@ -270,8 +270,8 @@ __daylight
 __dllonexit
 __doserrno
 __dstbias
-___fls_getvalue@4@4
-___fls_setvalue@8@8
+DECORATED_EXPORT(__fls_getvalue@4)
+DECORATED_EXPORT(__fls_setvalue@8)
 __fpecode
 __free_locale
 __get_app_type
diff --git a/mingw-w64-crt/lib32/msvcrt20.def.in 
b/mingw-w64-crt/lib32/msvcrt20.def.in
index d2702db90..1ac4d4701 100644
--- a/mingw-w64-crt/lib32/msvcrt20.def.in
+++ b/mingw-w64-crt/lib32/msvcrt20.def.in
@@ -1168,7 

Re: [Mingw-w64-public] [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

2024-04-16 Thread LIU Hao

在 2024-04-16 05:19, Martin Storsjö 写道:

Hmm, I would prefer if you'd add a new macro for this purpose, instead of 
reusing the old one.

The old existing one is used to add aliases for functions, usually like this:

---
_somefunc
ADD_UNDERSCORE(somefunc)
---

But here, you're adding an alias as a way to specify the literal DLL import name, as a way to undo 
the effect of dlltool's "-k" option for one single symbol. So I see it semantically as a different 
thing, so a new macro, e.g. "LITERAL_STDCALL(somefunc@4)" instead. Or maybe KEEP_STDCALL() or 
something like that?


(The reason why I want to make the distinction, is both because I feel that it's semantically a 
different thing, but also because llvm-dlltool doesn't handle this exact case right now, it only 
works with the aliases in the former style. But I think it should be possible to improve 
llvm-dlltool to make this case work as well.)'


Yes, this is indeed abuse.

I can add a macro for MSVCR* DLLs, but, this patch includes a hunk for 'x3daudio1_2.def', which is 
consumed without `-DDEF_I386` etc. I have an impression that 'lib32/*.def' should not use those macros.


And not only is 'x3daudio1_2.def', the only two functions which it exports have changed to __cdecl, 
and require an incompatible header (which doesn't exist however). Another option would be to just 
drop this file.




--
Best regards,
LIU Hao



OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

2024-04-16 Thread Martin Storsjö

On Tue, 16 Apr 2024, LIU Hao wrote:


在 2024-04-16 05:19, Martin Storsjö 写道:
Hmm, I would prefer if you'd add a new macro for this purpose, instead of 
reusing the old one.


The old existing one is used to add aliases for functions, usually like 
this:


---
_somefunc
ADD_UNDERSCORE(somefunc)
---

But here, you're adding an alias as a way to specify the literal DLL import 
name, as a way to undo the effect of dlltool's "-k" option for one single 
symbol. So I see it semantically as a different thing, so a new macro, e.g. 
"LITERAL_STDCALL(somefunc@4)" instead. Or maybe KEEP_STDCALL() or something 
like that?


(The reason why I want to make the distinction, is both because I feel that 
it's semantically a different thing, but also because llvm-dlltool doesn't 
handle this exact case right now, it only works with the aliases in the 
former style. But I think it should be possible to improve llvm-dlltool to 
make this case work as well.)'


Yes, this is indeed abuse.

I can add a macro for MSVCR* DLLs, but, this patch includes a hunk for 
'x3daudio1_2.def', which is consumed without `-DDEF_I386` etc. I have an 
impression that 'lib32/*.def' should not use those macros.


We can either spell it out manually, like what we have currently in 
x3daudio1_2.def (I guess the main bug there is that it should be 
"X3DAudioCalculate@20 == _X3DAudioCalculate@20" without the leading "_" at 
the start of the line?).


Or rename the file to .def.in; there's nothing saying that we can't use 
.def file preprocessing for files in lib32, it's just that we haven't 
really usually needed it so far.


And not only is 'x3daudio1_2.def', the only two functions which it exports 
have changed to __cdecl, and require an incompatible header (which doesn't 
exist however). Another option would be to just drop this file.


Yes, that bit seems like a big mess too.

I'm not at all familiar with these APIs and DLLs, so I don't quite know 
what the best way forward is. But the fact that the same functions can be 
declared with different calling conventions is indeed a bit of a problem. 
If nobody really are using the files, it's probably ok to just remove 
them, or remove the symbols and leave comments explaining the sitaution.


// Martin

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

2024-04-15 Thread Martin Storsjö

On Tue, 16 Apr 2024, LIU Hao wrote:

1. There is currently no 'x3daudio.h' in mingw-w64. Wine and Windows SDK 
headers have
  `X3DAudioInitialize()` and `X3DAudioCalculate()` as `__cdecl`, but they 
are really

  `__stdcall` in X3DAUDIO1_2.DLL.

2. The macros `ADD_UNDERSCORE()` and `ADD_DOUBLE_UNDERSCORE()` are moved from
  'msvcrt-common.def.in' to 'func.def.in' so they can be reused. Previously 
they

  were only used by 'msvcr*.def.in'.


Hmm, I would prefer if you'd add a new macro for this purpose, instead of 
reusing the old one.


The old existing one is used to add aliases for functions, usually like 
this:


---
_somefunc
ADD_UNDERSCORE(somefunc)
---

But here, you're adding an alias as a way to specify the literal DLL 
import name, as a way to undo the effect of dlltool's "-k" option for one 
single symbol. So I see it semantically as a different thing, so a new 
macro, e.g. "LITERAL_STDCALL(somefunc@4)" instead. Or maybe KEEP_STDCALL() 
or something like that?


(The reason why I want to make the distinction, is both because I feel 
that it's semantically a different thing, but also because llvm-dlltool 
doesn't handle this exact case right now, it only works with the aliases 
in the former style. But I think it should be possible to improve 
llvm-dlltool to make this case work as well.)


// Martin



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

2024-04-15 Thread LIU Hao

1. There is currently no 'x3daudio.h' in mingw-w64. Wine and Windows SDK 
headers have
   `X3DAudioInitialize()` and `X3DAudioCalculate()` as `__cdecl`, but they are 
really
   `__stdcall` in X3DAUDIO1_2.DLL.

2. The macros `ADD_UNDERSCORE()` and `ADD_DOUBLE_UNDERSCORE()` are moved from
   'msvcrt-common.def.in' to 'func.def.in' so they can be reused. Previously 
they
   were only used by 'msvcr*.def.in'.

3. 'lib32/usbd.def' was regenerated from USBD.SYS from Windows XP 32-bit.



--
Best regards,
LIU Hao

From 357c980c8a7b472a8e115b7af942531be915242b Mon Sep 17 00:00:00 2001
From: LIU Hao 
Date: Mon, 15 Apr 2024 23:08:08 +0800
Subject: [PATCH 2/2] crt: Fix some symbols with duplicate stdcall suffixes

Some of these functions, such as `ConvertAtJobsToTasks`, are exported with both
undecorated and decorated names, respectively, `ConvertAtJobsToTasks` and
`_ConvertAtJobsToTasks@0`. The decorated names are almost useless for C code
anyway and are removed.

Some other stdcall functions, such as `__fls_getvalue`, are only exported with
decorated names. We have the macro `ADD_UNDERSCORE()` for them.

This fixes errors like

   #include 
   #include 

   /* This was `__stdcall` in X3DAUDIO1_2.DLL, and changed to `__cdecl` later.  
*/
   __declspec(dllimport) void __stdcall X3DAudioCalculate(void*, void*, void*, 
UINT, void*);

   int main(void)
 {
   printf("X3DAudioCalculate = %p\n", (void*)(INT_PTR) X3DAudioCalculate);
 }

which used to result in

   test.c:(.text+0xf): undefined reference to `_imp__X3DAudioCalculate@20'

Signed-off-by: LIU Hao 
---
 mingw-w64-crt/def-include/func.def.in  |  3 +++
 mingw-w64-crt/def-include/msvcrt-common.def.in |  3 ---
 mingw-w64-crt/lib32/mstask.def | 13 -
 mingw-w64-crt/lib32/msvcr100.def.in|  4 ++--
 mingw-w64-crt/lib32/msvcr90.def.in |  4 ++--
 mingw-w64-crt/lib32/msvcr90d.def.in|  4 ++--
 mingw-w64-crt/lib32/msvcrt20.def.in|  2 +-
 mingw-w64-crt/lib32/t2embed.def| 11 ---
 mingw-w64-crt/lib32/usbd.def   | 12 +++-
 mingw-w64-crt/lib32/x3daudio1_2.def| 11 ---
 mingw-w64-crt/lib32/x3daudio1_2.def.in |  6 ++
 11 files changed, 19 insertions(+), 54 deletions(-)
 delete mode 100644 mingw-w64-crt/lib32/x3daudio1_2.def
 create mode 100644 mingw-w64-crt/lib32/x3daudio1_2.def.in

diff --git a/mingw-w64-crt/def-include/func.def.in 
b/mingw-w64-crt/def-include/func.def.in
index 58cc36d86..c67b6efe1 100644
--- a/mingw-w64-crt/def-include/func.def.in
+++ b/mingw-w64-crt/def-include/func.def.in
@@ -55,3 +55,6 @@
 #ifndef F_NON_I386
 #define F_NON_I386(x)
 #endif
+
+#define ADD_UNDERSCORE(symbol) symbol == _ ## symbol
+#define ADD_DOUBLE_UNDERSCORE(symbol) symbol == __ ## symbol
diff --git a/mingw-w64-crt/def-include/msvcrt-common.def.in 
b/mingw-w64-crt/def-include/msvcrt-common.def.in
index 9728b5ab8..80ce5e9fe 100644
--- a/mingw-w64-crt/def-include/msvcrt-common.def.in
+++ b/mingw-w64-crt/def-include/msvcrt-common.def.in
@@ -1,8 +1,5 @@
 #include "func.def.in"
 
-#define ADD_UNDERSCORE(symbol) symbol == _ ## symbol
-#define ADD_DOUBLE_UNDERSCORE(symbol) symbol == __ ## symbol
-
 ADD_DOUBLE_UNDERSCORE(iscsymf)
 ADD_DOUBLE_UNDERSCORE(iscsym)
 ADD_DOUBLE_UNDERSCORE(isascii)
diff --git a/mingw-w64-crt/lib32/mstask.def b/mingw-w64-crt/lib32/mstask.def
index 2cc5298e7..ba8f873a0 100644
--- a/mingw-w64-crt/lib32/mstask.def
+++ b/mingw-w64-crt/lib32/mstask.def
@@ -18,16 +18,3 @@ SAGetNSAccountInformation@12
 SASetAccountInformation@20
 SASetNSAccountInformation@12
 SetNetScheduleAccountInformation@12
-_ConvertAtJobsToTasks@0@0
-_DllCanUnloadNow@0@0
-_DllGetClassObject@12@12
-_GetNetScheduleAccountInformation@12@12
-_NetrJobAdd@12@12
-_NetrJobDel@12@12
-_NetrJobEnum@20@20
-_NetrJobGetInfo@12@12
-_SAGetAccountInformation@16@16
-_SAGetNSAccountInformation@12@12
-_SASetAccountInformation@20@20
-_SASetNSAccountInformation@12@12
-_SetNetScheduleAccountInformation@12@12
diff --git a/mingw-w64-crt/lib32/msvcr100.def.in 
b/mingw-w64-crt/lib32/msvcr100.def.in
index e2e0e18c7..b802b288c 100644
--- a/mingw-w64-crt/lib32/msvcr100.def.in
+++ b/mingw-w64-crt/lib32/msvcr100.def.in
@@ -626,8 +626,8 @@ __daylight
 __dllonexit
 __doserrno
 __dstbias
-___fls_getvalue@4@4
-___fls_setvalue@8@8
+ADD_UNDERSCORE(__fls_getvalue@4)
+ADD_UNDERSCORE(__fls_setvalue@8)
 __fpecode
 __free_locale
 __get_current_locale
diff --git a/mingw-w64-crt/lib32/msvcr90.def.in 
b/mingw-w64-crt/lib32/msvcr90.def.in
index 4424adfe5..1bc161a5f 100644
--- a/mingw-w64-crt/lib32/msvcr90.def.in
+++ b/mingw-w64-crt/lib32/msvcr90.def.in
@@ -230,8 +230,8 @@ __daylight
 __dllonexit
 __doserrno
 __dstbias
-___fls_getvalue@4@4
-___fls_setvalue@8@8
+ADD_UNDERSCORE(__fls_getvalue@4)
+ADD_UNDERSCORE(__fls_setvalue@8)
 __fpecode
 __free_locale
 __get_app_type
diff --git a/mingw-w64-crt/lib32/msvcr90d.def.in 
b/mingw-w64-crt/lib32/msvcr90d.def.in
index 2835301f0..61c63b65b 100644