OCamlPro / flambda-task-force

13 stars 1 forks source link

ocamlobjinfo #92

Closed mshinwell closed 8 years ago

mshinwell commented 8 years ago

We need to fix ocamlobjinfo so that it dumps the Flambda export information structure. This probably requires that executable to be linked against the middle_end/ and asmcomp/ directories.

objmagic commented 8 years ago

From this task description

in particular, the lists of object files making up Flambda should not be duplicated, but shared with the toplevel Makefile.shared

I am trying to import toplevel Makefile.shared's MIDDLE_END variable into tools/Makefile.shared. However, modifying Makefile seems not very easy. Here are some of my ideas:

  1. directly include toplevel Makefile.shared in tools/Makefile.shared, but it seems we may import lots of unnecessary things
  2. use grep to get variable MIDDLE_END in toplevel Makefile, but using grep is a very shaky approach
  3. cut toplevel Makefile.shared into smaller pieces

Neither of these approaches looks satisfying to me...

mshinwell commented 8 years ago

Is it possible to make ocamlobjinfo use the archive files in the compilerlibs/ directory to solve this problem? I think all the necessary objects should be inside there.

mshinwell commented 8 years ago

By the way, the correct functions to use for dumping the export information are at the bottom of asmcomp/export_info.mli.

objmagic commented 8 years ago

actually the Makefile for objinfo already used the archive file: https://github.com/chambart/ocaml-1/blob/flambda_trunk/tools/Makefile.shared#L268

However, it seems that archive doesn't have what we want in it, see:

https://github.com/chambart/ocaml-1/blob/flambda_trunk/Makefile.shared#L81

update: ocamloptcomp.cmxa has, but there is some dependency I need to fix...

objmagic commented 8 years ago

I fixed the Makefile and used Format.eprintf "%a" Export_info.print_all ui.ui_export_info; to print after your CR.

I then used new ocamlobjinfo on typing/path.cmx. I get the following error message:

marklrh@warroom $ ocamlobjinfo path.cmx
approxs Globals: Path! -> Path.camlPath; 
Symbols:
  Path.camlPath:
    (Path._50: [0:Path.camlPath__same_30_closure
      Path.camlPath__isfree_72_closure Path.camlPath__binding_time_95_closure
      (Path._51: -1) Path.camlPath__name_127_closure
      Path.camlPath__head_207_closure Path.camlPath__last_230_closure
      Path.camlPath__constructor_typath_closure_282_closure
      Path.camlPath__is_constructor_typath_closure_313_closure ]);
  >> Fatal error: Compilation_unit.get_current_exn
File path.cmx
Name: Path
CRC of implementation: 3295c32b667d0de7cddf687f97e9b50c
Globals defined:
    Path
Interfaces imported:
    e4d3a51f0fb367d668178a608dc498ba    String
    5518f8d5616bf93e60b1098e32cfa8eb    Set
    f759321612a0c04f13a30744b6ec7abd    Pervasives
    5328c74469b44288daa2a39c16c000ae    Path
    94fc3f39298ffcde04f9b1dd0d01e06f    Map
    613a6c9bb469cd1c004681880a317153    Ident
    8f7ce5e4005a7f94ac8c765fbd030218    Hashtbl
    50023237f7174d0d5dd487bc8bb41303    Format
    38a8d2f92493fe8b171f41b02ed31a1a    Ext_types
    5bdee229c05c91d1cd9ed3932dc82336    CamlinternalFormatBasics
    ccefe3162f1e7584179319533d42309b    Buffer
Implementations imported:
    d15b3cdb934b172a62372d3738800a36    Pervasives
    13d34bd82d39fe80f7f4cba5ad5b0656    Ident
Implementation exported:
Fatal error: exception Misc.Fatal_error

Seems that the error is raised from this place: https://github.com/chambart/ocaml-1/blob/flambda_trunk/middle_end/base_types/variable.ml#L44

mshinwell commented 8 years ago

Sorry, I've only just seen this comment. I think you probably need to set the current compilation unit using [Compilation_unit.set_current]. You'll need to create a [Compilation_unit.t] that corresponds to the unit being examined by ocamlobjinfo.

objmagic commented 8 years ago

Sorry, Mark, I have to admit I don't have the ability to fix this problem. Digging into middle_end and asmcomp helps, but I don't think I can fully understand what's going on. I tried the following solution and no error shows up at least, which I think is incorrect... If you would like to spare sometime to explain to me or take this issue over, I'll be very happy.

In variable.ml #L44, I did

  let print ppf t =
    begin match Compilation_unit.get_current () with
    | None -> Compilation_unit.set_current t.compilation_unit
    | _ -> ()
    end;
    if Compilation_unit.equal t.compilation_unit
        (Compilation_unit.get_current_exn ())

However, fixing Makefile is not as hard as we thought. Here is my attempt.

diff --git a/Makefile b/Makefile
index 5c8b661..8f5b931 100644
--- a/Makefile
+++ b/Makefile
@@ -623,7 +623,8 @@ clean::
 # Tools

 ocamltools: ocamlc ocamlyacc ocamllex asmcomp/cmx_format.cmi \
-            asmcomp/printclambda.cmo
+            asmcomp/printclambda.cmo \
+            compilerlibs/ocamloptcomp.cma
        cd tools; $(MAKE) all

 ocamltoolsopt: ocamlopt
diff --git a/tools/Makefile.shared b/tools/Makefile.shared
index 2263e48..151bb8f 100644
--- a/tools/Makefile.shared
+++ b/tools/Makefile.shared
@@ -267,6 +267,7 @@ objinfo_helper$(EXE): objinfo_helper.c ../config/s.h

 OBJINFO=../compilerlibs/ocamlcommon.cma \
         ../compilerlibs/ocamlbytecomp.cma \
+        ../compilerlibs/ocamloptcomp.cma \
         ../asmcomp/printclambda.cmo \
         objinfo.cmo
mshinwell commented 8 years ago

I don't think you should set the compilation unit in Variable.print (apart from anything else, that function wouldn't be expected to have such an effect). Just use Compilation_unit.create once in ocamlobjinfo and set it once before printing the export info. Does that not work?

objmagic commented 8 years ago

Thanks for the advice. Here is my another attempt. https://github.com/chambart/ocaml-1/pull/22

I am not sure if the Ident.create_persistent and Linkage_name.create used correct name. I didn't figure out the meaning of Linkage_name...

Also, it would be good to try some cmx files that actually export implementations. I tried some cmx files but their export fields are empty.

mshinwell commented 8 years ago

I will look at the patch. One gotcha that has arisen recently: you must use the "-flambda" option to the configure script before building the compiler. Check whether the export info fields are still empty after doing that (they should not be).

objmagic commented 8 years ago

rebased against trunk.

https://github.com/marklrh/ocaml/commit/8ccc8fa93555cd0c7fd9c9ce339eb8375acdffdc

there is suddenly something wrong with my opam configuration and installation script. I will test tomorrow.

mshinwell commented 8 years ago

I had to change a few things, but this is now merged upstream.