From 4f968563b6ea7d09b09888658463eaf33a6a34bb Mon Sep 17 00:00:00 2001 From: Wojciech Meyer Date: Sep 01 2012 13:10:10 +0000 Subject: PR#5611: avoid clashes betwen .cmo files and output files during linking git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12901 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- diff --git a/Changes b/Changes index 54c9119..03c0f03 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,7 @@ Bug fixes: - PR#5327: (Windows) Unix.select blocks if same socket listed in first and third arguments - PR#5551: Avoid repeated lookups for missing cmi files +- PR#5611: avoid clashes betwen .cmo files and output files during linking - PR#5662: typo in md5.c - PR#5695: remove warnings on sparc code emitter - PR#5697: better location for warnings on statement expressions diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml index a80a076..1fea4a2 100644 --- a/bytecomp/bytelink.ml +++ b/bytecomp/bytelink.ml @@ -21,6 +21,7 @@ open Cmo_format type error = File_not_found of string | Not_an_object_file of string + | Wrong_object_name of string | Symbol_error of string * Symtable.error | Inconsistent_import of string * string * string | Custom_runtime @@ -272,6 +273,12 @@ let make_absolute file = (* Create a bytecode executable file *) let link_bytecode ppf tolink exec_name standalone = + (* Avoid the case where the specified exec output file is the same as + one of the objects to be linked *) + List.iter (function + | Link_object(file_name, _) when file_name = exec_name -> + raise (Error (Wrong_object_name exec_name)); + | _ -> ()) tolink; Misc.remove_file exec_name; (* avoid permission problems, cf PR#1911 *) let outchan = open_out_gen [Open_wronly; Open_trunc; Open_creat; Open_binary] @@ -581,6 +588,8 @@ let report_error ppf = function | Not_an_object_file name -> fprintf ppf "The file %a is not a bytecode object file" Location.print_filename name + | Wrong_object_name name -> + fprintf ppf "The output file %s has a wrong name. The extension implies object file when the link step was requested" name | Symbol_error(name, err) -> fprintf ppf "Error while linking %a:@ %a" Location.print_filename name Symtable.report_error err diff --git a/bytecomp/bytelink.mli b/bytecomp/bytelink.mli index 1366a16..837a533 100644 --- a/bytecomp/bytelink.mli +++ b/bytecomp/bytelink.mli @@ -23,6 +23,7 @@ val extract_crc_interfaces: unit -> (string * Digest.t) list type error = File_not_found of string | Not_an_object_file of string + | Wrong_object_name of string | Symbol_error of string * Symtable.error | Inconsistent_import of string * string * string | Custom_runtime