bug#74175: libtool mishandles some compiler flags when used with MSVC tools

Kirill Makurin <[email protected]> Thu, 5 Jun 2025 10:09:11 +0000
Newsgroups gmane.comp.gnu.libtool.bugs
Message-ID <DM4PR84MB1373F0A8F68FE2D73643FA47B16FA@DM4PR84MB1373.NAMPRD84.PROD.OUTLOOK.COM>
--_000_DM4PR84MB1373F0A8F68FE2D73643FA47B16FADM4PR84MB1373NAMP_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

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.ex=
e would.

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

- Kirill Makurin
________________________________
From: [email protected] <bug-libtool-bo=
[email protected]> on behalf of Kirill Makurin <maidd=
[email protected]>
Sent: Thursday, June 5, 2025 6:58 PM
To: Ileana Dumitrescu <[email protected]>; [email protected]=
 <[email protected]>
Subject: bug#74175: libtool mishandles some compiler flags when used with M=
SVC tools

Hi Ileana,

The fix seems incomplete.

See attached file for `libtool --mode=3Dlink` 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 c=
l.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 thi=
s 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, `com=
pile` takes care of them.

There is one problematic case though. If we would use clang.exe installed w=
ith 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: [email protected]
Cc: Kirill Makurin
Subject: Re: bug#74175: libtool mishandles some compiler flags when used wi=
th 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=3Ddevelopme=
nt&id=3D4ded381a6f09cb761a05403450b5e34fec945f5a

--
Ileana Dumitrescu

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


--_000_DM4PR84MB1373F0A8F68FE2D73643FA47B16FADM4PR84MB1373NAMP_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
I am actually wrong. If we would pass -Wl and friends as is to clang.exe it=
 would handle them correctly by itself.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
Note: clang.exe installed with Visual Studio uses link.exe, just like cl.ex=
e would.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
What do you think about checking whether compiler defines _MSC_VER macro?</=
div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
- Kirill Makurin&nbsp;</div>
<div id=3D"appendonsend"></div>
<hr style=3D"display:inline-block;width:98%" tabindex=3D"-1">
<div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st=
yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> bug-libtool-bounces+m=
[email protected] &lt;bug-libtool-bounces+maiddaisuki=3Doutl=
[email protected]&gt; on behalf of Kirill Makurin &lt;[email protected]=
&gt;<br>
<b>Sent:</b> Thursday, June 5, 2025 6:58 PM<br>
<b>To:</b> Ileana Dumitrescu &lt;[email protected]&gt;; 74175@de=
bbugs.gnu.org &lt;[email protected]&gt;<br>
<b>Subject:</b> bug#74175: libtool mishandles some compiler flags when used=
 with MSVC tools</font>
<div>&nbsp;</div>
</div>
<style type=3D"text/css" style=3D"display:none">
<!--
p
	{margin-top:0;
	margin-bottom:0}
-->
</style>
<div dir=3D"ltr">
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
Hi Ileana,</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
<br>
</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
The fix seems incomplete.</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
<br>
</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
See attached file for `libtool --mode=3Dlink` 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.</di=
v>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
<br>
</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
Do you think checking compiler's name is a good idea? AFAIK, all three of c=
l.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.</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
<br>
</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
Maybe libtool could check&nbsp;during configuration&nbsp;whether compiler d=
efines this macro to decide how to pass linker flags? Since `compile` wrapp=
er should usually be involved, we need to just pass -Wl flags and friends a=
s is, `compile` takes care of them.</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
<br>
</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
There is one problematic case though. If we would use clang.exe installed w=
ith Visual Studio, this will not work. It defines _MSC_VER, but it usus gcc=
-like command line options.</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
<br>
</div>
<div class=3D"x_elementToProof" style=3D"font-family:Aptos,Aptos_EmbeddedFo=
nt,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:=
rgb(0,0,0)">
- Kirill Makurin</div>
<div id=3D"x_appendonsend"></div>
<div><br>
</div>
<div style=3D"font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12p=
t; color:rgb(0,0,0)">
<br>
</div>
<hr style=3D"display:inline-block; width:98%">
<div class=3D"x_elementToProof" style=3D"font-family:Calibri,Arial,Helvetic=
a,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<b>From:</b>&nbsp;Ileana Dumitrescu<br>
<b>Sent:</b>&nbsp;Friday, May 30, 2025 2:24 AM<br>
<b>To:</b>&nbsp;[email protected]<br>
<b>Cc:</b>&nbsp;Kirill Makurin<br>
<b>Subject:</b>&nbsp;Re: bug#74175: libtool mishandles some compiler flags =
when used with MSVC tools
</div>
<div style=3D"font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12p=
t; color:rgb(0,0,0)">
<br>
</div>
<div class=3D"x_elementToProof" style=3D"font-size:11pt">On 13/11/2024 21:5=
9, Ileana Dumitrescu wrote:<br>
&gt; Hi Kirill,<br>
&gt;<br>
&gt; On 02/11/2024 09:17, Kirill Makurin wrote:<br>
&gt;&gt; The encountered bugs are as follows:<br>
&gt;&gt;<br>
&gt;&gt; 1. When libtool is used with MSVC tools, libtool's link step<br>
&gt;&gt; mishandles compiler flags like`-Wl` and `-Xlinker`. For example, `=
-<br>
&gt;&gt; Wl,- def:FILENAME` becomes plain `-def:FILENAME` when libtool invo=
kes<br>
&gt;&gt; the compiler*. (as seen in make-msvc.txt)<br>
<br>
This part of the bug report has a patch applied [1] in the development<br>
branch now, which should migrate to master after some more time. MSVC<br>
building and testing has greatly improved, so I will hopefully get<br>
another stable release with these fixes out in a couple months.<br>
<br>
[1]https://cgit.git.savannah.gnu.org/cgit/libtool.git/commit/?h=3Ddevelopme=
nt&amp;id=3D4ded381a6f09cb761a05403450b5e34fec945f5a<br>
<br>
--<br>
Ileana Dumitrescu<br>
<br>
GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354<br>
<br>
</div>
</div>
</body>
</html>

--_000_DM4PR84MB1373F0A8F68FE2D73643FA47B16FADM4PR84MB1373NAMP_--