Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007603OCamlplatform support (windows, cross-compilation, etc)public2017-08-08 19:352017-10-04 18:56
Assigned Tofrisch 
PlatformWindows CygwinOSOS Version
Product Version4.04.2 
Target Version4.06.0 +dev/beta1/beta2/rc1Fixed in Version 
Summary0007603: segfault on windows in dynlink'd module's entry routine
DescriptionI have an OCAML program that I am trying to port to Windows (using the cygwin version of OCAML), and when it executes, it segfaults. I haven't been able to completely track down the cause of the error, but below is the stack trace in gdb, and I have been able to determine that adjusting the inlining settings seems to be capable of suppressing the bug, so I suspect that the issue is in the middle-end somewhere. I tried reducing the program further but it seems like the bug seems to only arise when the program reaches a certain point of complexity, so unfortunately the steps to reproduce the issue are a little involved.

#0 0x62c7e1c8 in camlRealdef__entry () from /home/dwightguth/rv-match/c-semantics/semantics/x86-gcc-limited-libc/cpp14-translation-kompiled/cpp14-translation-kompiled/program/realdef.cmxs
#1 0x0051d8e9 in caml_start_program ()
#2 0x00519617 in caml_callback ()
0000003 0x0051d520 in caml_natdynlink_run ()
0000004 0x0049ad25 in camlDynlink__fun_3854 () at dynlink.mlopt:176
0000005 0x004a3739 in camlList__iter_1258 () at
0000006 0x0049b285 in camlDynlink__loadunits_3569 () at dynlink.mlopt:179
0000007 0x0049b315 in camlDynlink__load_3582 () at dynlink.mlopt:185
0000008 0x00404f19 in camlPlugin__load_2861 ()
0000009 0x00404e5b in camlInterpreter__entry ()
0000010 0x00401fd0 in caml_startup.code_begin ()
0000011 0x0051d8e9 in caml_start_program ()
0000012 0x00506ef5 in caml_main ()
0000013 0x0051e599 in main ()
Steps To Reproduce1. install ocaml on Cygwin with ocamlfind and zarith and mlgmp packages


$ tar xvf program.tar.gz
$ cd program
$ make
$ ./interpreter.exe ./realdef.cma

This should complete successfully, but instead it triggers a segmentation fault.
TagsNo tags attached.
Attached Filesgz file icon program.tar.gz [^] (586,762 bytes) 2017-08-08 19:35
gz file icon program2.tar.gz [^] (595,102 bytes) 2017-10-04 13:27

- Relationships

-  Notes
dra (developer)
2017-08-08 19:50
edited on: 2017-08-08 19:51

Which version of Cygwin are you using? (
cygcheck -dc cygwin

dwight.guth (reporter)
2017-08-08 19:54

Cygwin Package Information
Package Version
cygwin 2.8.2-1
dra (developer)
2017-08-09 12:22

I'm able to reproduce this. The program doesn't segfault if everything is compiled with -g and bytecode appears to work (regardless of -g)
dwight.guth (reporter)
2017-08-09 17:54

for what it's worth, I think the fact that it doesn't reproduce with -g might be a red herring. I made the file a bit larger by uncommenting some of the code I commented out (lines 23656-24377 of, and I was able to reproduce it both with and without -g. It seems to have some relation to the size of the code generated...
xleroy (administrator)
2017-09-30 18:38

Any chance of understanding this bug in the coming weeks? Should it be tentatively scheduled for 4.06 or not?
frisch (developer)
2017-10-04 11:14

I'm fighting a bit to install mlgmp. Is [^] the most up-to-date version?
frisch (developer)
2017-10-04 11:18
edited on: 2017-10-04 11:25

Ok, in case someone else needs to do install mlgmp:

   - You need to "make clean" to remove build artefact shipped in the source distribution.

   - Replace int32 -> int32_t, uint32 -> uint32_t in config.h.

   - To compile with 4.06 or trunk, add "-unsafe-string" to OCAMLFLAGS in Makefile.

   - "make install", then move the target directory into lib/ocaml/site-lib/gmp, and a META file with these two lines:

archive(byte) = "gmp.cma"
archive(native) = "gmp.cmxa"

frisch (developer)
2017-10-04 11:29

I was able to reproduce the segfault.
frisch (developer)
2017-10-04 11:37

Observation: moving the code out of the Def module to the toplevel in apparently eliminates the segfault.
frisch (developer)
2017-10-04 13:28

To simplify further investigation, I've uploaded program2.tar.gz, which depends only on a plain distribution of OCaml (not findlib, zarith, gmp). Also, in this version of the reproduction case, the main program is trivial and all the code is in the dynlinked code. Interestingly, inlining the content of into eliminates the segfault.
frisch (developer)
2017-10-04 14:26

Reproduced with the mingw port (32-bit).
frisch (developer)
2017-10-04 14:37

Ah, with the msvc port (32-bit), I get:

ocamlopt -w -A -shared -o realdef.cmxs
dyndll944c5f.obj : fatal error LNK1183: invalid or corrupt file: extended relocation count 21341 less 
than 65535
** Fatal error: Error during linking
frisch (developer)
2017-10-04 15:57

I think I got it, this is a problem in flexdll (namely: the rewriting performed by flexdll reduce the number of relocations from above 65535 to below this limit, but the corresponding flag that indicates more than 65535 relocations was not reset).
frisch (developer)
2017-10-04 16:12

Fix on the flexdll side by: [^]

No change required on the ocaml side.

For once, link.exe was more helpful than ld, which happily accepted the invalid COFF file generated by flexdll.
dra (developer)
2017-10-04 16:26

Is it worth adding the testcase to prevent regressions?
frisch (developer)
2017-10-04 18:56

It's really a large piece of code, and flexdll doesn't currently has any such non-regression test (not that it would be useless to have some). As for OCaml's testsuite, I don't think that would be the place to put it (esp. since using any currently released version of flexdll would trigger the bug).

- Issue History
Date Modified Username Field Change
2017-08-08 19:35 dwight.guth New Issue
2017-08-08 19:35 dwight.guth File Added: program.tar.gz
2017-08-08 19:50 dra Note Added: 0018165
2017-08-08 19:51 dra Note Edited: 0018165 View Revisions
2017-08-08 19:54 dwight.guth Note Added: 0018166
2017-08-09 12:22 dra Note Added: 0018168
2017-08-09 12:22 dra Assigned To => frisch
2017-08-09 12:22 dra Status new => confirmed
2017-08-09 17:54 dwight.guth Note Added: 0018169
2017-09-30 18:38 xleroy Note Added: 0018429
2017-10-02 13:58 doligez Target Version => 4.06.0 +dev/beta1/beta2/rc1
2017-10-04 11:14 frisch Note Added: 0018471
2017-10-04 11:18 frisch Note Added: 0018472
2017-10-04 11:20 frisch Note Edited: 0018472 View Revisions
2017-10-04 11:21 frisch Note Edited: 0018472 View Revisions
2017-10-04 11:25 frisch Note Edited: 0018472 View Revisions
2017-10-04 11:29 frisch Note Added: 0018473
2017-10-04 11:37 frisch Note Added: 0018474
2017-10-04 13:27 frisch File Added: program2.tar.gz
2017-10-04 13:28 frisch Note Added: 0018475
2017-10-04 14:26 frisch Note Added: 0018476
2017-10-04 14:37 frisch Note Added: 0018477
2017-10-04 15:57 frisch Note Added: 0018478
2017-10-04 16:12 frisch Note Added: 0018479
2017-10-04 16:15 frisch Status confirmed => resolved
2017-10-04 16:15 frisch Resolution open => fixed
2017-10-04 16:26 dra Note Added: 0018480
2017-10-04 18:56 frisch Note Added: 0018482

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker