[m-rev.] diff: fix problem with `--output-link-library-flags'

Julien Fischer jfischer at opturion.com
Mon Sep 23 17:39:39 AEST 2013


Branches: 13.05, master

-----------------------

Fix a problem with `--output-link-library-flags'.

When printing the list of link library flags, the Mercury compiler would
attempt to perform any shell escapes required by the current shell**.  This was
causing trouble if one of the libraries involved was libstdc++ and the output
of `--output-link-library-flags' was used in a shell script, for example:

    LIB_LD_FLAGS=`$MMC --library stdc++ --output-library-flags`

This results in LIB_LD_FLAGS containing:

     "-lstdc++" -lmer_std -lmer_rt -lgc  -lm

And Doing something like this,

     $CXX -o foo $OBJS $LIB_LD_FLAGS

would then result in a error, as "-lstdc++" would be treated by the C++
compiler as an argument not an option.  This particular use case is fairly
common when using Mercury stand-alone interfaces.

The solution implemented by this change is to output the link library options
as-is when the compiler is invoked with `--output-link-library-flags' (i.e.  do
not attempt to do any shell escapes).  If, for some reason, the library names
do require shell escapes then doing so is the user's problem.
(There's not much the compiler can do anywayw, since it doesn't know how the
user is going to use the output generated by `--output-library-link-flags'.)

** there's a deeper issue here that the compiler's notion of the
"current shell" is not very good in some spots -- I'm thinking specifically of
the the function quote_arg/1 in compiler/options.m.  Ideally, that function
should use the current setting of `--host-env-type' and not try to guess based
on whether dir.use_windows_paths/0 succeeds or not, however that's a problem
for a separate change.

compiler/compile_target_code.m;
 	Do not attempt to insert shell escapes into the link library options
 	when invoked with --output-library-link-flags.

 	Print a newline after the output from --output-library-link-flags.

Julien.

diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index ba8902f..3390575 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -3617,8 +3617,7 @@ output_library_link_flags(Globals, Stream, !IO) :-
      get_link_libraries(Globals, MaybeLinkLibraries, !IO),
      (
          MaybeLinkLibraries = yes(LinkLibrariesList),
-        join_quoted_string_list(LinkLibrariesList, "", "", " ",
-            LinkLibraries)
+        join_string_list(LinkLibrariesList, "", "", " ", LinkLibraries)
      ;
          MaybeLinkLibraries = no,
          LinkLibraries = ""
@@ -3632,7 +3631,8 @@ output_library_link_flags(Globals, Stream, !IO) :-
          LinkLibraries, " ",
          MercuryStdLibs, " ",
          SystemLibs], LinkFlags),
-    io.write_string(Stream, LinkFlags, !IO).
+    io.write_string(Stream, LinkFlags, !IO),
+    io.nl(Stream, !IO).

  %-----------------------------------------------------------------------------%





More information about the reviews mailing list