[m-rev.] diff: Fix error creating temporary archive with --restricted-command-line.

Peter Wang novalazy at gmail.com
Fri Oct 7 15:28:47 AEDT 2016


With `--restricted-command-line' we generate a temporary archive file
name with `io.make_temp_file' then run `ar' to create the archive.
`ar' sees that the archive file already exists (it is empty), tries to
detect its format, and fails.  The solution is to delete the temporary
file before calling `ar'.  Fixes Mantis bug #424.

compiler/compile_target_code.m:
    As above.

    Add "mtmp" prefix to the temporary archive file name.
---
 compiler/compile_target_code.m | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 41eecfe..8c56108 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -1992,13 +1992,16 @@ link_exe_or_shared_lib(Globals, ErrorStream, LinkTargetType, ModuleName,
             RestrictedCommandLine = yes,
             globals.lookup_string_option(Globals, library_extension, LibExt),
             io.get_temp_directory(TempDir, !IO),
-            io.make_temp_file(TempDir, "", LibExt, TmpArchiveResult, !IO),
+            io.make_temp_file(TempDir, "mtmp", LibExt, TmpArchiveResult, !IO),
             (
                 TmpArchiveResult = ok(TmpArchive),
                 % Only include actual object files in the temporary archive,
                 % not other files such as other archives.
                 filter_object_files(Globals, ObjectsList,
                     ProperObjectFiles, NonObjectFiles),
+                % Delete the currently empty output file first, otherwise ar
+                % will fail to recognise its file format.
+                remove_file(TmpArchive, _, !IO),
                 create_archive(Globals, ErrorStream, TmpArchive, yes,
                     ProperObjectFiles, ArchiveSucceeded, !IO),
                 MaybeDeleteTmpArchive = yes(TmpArchive),
-- 
2.9.0



More information about the reviews mailing list