Commits

Anonymous committed 9684190

PR#5611: avoid clashes betwen .cmo files and output files during linking

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12901f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

  • Participants
  • Parent commits b68a229

Comments (0)

Files changed (3)

 - 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

bytecomp/bytelink.ml

 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
 (* 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]
   | 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

bytecomp/bytelink.mli

 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