]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
libtool: Fix mishandling compiler flags with MSVC tools
authorIleana Dumitrescu <ileanadumitrescu95@gmail.com>
Tue, 7 Jan 2025 17:34:11 +0000 (19:34 +0200)
committerIleana Dumitrescu <ileanadumitrescu95@gmail.com>
Mon, 26 May 2025 14:18:40 +0000 (17:18 +0300)
With MSVC, linker flags were not properly being linked in during a
compile command. A check has been added to verify if there are linker
flags set and then use a different command when linking.

Fixes applied for bug#74175.

* build-aux/ltmain.in: Fix command parser for '-Wl' option for MSVC.
* m4/libtool.m4: Fix MSVC compile commands.
* tests/flags.at: Use '$GREP --' instead of '$FGREP' when comparing with
  stdout.

build-aux/ltmain.in
m4/libtool.m4
tests/flags.at

index 38b56a71118df65c7c6987e4de7513b8633adffb..d792be2baf04276f3d6b966a341e02cbfed7cd2b 100644 (file)
@@ -5155,8 +5155,13 @@ func_mode_link ()
          continue
          ;;
        xlinker)
-         func_append linker_flags " $qarg"
-         func_append compiler_flags " $wl$qarg"
+         func_append linker_flags "$qarg,"
+         # Args in the var 'compiler_flags' causes warnings in MSVC
+         func_cc_basename "$CC"
+         case $func_cc_basename_result in
+           cl|cl.exe) ;;
+           *) func_append compiler_flags " $wl$qarg" ;;
+         esac
          prev=
          func_append compile_command " $wl$qarg"
          func_append finalize_command " $wl$qarg"
@@ -5530,8 +5535,13 @@ func_mode_link ()
          IFS=$save_ifs
           func_quote_arg pretty "$flag"
          func_append arg " $wl$func_quote_arg_result"
-         func_append compiler_flags " $wl$func_quote_arg_result"
-         func_append linker_flags " $func_quote_arg_result"
+         # Args in the var 'compiler_flags' causes warnings in MSVC
+         func_cc_basename "$CC"
+         case $func_cc_basename_result in
+            cl|cl.exe) ;;
+            *) func_append compiler_flags " $wl$func_quote_arg_result" ;;
+         esac
+         func_append linker_flags "$func_quote_arg_result,"
        done
        IFS=$save_ifs
        func_stripname ' ' '' "$arg"
index 8e0a46bcb893c8f137fdf67bc8ae553b83a2bc07..c97fdd3bb0fc01aa48c86fea39ec04a669598650 100644 (file)
@@ -5776,6 +5776,8 @@ _LT_EOF
        # Tell ltmain to make .dll files, not .so files.
        shrext_cmds=.dll
        # FIXME: Setting linknames here is a bad hack.
+       # A check exists to verify if there are linker flags, which will use
+       # different commands when linking.
        _LT_TAGVAR(archive_cmds, $1)='$CC -Fe$output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames='
        _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then
             cp "$export_symbols" "$output_objdir/$soname.def";
@@ -5783,7 +5785,11 @@ _LT_EOF
           else
             $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp;
           fi~
-          $CC -Fe$tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+          if test -z "$linker_flags"; then
+             $CC -Fe$tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib";
+          else
+             $CC -Fe$tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,$linker_flags-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib";
+          fi~
           linknames='
        # The linker will not automatically build a static lib if we build a DLL.
        # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
@@ -5815,7 +5821,7 @@ _LT_EOF
        # Tell ltmain to make .dll files, not .so files.
        shrext_cmds=.dll
        # FIXME: Setting linknames here is a bad hack.
-       _LT_TAGVAR(archive_cmds, $1)='$CC -$lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames='
+       _LT_TAGVAR(archive_cmds, $1)='$CC -Fe$lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames='
        # The linker will automatically build a .lib file if we build a DLL.
        _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
        # FIXME: Should let the user specify the lib program.
@@ -6856,14 +6862,20 @@ if test yes != "$_lt_caught_CXX_error"; then
          # Tell ltmain to make .dll files, not .so files.
          shrext_cmds=.dll
          # FIXME: Setting linknames here is a bad hack.
-         _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames='
+         # A check exists to verify if there are linker flags, which will use
+         # different commands when linking.
+         _LT_TAGVAR(archive_cmds, $1)='$CC -Fe$output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames='
          _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then
               cp "$export_symbols" "$output_objdir/$soname.def";
               echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp";
             else
               $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp;
             fi~
-            $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+            if test -z "$linker_flags"; then
+               $CC -Fe$tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib";
+            else
+               $CC -Fe$tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,$linker_flags-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib";
+            fi~
             linknames='
          # The linker will not automatically build a static lib if we build a DLL.
          # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
index b13ed0bd92bf19bc945c33f746136ae72caff515..82cfd8a6a2b28205966719a4f35327703e0ebeee 100644 (file)
@@ -129,7 +129,7 @@ for flag in -Wc, -Wl, '-Xcompiler ' '-Xlinker '; do
   -Wc, | -Xcompiler\ )
     AT_CHECK([$LIBTOOL -n --tag=lt_tag --mode=compile $compile ]dnl
             [$flag-foo -c $source], [], [stdout], [ignore])
-    AT_CHECK([$FGREP " -foo" stdout], [], [ignore])
+    AT_CHECK([$GREP -- " -foo" stdout], [], [ignore])
     flag_prefix_prog=
     flag_prefix_lib=
     flags_in_liblink=$compiler_flags_in_liblink
@@ -143,7 +143,7 @@ for flag in -Wc, -Wl, '-Xcompiler ' '-Xlinker '; do
 
   AT_CHECK([$LIBTOOL -n --tag=lt_tag --mode=link $link ]dnl
           [-o program$EXEEXT a.lo $flag-foo], [], [stdout], [ignore])
-  AT_CHECK([$FGREP " $flag_prefix_prog-foo" stdout], [], [ignore])
+  AT_CHECK([$GREP -- "$flag_prefix_prog-foo" stdout], [], [ignore])
 
   eval set x "$library_and_module"
   for output
@@ -152,9 +152,9 @@ for flag in -Wc, -Wl, '-Xcompiler ' '-Xlinker '; do
     AT_CHECK([$LIBTOOL -n --tag=lt_tag --mode=link $link ]dnl
             [-o $output a.lo -rpath /nowhere $flag-foo], [], [stdout], [ignore])
     if $flags_in_liblink; then
-      AT_CHECK([$FGREP " $flag_prefix_lib-foo" stdout], [], [ignore])
+      AT_CHECK([$GREP -- "$flag_prefix_lib-foo" stdout], [], [ignore])
     else
-      AT_CHECK([$FGREP " $flag_prefix_lib-foo" stdout], [1])
+      AT_CHECK([$GREP -- " $flag_prefix_lib-foo" stdout], [1])
     fi
   done
 done