GNU bug report logs - #74175
libtool mishandles some compiler flags when used with MSVC tools

Previous Next

Package: libtool;

Reported by: Kirill Makurin <maiddaisuki <at> outlook.com>

Date: Sat, 2 Nov 2024 07:52:02 UTC

Severity: normal

Done: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>

To reply to this bug, email your comments to 74175 AT debbugs.gnu.org.
There is no need to reopen the bug first.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-libtool <at> gnu.org:
bug#74175; Package libtool. (Sat, 02 Nov 2024 07:52:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kirill Makurin <maiddaisuki <at> outlook.com>:
New bug report received and forwarded. Copy sent to bug-libtool <at> gnu.org. (Sat, 02 Nov 2024 07:52:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kirill Makurin <maiddaisuki <at> outlook.com>
To: "bug-libtool <at> gnu.org" <bug-libtool <at> gnu.org>
Subject: libtool mishandles some compiler flags when used with MSVC tools
Date: Sat, 2 Nov 2024 07:17:12 +0000
[Message part 1 (text/plain, inline)]
Hello,

I have encountered a few bugs with libtool when it is used with MSVC tools.

I have written a simple dummy project which should demonstrate the bugs. I uploaded the archive to Google Drive: https://drive.google.com/drive/folders/1DPJTid8PG6JjR7MHKKoz_i2QQTRGh8EO

The `configure`, `Makefile.in` etc. were generated from Msys2 environment with Autoconf 2.72, Automake 1.17 and libtool 2.5.3.

When built with MSVC tools, it will 1) produce a warning from the compiler (cl.exe) about unrecognized option and 2) fail with error from the linker (link.exe) about missing input file.

I also attached two files containing output from make for comparison. One when used with MSVC tools and another when used with GNU tools.

The encountered bugs are as follows:

1. When libtool is used with MSVC tools, libtool's link step mishandles compiler flags like`-Wl` and `-Xlinker`. For example, `-Wl,-def:FILENAME` becomes plain `-def:FILENAME` when libtool invokes the compiler*. (as seen in make-msvc.txt)

2. When producing a DLL, libtool passes `-Fe FILENAME` directly to the compiler*. The space between `-Fe` and `FILENAME` prevents cl.exe (and clang-cl.exe) from treating FILENAME as an output file, but rather as an input file.

* the compiler in question is `path/to/compile cl.exe` which should handle the usual `-o FILENAME` and flags like `-Wl` correctly with cl.exe

The second bug does not appear when libtool creates executables. It also seems to appear only in recent versions of libtool, since it does not appear in existing projects which used older versions of libtool. In older versions, libtool passes `-o FILENAME` which is handled by `compile` wrapper.

- Kirill Makurin
[Message part 2 (text/html, inline)]
[make-gnu.txt (text/plain, attachment)]
[make-msvc.txt (text/plain, attachment)]

Information forwarded to bug-libtool <at> gnu.org:
bug#74175; Package libtool. (Wed, 13 Nov 2024 20:01:01 GMT) Full text and rfc822 format available.

Message #8 received at 74175 <at> debbugs.gnu.org (full text, mbox):

From: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>
To: Kirill Makurin <maiddaisuki <at> outlook.com>, 74175 <at> debbugs.gnu.org
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with
 MSVC tools
Date: Wed, 13 Nov 2024 21:59:16 +0200
[Message part 1 (text/plain, inline)]
Hi Kirill,

On 02/11/2024 09:17, Kirill Makurin wrote:
> Hello,
> 
> I have encountered a few bugs with libtool when it is used with MSVC tools.
> 
> I have written a simple dummy project which should demonstrate the bugs. 
> I uploaded the archive to Google Drive: https://drive.google.com/drive/ 
> folders/1DPJTid8PG6JjR7MHKKoz_i2QQTRGh8EO <https://drive.google.com/ 
> drive/folders/1DPJTid8PG6JjR7MHKKoz_i2QQTRGh8EO>

Thank you for your bug report and supplying an example project! The
testsuite for libtool on MSVC is still not in a good state, but I will
start working on debugging those issues.

> The `configure`, `Makefile.in` etc. were generated from Msys2 
> environment with Autoconf 2.72, Automake 1.17 and libtool 2.5.3.
> 
> When built with MSVC tools, it will 1) produce a warning from the 
> compiler (cl.exe) about unrecognized option and 2) fail with error from 
> the linker (link.exe) about missing input file.
> 
> I also attached two files containing output from make for comparison. 
> One when used with MSVC tools and another when used with GNU tools.
> 
> The encountered bugs are as follows:
> 
> 1. When libtool is used with MSVC tools, libtool's link step mishandles 
> compiler flags like`-Wl` and `-Xlinker`. For example, `-Wl,- 
> def:FILENAME` becomes plain `-def:FILENAME` when libtool invokes the 
> compiler*. (as seen in make-msvc.txt)
> 
> 2. When producing a DLL, libtool passes `-Fe FILENAME` directly to the 
> compiler*. The space between `-Fe` and `FILENAME` prevents cl.exe (and 
> clang-cl.exe) from treating FILENAME as an output file, but rather as an 
> input file.

The second bug has been fixed in the development branch [1], and it
should be available in the next stable release of libtool. I am not sure
how to fix the first bug yet, but I have some guesses for why it is not
working.

> * the compiler in question is `path/to/compile cl.exe` which should 
> handle the usual `-o FILENAME` and flags like `-Wl` correctly with cl.exe
> 
> The second bug does not appear when libtool creates executables. It also 
> seems to appear only in recent versions of libtool, since it does not 
> appear in existing projects which used older versions of libtool. In 
> older versions, libtool passes `-o FILENAME` which is handled by 
> `compile` wrapper.

[1] 
https://git.savannah.gnu.org/cgit/libtool.git/commit/?h=development&id=09e89cc28da81d7e1bae189207eb4426636ccad6

-- 
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354

[OpenPGP_0x6570EA01146F7354.asc (application/pgp-keys, attachment)]
[OpenPGP_signature.asc (application/pgp-signature, attachment)]

Reply sent to Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>:
You have taken responsibility. (Thu, 29 May 2025 17:26:03 GMT) Full text and rfc822 format available.

Notification sent to Kirill Makurin <maiddaisuki <at> outlook.com>:
bug acknowledged by developer. (Thu, 29 May 2025 17:26:03 GMT) Full text and rfc822 format available.

Message #13 received at 74175-done <at> debbugs.gnu.org (full text, mbox):

From: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>
To: 74175-done <at> debbugs.gnu.org
Cc: Kirill Makurin <maiddaisuki <at> outlook.com>
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with
 MSVC tools
Date: Thu, 29 May 2025 20:24:56 +0300
[Message part 1 (text/plain, inline)]
On 13/11/2024 21:59, Ileana Dumitrescu wrote:
> Hi Kirill,
> 
> On 02/11/2024 09:17, Kirill Makurin wrote:
>> The encountered bugs are as follows:
>>
>> 1. When libtool is used with MSVC tools, libtool's link step 
>> mishandles compiler flags like`-Wl` and `-Xlinker`. For example, `- 
>> Wl,- def:FILENAME` becomes plain `-def:FILENAME` when libtool invokes 
>> the compiler*. (as seen in make-msvc.txt)

This part of the bug report has a patch applied [1] in the development
branch now, which should migrate to master after some more time. MSVC
building and testing has greatly improved, so I will hopefully get
another stable release with these fixes out in a couple months.

[1]https://cgit.git.savannah.gnu.org/cgit/libtool.git/commit/?h=development&id=4ded381a6f09cb761a05403450b5e34fec945f5a

-- 
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354

[OpenPGP_0x6570EA01146F7354.asc (application/pgp-keys, attachment)]
[OpenPGP_signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-libtool <at> gnu.org:
bug#74175; Package libtool. (Thu, 05 Jun 2025 09:59:02 GMT) Full text and rfc822 format available.

Message #16 received at 74175 <at> debbugs.gnu.org (full text, mbox):

From: Kirill Makurin <maiddaisuki <at> outlook.com>
To: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>, "74175 <at> debbugs.gnu.org"
 <74175 <at> debbugs.gnu.org>
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with
 MSVC tools
Date: Thu, 5 Jun 2025 09:58:23 +0000
[Message part 1 (text/plain, inline)]
Hi Ileana,

The fix seems incomplete.

See attached file for `libtool --mode=link` invocation with clang-cl. You may notice that the flag passed with -Wl is passed twice: once on its own (just like it was with cl.exe with the bug) and once properly with -Wl.

Do you think checking compiler's name is a good idea? AFAIK, all three of cl.exe, clang-cl.exe and icl.exe (MSVC-like compilers handled by Automake's `compile` wrapper) define _MSC_VER macro. If libtool does check, it should be at least consistent with `compile` wrapper.

Maybe libtool could check during configuration whether compiler defines this macro to decide how to pass linker flags? Since `compile` wrapper should usually be involved, we need to just pass -Wl flags and friends as is, `compile` takes care of them.

There is one problematic case though. If we would use clang.exe installed with Visual Studio, this will not work. It defines _MSC_VER, but it usus gcc-like command line options.

- Kirill Makurin


________________________________
From: Ileana Dumitrescu
Sent: Friday, May 30, 2025 2:24 AM
To: 74175-done <at> debbugs.gnu.org
Cc: Kirill Makurin
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with MSVC tools

On 13/11/2024 21:59, Ileana Dumitrescu wrote:
> Hi Kirill,
>
> On 02/11/2024 09:17, Kirill Makurin wrote:
>> The encountered bugs are as follows:
>>
>> 1. When libtool is used with MSVC tools, libtool's link step
>> mishandles compiler flags like`-Wl` and `-Xlinker`. For example, `-
>> Wl,- def:FILENAME` becomes plain `-def:FILENAME` when libtool invokes
>> the compiler*. (as seen in make-msvc.txt)

This part of the bug report has a patch applied [1] in the development
branch now, which should migrate to master after some more time. MSVC
building and testing has greatly improved, so I will hopefully get
another stable release with these fixes out in a couple months.

[1]https://cgit.git.savannah.gnu.org/cgit/libtool.git/commit/?h=development&id=4ded381a6f09cb761a05403450b5e34fec945f5a

--
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354

[Message part 2 (text/html, inline)]
[cmd.txt (text/plain, attachment)]

Information forwarded to bug-libtool <at> gnu.org:
bug#74175; Package libtool. (Thu, 05 Jun 2025 10:10:03 GMT) Full text and rfc822 format available.

Message #19 received at 74175 <at> debbugs.gnu.org (full text, mbox):

From: Kirill Makurin <maiddaisuki <at> outlook.com>
To: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>, "74175 <at> debbugs.gnu.org"
 <74175 <at> debbugs.gnu.org>
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with
 MSVC tools
Date: Thu, 5 Jun 2025 10:09:11 +0000
[Message part 1 (text/plain, inline)]
I am actually wrong. If we would pass -Wl and friends as is to clang.exe it would handle them correctly by itself.

Note: clang.exe installed with Visual Studio uses link.exe, just like cl.exe would.

What do you think about checking whether compiler defines _MSC_VER macro?

- Kirill Makurin
________________________________
From: bug-libtool-bounces+maiddaisuki=outlook.com <at> gnu.org <bug-libtool-bounces+maiddaisuki=outlook.com <at> gnu.org> on behalf of Kirill Makurin <maiddaisuki <at> outlook.com>
Sent: Thursday, June 5, 2025 6:58 PM
To: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>; 74175 <at> debbugs.gnu.org <74175 <at> debbugs.gnu.org>
Subject: bug#74175: libtool mishandles some compiler flags when used with MSVC tools

Hi Ileana,

The fix seems incomplete.

See attached file for `libtool --mode=link` invocation with clang-cl. You may notice that the flag passed with -Wl is passed twice: once on its own (just like it was with cl.exe with the bug) and once properly with -Wl.

Do you think checking compiler's name is a good idea? AFAIK, all three of cl.exe, clang-cl.exe and icl.exe (MSVC-like compilers handled by Automake's `compile` wrapper) define _MSC_VER macro. If libtool does check, it should be at least consistent with `compile` wrapper.

Maybe libtool could check during configuration whether compiler defines this macro to decide how to pass linker flags? Since `compile` wrapper should usually be involved, we need to just pass -Wl flags and friends as is, `compile` takes care of them.

There is one problematic case though. If we would use clang.exe installed with Visual Studio, this will not work. It defines _MSC_VER, but it usus gcc-like command line options.

- Kirill Makurin


________________________________
From: Ileana Dumitrescu
Sent: Friday, May 30, 2025 2:24 AM
To: 74175-done <at> debbugs.gnu.org
Cc: Kirill Makurin
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with MSVC tools

On 13/11/2024 21:59, Ileana Dumitrescu wrote:
> Hi Kirill,
>
> On 02/11/2024 09:17, Kirill Makurin wrote:
>> The encountered bugs are as follows:
>>
>> 1. When libtool is used with MSVC tools, libtool's link step
>> mishandles compiler flags like`-Wl` and `-Xlinker`. For example, `-
>> Wl,- def:FILENAME` becomes plain `-def:FILENAME` when libtool invokes
>> the compiler*. (as seen in make-msvc.txt)

This part of the bug report has a patch applied [1] in the development
branch now, which should migrate to master after some more time. MSVC
building and testing has greatly improved, so I will hopefully get
another stable release with these fixes out in a couple months.

[1]https://cgit.git.savannah.gnu.org/cgit/libtool.git/commit/?h=development&id=4ded381a6f09cb761a05403450b5e34fec945f5a

--
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354

[Message part 2 (text/html, inline)]

Information forwarded to bug-libtool <at> gnu.org:
bug#74175; Package libtool. (Thu, 05 Jun 2025 16:14:07 GMT) Full text and rfc822 format available.

Message #22 received at 74175 <at> debbugs.gnu.org (full text, mbox):

From: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>
To: "74175 <at> debbugs.gnu.org" <74175 <at> debbugs.gnu.org>
Cc: Kirill Makurin <maiddaisuki <at> outlook.com>
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with
 MSVC tools
Date: Thu, 5 Jun 2025 19:13:10 +0300
[Message part 1 (text/plain, inline)]
On 05/06/2025 13:09, Kirill Makurin wrote:
> I am actually wrong. If we would pass -Wl and friends as is to clang.exe 
> it would handle them correctly by itself.
> 
> Note: clang.exe installed with Visual Studio uses link.exe, just like 
> cl.exe would.

Thank you for the updates. Is this an issue specifically with clang-cl?
I believe the issue is fixed with cl/cl.exe in development.

> What do you think about checking whether compiler defines _MSC_VER macro?

I do not have a strong opinion on this, so it could be added. Could you
submit a patch for review?

> - Kirill Makurin
> ------------------------------------------------------------------------
> *From:* bug-libtool-bounces+maiddaisuki=outlook.com <at> gnu.org <bug- 
> libtool-bounces+maiddaisuki=outlook.com <at> gnu.org> on behalf of Kirill 
> Makurin <maiddaisuki <at> outlook.com>
> *Sent:* Thursday, June 5, 2025 6:58 PM
> *To:* Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>; 
> 74175 <at> debbugs.gnu.org <74175 <at> debbugs.gnu.org>
> *Subject:* bug#74175: libtool mishandles some compiler flags when used 
> with MSVC tools
> Hi Ileana,
> 
> The fix seems incomplete.
> 
> See attached file for `libtool --mode=link` invocation with clang-cl. 
> You may notice that the flag passed with -Wl is passed twice: once on 
> its own (just like it was with cl.exe with the bug) and once properly 
> with -Wl.
> 
> Do you think checking compiler's name is a good idea? AFAIK, all three 
> of cl.exe, clang-cl.exe and icl.exe (MSVC-like compilers handled by 
> Automake's `compile` wrapper) define _MSC_VER macro. If libtool does 
> check, it should be at least consistent with `compile` wrapper.

There are checks for compilers in libtool, like "cl* | icl*)" for
cc_basename when on a windows-like system. If libtool's configuration
when using clang-cl.exe is incorrect, these could be updated to avoid
clang-cl.exe or a new check could be added for the needed configuration.

> Maybe libtool could check during configuration whether compiler defines 
> this macro to decide how to pass linker flags? Since `compile` wrapper 
> should usually be involved, we need to just pass -Wl flags and friends 
> as is, `compile` takes care of them.
> 
> There is one problematic case though. If we would use clang.exe 
> installed with Visual Studio, this will not work. It defines _MSC_VER, 
> but it usus gcc-like command line options.

-- 
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354

[OpenPGP_0x6570EA01146F7354.asc (application/pgp-keys, attachment)]
[OpenPGP_signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-libtool <at> gnu.org:
bug#74175; Package libtool. (Thu, 05 Jun 2025 16:27:05 GMT) Full text and rfc822 format available.

Message #25 received at 74175 <at> debbugs.gnu.org (full text, mbox):

From: Kirill Makurin <maiddaisuki <at> outlook.com>
To: Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>, "74175 <at> debbugs.gnu.org"
 <74175 <at> debbugs.gnu.org>
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with
 MSVC tools
Date: Thu, 5 Jun 2025 16:26:23 +0000
[Message part 1 (text/plain, inline)]
Yes, this issue appears only with clang-cl.exe. The issue has been fixed for cl.exe.

I do not have icl.exe to test it, unfortunately.

- Kirill Makurin


________________________________
From: Ileana Dumitrescu
Sent: Friday, June 6, 2025 1:13 AM
To: 74175 <at> debbugs.gnu.org
Cc: Kirill Makurin
Subject: Re: bug#74175: libtool mishandles some compiler flags when used with MSVC tools

On 05/06/2025 13:09, Kirill Makurin wrote:
> I am actually wrong. If we would pass -Wl and friends as is to clang.exe
> it would handle them correctly by itself.
>
> Note: clang.exe installed with Visual Studio uses link.exe, just like
> cl.exe would.

Thank you for the updates. Is this an issue specifically with clang-cl?
I believe the issue is fixed with cl/cl.exe in development.

> What do you think about checking whether compiler defines _MSC_VER macro?

I do not have a strong opinion on this, so it could be added. Could you
submit a patch for review?

> - Kirill Makurin
> ------------------------------------------------------------------------
> *From:* bug-libtool-bounces+maiddaisuki=outlook.com <at> gnu.org <bug-
> libtool-bounces+maiddaisuki=outlook.com <at> gnu.org> on behalf of Kirill
> Makurin <maiddaisuki <at> outlook.com>
> *Sent:* Thursday, June 5, 2025 6:58 PM
> *To:* Ileana Dumitrescu <ileanadumitrescu95 <at> gmail.com>;
> 74175 <at> debbugs.gnu.org <74175 <at> debbugs.gnu.org>
> *Subject:* bug#74175: libtool mishandles some compiler flags when used
> with MSVC tools
> Hi Ileana,
>
> The fix seems incomplete.
>
> See attached file for `libtool --mode=link` invocation with clang-cl.
> You may notice that the flag passed with -Wl is passed twice: once on
> its own (just like it was with cl.exe with the bug) and once properly
> with -Wl.
>
> Do you think checking compiler's name is a good idea? AFAIK, all three
> of cl.exe, clang-cl.exe and icl.exe (MSVC-like compilers handled by
> Automake's `compile` wrapper) define _MSC_VER macro. If libtool does
> check, it should be at least consistent with `compile` wrapper.

There are checks for compilers in libtool, like "cl* | icl*)" for
cc_basename when on a windows-like system. If libtool's configuration
when using clang-cl.exe is incorrect, these could be updated to avoid
clang-cl.exe or a new check could be added for the needed configuration.

> Maybe libtool could check during configuration whether compiler defines
> this macro to decide how to pass linker flags? Since `compile` wrapper
> should usually be involved, we need to just pass -Wl flags and friends
> as is, `compile` takes care of them.
>
> There is one problematic case though. If we would use clang.exe
> installed with Visual Studio, this will not work. It defines _MSC_VER,
> but it usus gcc-like command line options.

--
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354

[Message part 2 (text/html, inline)]

This bug report was last modified 17 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.