Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007427OCamlback end (clambda to assembly)public2016-12-06 16:242016-12-09 10:02
Reportersliquister 
Assigned To 
PriorityhighSeverityminorReproducibilityhave not tried
StatusclosedResolutionduplicate 
PlatformOSOS Version
Product Version4.03.0 
Target VersionFixed in Version 
Summary0007427: ocamlopt generates broken object files
DescriptionGiven the file [1], the linking usually fails this way:

$ ocamlopt -version
4.03.0
$ rm -f main.o; ocamlopt main.ml
main.o: In function `camlMain__ccc_1208':
/path/to/main.ml:8: undefined reference to `camlMain__bbb_1207'
collect2: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking

Although I see sometimes:
$ ocamlopt main.ml
/usr/bin/ld: error in main.o(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: main.o: invalid string offset 1126 >= 564 for section `.strtab'
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
$ ocamlopt main.ml
main.o: file not recognized: File truncated
collect2: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking

and sometimes the link even succeeds.

[1]
$ cat main.ml
module F() = struct
  let ( *>>| ) t f = f t
  let ddd _ = assert false
  module M = struct
    let aaa = ddd (() *>>| fun _ -> assert false)
    let bbb () = () *>>| (fun _ -> assert false)
  end
  let ccc () = M.bbb ()
end
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0016655)
xleroy (administrator)
2016-12-06 19:58

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?
(0016693)
sliquister (reporter)
2016-12-07 00:28

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.
(0016694)
sliquister (reporter)
2016-12-07 00:39

The machine is x86-64 as well, running linux. I just tested with 4.04.0 and I see the same problem.
(0016698)
xleroy (administrator)
2016-12-07 12:09

Reproduced with 4.03.0, no flambda, -inline 20.
(0016750)
bvaugon (developer)
2016-12-07 17:55

To simplify, the following example is broken with inlining <= 1 and works well with inlining > 1:

module F() = struct
  module M = struct
    let aaa = assert false
    let bbb () = assert false
  end
  let ccc () = M.bbb ()
end
(0016801)
sliquister (reporter)
2016-12-07 18:56

Looking at the simpler example, I imagine something is deducing that bbb is dead code because of aaa, and deletes it. But that thing doesn't deduce that ccc is dead code and so ccc ends up calling a non-existent bbb.
(0016916)
shinwell (developer)
2016-12-08 17:15

I will look at this
(0016923)
shinwell (developer)
2016-12-08 17:43
edited on: 2016-12-08 17:44

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.

(0016939)
shinwell (developer)
2016-12-09 10:01

Superceded by https://github.com/ocaml/ocaml/pull/959 [^]

- Issue History
Date Modified Username Field Change
2016-12-06 16:24 sliquister New Issue
2016-12-06 19:58 xleroy Note Added: 0016655
2016-12-06 19:58 xleroy Status new => feedback
2016-12-07 00:28 sliquister Note Added: 0016693
2016-12-07 00:28 sliquister Status feedback => new
2016-12-07 00:39 sliquister Note Added: 0016694
2016-12-07 12:09 xleroy Note Added: 0016698
2016-12-07 12:09 xleroy Status new => confirmed
2016-12-07 17:55 bvaugon Note Added: 0016750
2016-12-07 18:56 sliquister Note Added: 0016801
2016-12-08 17:15 shinwell Note Added: 0016916
2016-12-08 17:16 shinwell Assigned To => shinwell
2016-12-08 17:16 shinwell Status confirmed => assigned
2016-12-08 17:43 shinwell Note Added: 0016923
2016-12-08 17:44 shinwell Note Edited: 0016923 View Revisions
2016-12-08 17:45 shinwell Priority normal => high
2016-12-09 10:01 shinwell Note Added: 0016939
2016-12-09 10:02 shinwell Status assigned => closed
2016-12-09 10:02 shinwell Assigned To shinwell =>
2016-12-09 10:02 shinwell Resolution open => duplicate
2017-02-23 16:35 doligez Category OCaml backend (code generation) => Back end (clambda to assembly)
2017-02-23 16:44 doligez Category Back end (clambda to assembly) => back end (clambda to assembly)


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker