objinfo: tell when the object file comes from a different OCaml version#463
objinfo: tell when the object file comes from a different OCaml version#463gasche merged 3 commits intoocaml:trunkfrom
Conversation
|
Once we have some logic in the compiler codebase that understand magic numbers, we can use it in other places than (ocaml)objinfo. In particular, when the compiler itself reads a compiled object file, it currently has the same irritating behaviour of not recognizing that object file from other OCaml versions are a bit more valid than random text files with the wrong extension, and we could easily fix that. Depending on the feedback on this PR, I may try to do this it as well. There is no Changes entry for this one. I'm not quite sure where I should put it, and if I understand correctly |
cc404a3 to
4abca28
Compare
|
Look for |
|
Oh, I hadn't seen that the |
|
I agree it's a good idea to generalize it, especially if you share the implementation. |
|
It is installed: |
|
So I started working a bit more on this PR, but:
I'll thus wait for the release branching. |
|
I had forgotten about this PR; I would like to work on it more sometime after the release. |
|
@gasche Would you have time to bring this up-to-date? |
|
@mshinwell thanks for your hard triaging work today :-) |
ac96f66 to
97fcd5f
Compare
|
I rebased my patch against trunk. I should also look at Damien's remark on using in in |
|
There seems to be a minor double- |
2212e4c to
67444ec
Compare
|
So I tried to use the new functions in a few places in the compiler -- namely A difficulty that made this quite more difficult than I expected is that all use-sites have already their own error-reporting logic, and that it is not trivial to integrate the Changing the error-reporting logic results in better-quality error messages (which was the goal in the first place), but it requires changing the exception types for the affected modules. We have to think about this, because it means that it can break For each of the two updated sites I thus did two iterations:
@damiendoligez, would have a look and give your opinion on whether you think these changes are worthwhile? If we consider that the improved error messages are not worth changing the error type declarations, I can easily roll-back to the "first iteration" approach. |
184e070 to
51d6b09
Compare
Drup
left a comment
There was a problem hiding this comment.
I like the new API quite a lot. As someone who hacked into cmi files at some point. this API would be much easier to tinker with.
Something that would make it even better (for me) would be to have a function similar to check_current but of type kind list -> info -> (kind, unexpected_error) result, which would try to check for several magic kind, and return the one we got.
|
I just rebased the PR on top of trunk. I also redesigned the API of the Magic_number module, and (following @shindere's comments on feature bloat) restricted the scope of the PR to improving In his review @Drup had made criticism of the API, which relied too much on exceptions. I used exceptions to make caller-site changes less invasive. The new API is written without any exception, purely using the @Drup, would you be willing to give another round of review to the PR? |
80addc3 to
071623c
Compare
|
(I managed to convince Travis to indeed check this PR.) |
There was a problem hiding this comment.
Looks good! As an added benefit, objinfo now understands serialized ASTs, which is nice. All my comments are minor. travis also spotted a few long-lines:
./tools/objinfo.ml:334.81: [long-line] line is over 80 columns
./utils/misc.ml:996.81: [long-line] line is over 80 columns
071623c to
bd91019
Compare
|
I rebased the PR to address @Drup's last batch of comments. |
bd91019 to
443a9de
Compare
This module was originally inspired by js_of_ocaml Misc.MagicNumber module https://github.com/ocsigen/js_of_ocaml/blob/151b811/compiler/util.cppo.ml#L277-L347 It provides parsing and validation function for magic numbers, that can tell the difference between "not a valid magic number" and "a valid magic number, but with another version", and print user-friendly user messages about it. It does not contain any knowledge for where to find the magic number in an OCaml file (this depends on the file format); the parsing function should be called with an input channel already at the right position for whichever format is expect.
When passed an object file that comes from a different OCaml version,
objinfo will currently just detect that the magic number is not what
it expects, and claim it is not a valid file. This is irritating.
The error message output by objinfo now looks like this:
File /home/gasche/.opam/4.08.0/lib/astring/astring.cmi
Wrong magic number:
this tool only supports object files produced by compiler version
4.11.0+dev0-2019-10-18
This seems to be a compiled interface file (cmi) for an older version of OCaml.
|
I went ahead and merged in trunk. Thanks again @damiendoligez and @Drup for the reviews. This story arc is not yet complete; only |
|
The objinfo test is now broken on Wygwin32. File question.cmxs |
|
And by the way, this also affects the 4.10 branch. |
|
Do you think that it is related to this PR? This PR was merged two days ago, in trunk only (I think? no reason to cherry-pick to 4.10), so I don't think it could explain a broken test on 4.10. |
|
Gabriel Scherer (2019/12/05 01:52 -0800):
Do you think that it is related to this PR? This PR was merged two
days ago, in trunk only (I think? no reason to cherry-pick to 4.10),
so I don't think it could explain a broken test on 4.10.
Well that may be a wrong guess of mine, sorry if that's the case.
Given the times it takes to build OCaml on Cygwin the bisection is not a
very appealing solution so I guess somebody will have to investigate.
I'll see whether I can do it or not.
|
|
(I think that today, being a general strike day in France, is an excellent day to not investigate an obscure Cygin32 failure (don't count on me!), but I'm going to humor you and ask the first question that comes to mind.) Do we know when the failures started to happen? |
|
Gabriel Scherer (2019/12/05 02:36 -0800):
(I think that today, being a general strike day in France, is an
excellent day to *not* investigate an obscure Cygin32 failure (don't
count on me!), but I'm going to humor you and ask the first question
that comes to mind.) Do we know when the failures started to happen?
No, we don't.
And actually I am now investigating another hypothesis. It may very well
be that this test was actually never executed under Cygwin32 because its
BFD library was just not detected. Due to the recent fixes in the BFD
support, hte library is now correctly detected and the test is run...
and fails.
|
|
I confirm the hypothesis mentionned above. objinfo_helper can not find the caml_header_plugin symbol for several |
Minor GC: restrict global roots scanning to one domain
…currences-diff Speed up Name_occurrences.diff
When passed an object file that comes from a different OCaml version,
objinfo will currently just detect that the magic number is not what
it expects, and claim it is not a valid file. This is irritating.
The current patch implements some more advanced handling of magic
number in a new Misc.Magic_number module, inspired by js_of_ocaml
Misc.MagicNumber module
https://github.com/ocsigen/js_of_ocaml/blob/151b811/compiler/util.cppo.ml#L277-L347
that lets us easily tell the difference between "not a valid magic number"
and "a valid magic number, but with another version".
The error message output by objinfo now looks like this: