Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
ocamlopt generates broken object files #7427
Original bug ID: 7427
Given the file , the linking usually fails this way:
$ ocamlopt -version
Although I see sometimes:
and sometimes the link even succeeds.
Comment author: @xavierleroy
I couldn't reproduce the problem on my machine (x86-64, Ubuntu 16.04), neither with 4.03.0 nor with 4.03.0+flambda, both coming from OPAM.
Could you give us more details on your OCaml configuration and how to reproduce the issue?
Comment author: @sliquister
I can't reproduce the problem either with my instructions :/. I think I was confused when I was narrowing down the use case by the build system rebuilding things while I was running commands. That would explain the random errors.
In any case, I narrowed my issue again more carefully, and ended up at the same file, BUT the command to build is: ocamlopt -inline 20 main.ml. And this time, the only possible error is the first one.
Comment author: @mshinwell
The problem (with this specific example anyway) only occurs with Closure, not Flambda, as far as I can tell. This is probably because Flambda does both the lifting of the constant closure for "bbb" together with the rewriting of the variable "M.bbb" to the corresponding symbol where it is applied on the penultimate line. When using Closure, the lifting is left to Cmmgen.
In the function Cmmgen.transl_let there is a case that says "if the defining expression of a let doesn't have a result, then ignore the body". In this example, the defining expression of M.aaa is non-terminating and will hit this case. This causes the "bbb" closure not to be lifted.
The fix would appear to be to still examine the body of such lets to lift constant closures out of them. I will attempt to write a fix tomorrow.