ada: Provide shared GNAT implib on Windows
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
Commit Message
Hi, below is a long existing patch in MSYS2's MINGW GCC, and I'm upstreaming it
because I think it's actually needed by all Windows targets, not only MSYS2 / mingw-w64.
Tested at https://github.com/dragon-archer/gcc-for-windows/pull/16, and it worked
well for all Windows targets including Cygwin.
-------
From ba748053d3fc59b000a6727780ba707985205174 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrgen=20Pfeifer?= <juergen@familiepfeifer.de>
Date: Wed, 5 Aug 2015 23:36:27 +0100
Subject: [PATCH] ada: Provide shared GNAT implib on Windows
This allow link against shared runtime on Windows.
Original commit:
https://github.com/msys2/MINGW-packages/commit/51b4eb3b702fdb38df0460180c2f8209a686aaec
gcc/ada/ChangeLog:
* gcc-interface/Makefile.in (gnatlib-shared-win32): Provide
import library.
Co-authored-by: Zhongteng Gui <dragon-archer@outlook.com>
Signed-off-by: Zhongteng Gui <dragon-archer@outlook.com>
---
gcc/ada/gcc-interface/Makefile.in | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On 11/3/26 17:38, Zhongteng Gui wrote:
> Hi, below is a long existing patch in MSYS2's MINGW GCC, and I'm upstreaming it
> because I think it's actually needed by all Windows targets, not only MSYS2 / mingw-w64.
>
> Tested at https://github.com/dragon-archer/gcc-for-windows/pull/16, and it worked
> well for all Windows targets including Cygwin.
>
> -------
>
> From ba748053d3fc59b000a6727780ba707985205174 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?J=C3=BCrgen=20Pfeifer?= <juergen@familiepfeifer.de>
> Date: Wed, 5 Aug 2015 23:36:27 +0100
> Subject: [PATCH] ada: Provide shared GNAT implib on Windows
>
> This allow link against shared runtime on Windows.
>
> Original commit:
> https://github.com/msys2/MINGW-packages/commit/51b4eb3b702fdb38df0460180c2f8209a686aaec
>
> gcc/ada/ChangeLog:
>
> * gcc-interface/Makefile.in (gnatlib-shared-win32): Provide
> import library.
>
> Co-authored-by: Zhongteng Gui <dragon-archer@outlook.com>
> Signed-off-by: Zhongteng Gui <dragon-archer@outlook.com>
> ---
> gcc/ada/gcc-interface/Makefile.in | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
> index ccd44caa551..2e84d3cb0c8 100644
> --- a/gcc/ada/gcc-interface/Makefile.in
> +++ b/gcc/ada/gcc-interface/Makefile.in
> @@ -797,12 +797,15 @@ gnatlib-shared-win32:
> $(PICFLAG_FOR_TARGET) \
> -o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
> $(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
> - $(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) $(MISCLIB)
> + $(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
> + -Wl,-out-implib,libgnat$(hyphen)$(LIBRARY_VERSION).dll.a \
> + $(MISCLIB)
> cd $(RTSDIR); $(GCC_FOR_ADA_RTS) -shared -shared-libgcc \
> $(PICFLAG_FOR_TARGET) \
> -o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
> $(GNATRTL_TASKING_OBJS) \
> $(SO_OPTS)libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
> + -Wl,-out-implib,libgnarl$(hyphen)$(LIBRARY_VERSION).dll.a \
> $(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext)
>
> gnatlib-shared-darwin:
Thanks, pushed to master branch.
> Hi, below is a long existing patch in MSYS2's MINGW GCC, and I'm upstreaming
> it because I think it's actually needed by all Windows targets, not only
> MSYS2 / mingw-w64.
No, it's actually needed by none of them, since GNU ld can directly link to
DLLs, see the GNU ld manual section 6.15 for a complete exposition, and we do
not use dllimport/dllexport decoration in Ada.
On 2026/11/04 23:36, Eric Botcazou wrote:
>> Hi, below is a long existing patch in MSYS2's MINGW GCC, and I'm upstreaming
>> it because I think it's actually needed by all Windows targets, not only
>> MSYS2 / mingw-w64.
>
> No, it's actually needed by none of them, since GNU ld can directly link to
> DLLs, see the GNU ld manual section 6.15 for a complete exposition, and we do
> not use dllimport/dllexport decoration in Ada.
>
I've just read the manual, and I think import library is still needed here.
According to the manual, directly link to DLL is possible, but usually not easy
to use under Cygwin/MSYS2, because:
1. GCC only adds -L<path>/lib by default, while DLLs are usually placed under
<path>/bin, so you have to manually add a -L for this.
2. DLLs are usually versioned, so you can't use -lfoo, but have to use, e.g. -lfoo-17
Regarding 2, I think we can slightly edit the original patch and remove $(LIBRARY_VERSION)
from import lib, so that we got libgnat.dll.a instead of libgnat-17.dll.a, and users can
easily link with -lgnat.
Below is a fixup patch.
---
From 8dea423acf74a67cdf7b758097fe9e0744c8c63c Mon Sep 17 00:00:00 2001
From: Zhongteng Gui <dragon-archer@outlook.com>
Date: Wed, 4 Nov 2026 23:57:17 +0800
Subject: [PATCH] ada: Make import lib unversioned
This alignes with other import libraries, and allows users to use -lgnat
instead of -lgnat-17 for linking.
Fixes r17-5944-gcfb2e0e8e9d7c5.
gcc/ada/ChangeLog:
* gcc-interface/Makefile.in (gnatlib-shared-win32): Remove
$(LIBRARY_VERSION) from import lib.
Signed-off-by: Zhongteng Gui <dragon-archer@outlook.com>
---
gcc/ada/gcc-interface/Makefile.in | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
index 6a91f12a7bd..6e6fa7ec0a2 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -798,14 +798,14 @@ gnatlib-shared-win32:
-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
$(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
- -Wl,-out-implib,libgnat$(hyphen)$(LIBRARY_VERSION).dll.a \
+ -Wl,-out-implib,libgnat.dll.a \
$(MISCLIB)
cd $(RTSDIR); $(GCC_FOR_ADA_RTS) -shared -shared-libgcc \
$(PICFLAG_FOR_TARGET) \
-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
$(GNATRTL_TASKING_OBJS) \
$(SO_OPTS)libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
- -Wl,-out-implib,libgnarl$(hyphen)$(LIBRARY_VERSION).dll.a \
+ -Wl,-out-implib,libgnarl.dll.a \
$(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext)
gnatlib-shared-darwin:
> I've just read the manual, and I think import library is still needed here.
Then you need to read it again!
> According to the manual, directly link to DLL is possible, but usually not
> easy to use under Cygwin/MSYS2, because:
>
> 1. GCC only adds -L<path>/lib by default, while DLLs are usually placed
> under <path>/bin, so you have to manually add a -L for this.
But that's not true for libgnat/libgnarl, see the install tree.
> 2. DLLs are usually versioned, so you can't use -lfoo, but have to use, e.g.
> -lfoo-17
That's automatically done by gnatmake and we need to keep the version number
because there is no stable ABI for these libraries.
> Regarding 2, I think we can slightly edit the original patch and remove
> $(LIBRARY_VERSION) from import lib, so that we got libgnat.dll.a instead of
> libgnat-17.dll.a, and users can easily link with -lgnat.
> Below is a fixup patch.
No, we definitely do not want that.
On 2026/11/05 00:17, Eric Botcazou wrote:
>> I've just read the manual, and I think import library is still needed here.
>
> Then you need to read it again!
>
>> According to the manual, directly link to DLL is possible, but usually not
>> easy to use under Cygwin/MSYS2, because:
>>
>> 1. GCC only adds -L<path>/lib by default, while DLLs are usually placed
>> under <path>/bin, so you have to manually add a -L for this.
>
> But that's not true for libgnat/libgnarl, see the install tree.
I understand that gnatmake and some other Ada tools will automatically do this,
but I think it might be better to still provide a import lib, so that you can
link to shared libgnat just like other libraries, e.g. libgcc. For example,
what if you have a project with mixed Ada/C/C++, and you want to use the C-style
way to build/link it?
There's also following snippet from gcc/ada/gnat_ugn.texi, line 17357
$@{LIB_DIR@}:
mkdir -p $@{dir $@@ @}
cd $@{dir $@@ @} && gcc -shared -o $@{notdir $@@ @} ../*.o -L$@{GLIB@} -lgnat
cd $@{dir $@@ @} && cp -f ../*.ali .
>
>> 2. DLLs are usually versioned, so you can't use -lfoo, but have to use, e.g.
>> -lfoo-17
>
> That's automatically done by gnatmake and we need to keep the version number
> because there is no stable ABI for these libraries.
That's OK if you want that, I'm not familiar with Ada. But I'd like to note that
on Linux, there's a libgnat.so -> libgnat-<version>.so symlink installed, so
-lgnat can work on Linux, and it might be suprising if it can't work on Windows.
>
>> Regarding 2, I think we can slightly edit the original patch and remove
>> $(LIBRARY_VERSION) from import lib, so that we got libgnat.dll.a instead of
>> libgnat-17.dll.a, and users can easily link with -lgnat.
>
>> Below is a fixup patch.
>
> No, we definitely do not want that.
>
> I understand that gnatmake and some other Ada tools will automatically do
> this, but I think it might be better to still provide a import lib, so that
> you can link to shared libgnat just like other libraries, e.g. libgcc. For
> example, what if you have a project with mixed Ada/C/C++, and you want to
> use the C-style way to build/link it?
But people have been doing this for decades...
On 2026/11/05 01:10, Eric Botcazou wrote:
>> I understand that gnatmake and some other Ada tools will automatically do
>> this, but I think it might be better to still provide a import lib, so that
>> you can link to shared libgnat just like other libraries, e.g. libgcc. For
>> example, what if you have a project with mixed Ada/C/C++, and you want to
>> use the C-style way to build/link it?
>
> But people have been doing this for decades...
>
Are you sure? There's lots of matches if you search for -lgnat, e.g. on GitHub [1]
Among these, many of them just calls gcc, not gnatmake or any Ada specific tools.
And is there any downside of providing an import library for it on Windows? People
can still directly link to the DLL if they want. It just allows another usage, and
it shouldn't break anything. The additional space is ignorable.
[1]: https://github.com/search?q=-lgnat&type=code
> And is there any downside of providing an import library for it on Windows?
> People can still directly link to the DLL if they want. It just allows
> another usage, and it shouldn't break anything. The additional space is
> ignorable.
Yes, it's totally useless and, therefore, a waste of energy and resources.
On 11/4/26 17:29, Eric Botcazou wrote:
>> And is there any downside of providing an import library for it on Windows?
>> People can still directly link to the DLL if they want. It just allows
>> another usage, and it shouldn't break anything. The additional space is
>> ignorable.
>
> Yes, it's totally useless and, therefore, a waste of energy and resources.
>
Should I revert the changes?
> Should I revert the changes?
Yes, please.
On 11/4/26 18:36, Eric Botcazou wrote:
>> Should I revert the changes?
>
> Yes, please.
>
Done, reverted in master branch.
@@ -797,12 +797,15 @@ gnatlib-shared-win32:
$(PICFLAG_FOR_TARGET) \
-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
- $(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) $(MISCLIB)
+ $(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
+ -Wl,-out-implib,libgnat$(hyphen)$(LIBRARY_VERSION).dll.a \
+ $(MISCLIB)
cd $(RTSDIR); $(GCC_FOR_ADA_RTS) -shared -shared-libgcc \
$(PICFLAG_FOR_TARGET) \
-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
$(GNATRTL_TASKING_OBJS) \
$(SO_OPTS)libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
+ -Wl,-out-implib,libgnarl$(hyphen)$(LIBRARY_VERSION).dll.a \
$(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext)
gnatlib-shared-darwin: