Guest User

Untitled

a guest
Feb 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.93 KB | None | 0 0
  1. diff --git a/Changes b/Changes
  2. index d952260..3def852 100644
  3. --- a/Changes
  4. +++ b/Changes
  5. @@ -127,6 +127,9 @@ Compilers:
  6. incrementally (Jacques Garrigue)
  7. - PR#6642: replace $CAMLORIGIN in -ccopt with the path to cma or cmxa
  8. (Peter Zotov, Gabriel Scherer, review by Damien Doligez)
  9. +- PR#6797: accept ocaml{c,opt} -output-complete-obj
  10. + and link in the runtime and autolink libraries
  11. + (Peter Zotov)
  12.  
  13. Toplevel and debugger:
  14. - PR#5958: generalized polymorphic #install_printer
  15. diff --git a/asmcomp/asmlink.ml b/asmcomp/asmlink.ml
  16. index 79f657e..5c4349b 100644
  17. --- a/asmcomp/asmlink.ml
  18. +++ b/asmcomp/asmlink.ml
  19. @@ -277,12 +277,13 @@ let link_shared ppf objfiles output_name =
  20. let call_linker file_list startup_file output_name =
  21. let main_dll = !Clflags.output_c_object
  22. && Filename.check_suffix output_name Config.ext_dll
  23. + and main_obj_runtime = !Clflags.output_complete_object
  24. in
  25. let files = startup_file :: (List.rev file_list) in
  26. let files, c_lib =
  27. - if (not !Clflags.output_c_object) || main_dll then
  28. + if (not !Clflags.output_c_object) || main_dll || main_obj_runtime then
  29. files @ (List.rev !Clflags.ccobjs) @ runtime_lib (),
  30. - (if !Clflags.nopervasives then "" else Config.native_c_libraries)
  31. + (if !Clflags.nopervasives || main_obj_runtime then "" else Config.native_c_libraries)
  32. else
  33. files, ""
  34. in
  35. diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml
  36. index c4c35bf..006c0a6 100644
  37. --- a/bytecomp/bytelink.ml
  38. +++ b/bytecomp/bytelink.ml
  39. @@ -574,7 +574,11 @@ let link ppf objfiles output_name =
  40. end else begin
  41. let basename = Filename.chop_extension output_name in
  42. let c_file = basename ^ ".c"
  43. - and obj_file = basename ^ Config.ext_obj in
  44. + and obj_file =
  45. + if !Clflags.output_complete_object
  46. + then Filename.temp_file "camlobj" Config.ext_obj
  47. + else basename ^ Config.ext_obj
  48. + in
  49. if Sys.file_exists c_file then raise(Error(File_exists c_file));
  50. let temps = ref [] in
  51. try
  52. @@ -583,13 +587,19 @@ let link ppf objfiles output_name =
  53. temps := c_file :: !temps;
  54. if Ccomp.compile_file ~output_name:(Some obj_file) c_file <> 0 then
  55. raise(Error Custom_runtime);
  56. - if not (Filename.check_suffix output_name Config.ext_obj) then begin
  57. + if not (Filename.check_suffix output_name Config.ext_obj) ||
  58. + !Clflags.output_complete_object then begin
  59. temps := obj_file :: !temps;
  60. + let mode, c_libs =
  61. + if Filename.check_suffix output_name Config.ext_obj
  62. + then Ccomp.Partial, ""
  63. + else Ccomp.MainDll, Config.bytecomp_c_libraries
  64. + in
  65. if not (
  66. let runtime_lib = "-lcamlrun" ^ !Clflags.runtime_variant in
  67. - Ccomp.call_linker Ccomp.MainDll output_name
  68. + Ccomp.call_linker mode output_name
  69. ([obj_file] @ List.rev !Clflags.ccobjs @ [runtime_lib])
  70. - Config.bytecomp_c_libraries
  71. + c_libs
  72. ) then raise (Error Custom_runtime);
  73. end
  74. end;
  75. diff --git a/driver/main.ml b/driver/main.ml
  76. index f8358a0..a390c7c 100644
  77. --- a/driver/main.ml
  78. +++ b/driver/main.ml
  79. @@ -106,6 +106,8 @@ module Options = Main_args.Make_bytecomp_options (struct
  80. let _o s = output_name := Some s
  81. let _open s = open_modules := s :: !open_modules
  82. let _output_obj () = output_c_object := true; custom_runtime := true
  83. + let _output_complete_obj () =
  84. + output_c_object := true; output_complete_object := true; custom_runtime := true
  85. let _pack = set make_package
  86. let _pp s = preprocessor := Some s
  87. let _ppx s = first_ppx := s :: !first_ppx
  88. diff --git a/driver/main_args.ml b/driver/main_args.ml
  89. index 7636abe..0f33e52 100644
  90. --- a/driver/main_args.ml
  91. +++ b/driver/main_args.ml
  92. @@ -214,7 +214,12 @@ let mk_open f =
  93. "-open", Arg.String f, "<module> Opens the module <module> before typing"
  94.  
  95. let mk_output_obj f =
  96. - "-output-obj", Arg.Unit f, " Output a C object file instead of an executable"
  97. + "-output-obj", Arg.Unit f, " Output an object file instead of an executable"
  98. +;;
  99. +
  100. +let mk_output_complete_obj f =
  101. + "-output-complete-obj", Arg.Unit f,
  102. + " Output an object file, including runtime, instead of an executable"
  103. ;;
  104.  
  105. let mk_p f =
  106. @@ -521,6 +526,7 @@ module type Compiler_options = sig
  107. val _noautolink : unit -> unit
  108. val _o : string -> unit
  109. val _output_obj : unit -> unit
  110. + val _output_complete_obj : unit -> unit
  111. val _pack : unit -> unit
  112. val _pp : string -> unit
  113. val _principal : unit -> unit
  114. @@ -668,6 +674,7 @@ struct
  115. mk_o F._o;
  116. mk_open F._open;
  117. mk_output_obj F._output_obj;
  118. + mk_output_complete_obj F._output_complete_obj;
  119. mk_pack_byt F._pack;
  120. mk_pp F._pp;
  121. mk_ppx F._ppx;
  122. @@ -783,6 +790,7 @@ struct
  123. mk_o F._o;
  124. mk_open F._open;
  125. mk_output_obj F._output_obj;
  126. + mk_output_complete_obj F._output_complete_obj;
  127. mk_p F._p;
  128. mk_pack_opt F._pack;
  129. mk_pp F._pp;
  130. diff --git a/driver/main_args.mli b/driver/main_args.mli
  131. index 18ade80..021a952 100644
  132. --- a/driver/main_args.mli
  133. +++ b/driver/main_args.mli
  134. @@ -67,6 +67,7 @@ module type Compiler_options = sig
  135. val _noautolink : unit -> unit
  136. val _o : string -> unit
  137. val _output_obj : unit -> unit
  138. + val _output_complete_obj : unit -> unit
  139. val _pack : unit -> unit
  140. val _pp : string -> unit
  141. val _principal : unit -> unit
  142. diff --git a/driver/optmain.ml b/driver/optmain.ml
  143. index 947d430..0e2eb3c 100644
  144. --- a/driver/optmain.ml
  145. +++ b/driver/optmain.ml
  146. @@ -104,6 +104,8 @@ module Options = Main_args.Make_optcomp_options (struct
  147. let _o s = output_name := Some s
  148. let _open s = open_modules := s :: !open_modules
  149. let _output_obj = set output_c_object
  150. + let _output_complete_obj s =
  151. + set output_c_object s; set output_complete_object s
  152. let _p = set gprofile
  153. let _pack = set make_package
  154. let _pp s = preprocessor := Some s
  155. diff --git a/tools/ocamlcp.ml b/tools/ocamlcp.ml
  156. index 51559ae..b5a124f 100644
  157. --- a/tools/ocamlcp.ml
  158. +++ b/tools/ocamlcp.ml
  159. @@ -74,6 +74,7 @@ module Options = Main_args.Make_bytecomp_options (struct
  160. let _o s = option_with_arg "-o" s
  161. let _open s = option_with_arg "-open" s
  162. let _output_obj = option "-output-obj"
  163. + let _output_complete_obj = option "-output-complete-obj"
  164. let _pack = option "-pack"
  165. let _pp _s = incompatible "-pp"
  166. let _ppx _s = incompatible "-ppx"
  167. diff --git a/tools/ocamloptp.ml b/tools/ocamloptp.ml
  168. index 0b78884..a0d20ed 100644
  169. --- a/tools/ocamloptp.ml
  170. +++ b/tools/ocamloptp.ml
  171. @@ -75,6 +75,7 @@ module Options = Main_args.Make_optcomp_options (struct
  172. let _o s = option_with_arg "-o" s
  173. let _open s = option_with_arg "-open" s
  174. let _output_obj = option "-output-obj"
  175. + let _output_complete_obj = option "-output-complete-obj"
  176. let _p = option "-p"
  177. let _pack = option "-pack"
  178. let _pp _s = incompatible "-pp"
  179. diff --git a/utils/ccomp.ml b/utils/ccomp.ml
  180. index 4bea268..a897ddc 100644
  181. --- a/utils/ccomp.ml
  182. +++ b/utils/ccomp.ml
  183. @@ -101,14 +101,22 @@ type link_mode =
  184. | MainDll
  185. | Partial
  186.  
  187. +let remove_Wl cclibs =
  188. + cclibs |> List.map (fun cclib ->
  189. + (* -Wl,-foo,bar -> -foo bar *)
  190. + if String.length cclib >= 4 && "-Wl," = String.sub cclib 0 4 then
  191. + String.map (function ',' -> ' ' | c -> c)
  192. + (String.sub cclib 4 (String.length cclib - 4))
  193. + else cclib)
  194. +
  195. let call_linker mode output_name files extra =
  196. - let files = quote_files files in
  197. let cmd =
  198. if mode = Partial then
  199. - Printf.sprintf "%s%s %s %s"
  200. + Printf.sprintf "%s%s %s %s %s"
  201. Config.native_pack_linker
  202. (Filename.quote output_name)
  203. - files
  204. + (quote_prefixed "-L" !Config.load_path)
  205. + (quote_files (remove_Wl files))
  206. extra
  207. else
  208. Printf.sprintf "%s -o %s %s %s %s %s %s %s"
  209. @@ -124,7 +132,7 @@ let call_linker mode output_name files extra =
  210. "" (*(Clflags.std_include_flag "-I")*)
  211. (quote_prefixed "-L" !Config.load_path)
  212. (String.concat " " (List.rev !Clflags.all_ccopts))
  213. - files
  214. + (quote_files files)
  215. extra
  216. in
  217. command cmd = 0
  218. diff --git a/utils/clflags.ml b/utils/clflags.ml
  219. index c65790c..a7fc598 100644
  220. --- a/utils/clflags.ml
  221. +++ b/utils/clflags.ml
  222. @@ -28,6 +28,7 @@ and link_everything = ref false (* -linkall *)
  223. and custom_runtime = ref false (* -custom *)
  224. and bytecode_compatible_32 = ref false (* -compat-32 *)
  225. and output_c_object = ref false (* -output-obj *)
  226. +and output_complete_object = ref false (* -output-complete-obj *)
  227. and all_ccopts = ref ([] : string list) (* -ccopt *)
  228. and classic = ref false (* -nolabels *)
  229. and nopervasives = ref false (* -nopervasives *)
  230. diff --git a/utils/clflags.mli b/utils/clflags.mli
  231. index 59cbd3f..873e04f 100644
  232. --- a/utils/clflags.mli
  233. +++ b/utils/clflags.mli
  234. @@ -25,6 +25,7 @@ val link_everything : bool ref
  235. val custom_runtime : bool ref
  236. val bytecode_compatible_32 : bool ref
  237. val output_c_object : bool ref
  238. +val output_complete_object : bool ref
  239. val all_ccopts : string list ref
  240. val classic : bool ref
  241. val nopervasives : bool ref
Add Comment
Please, Sign In to add comment