Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault apparently due to dynlink'ed code (both native and bytecode) #4707

Closed
vicuna opened this issue Feb 1, 2009 · 2 comments
Closed
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Feb 1, 2009

Original bug ID: 4707
Reporter: letouzey
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2009-02-05T09:54:02Z)
Resolution: not a bug
Priority: normal
Severity: major
Version: 3.11.0
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hi

While converting some parts of the Coq system into dynlink'able
plugins, I've encountered the following issue: while other plugins
work great, the one containing Subtac (the work of Matthieu Sozeau,
also known as Program) triggers a segfault when processing one of the
file of the Coq Standard Library. The same Subtac code works well when
compiled statically into Coq. This segfault appears to be
reproducible both with native and bytecode ocaml 3.11, either on amd64
or x86. I haven't tried yet with (bytecode) dynlink of earlier
versions of ocaml.

For the moment, to reproduce the bug, I'm afraid I can only point to
the Coq source, see below. I plan to investigate more the issue, so I
might be able to exhibit later a smaller testcase. Anyway D. Doliguez
encouraged me to report this matter early. Last disclaimer: it may
perfectly happen that my construction of subtac_plugin.cma does
something wrong (or some part of Matthieu's code ?), but if it is the
case, an error message nicer than segfault would be nice...

Steps to reproduce:

  1. get a copy of the development version of Coq sources (a recent one,
    for instance today's svn revision 11875) :

svn checkout svn://scm.gforge.inria.fr/svn/coq/trunk/ -r 11875
cd trunk

  1. activate the build of subtac_plugin.cm{a,xs} (which is currently disabled)
    by applying the small patch attached to this bug-report

patch -p1 < activate_subtac_as_plugin.patch

  1. configure (note: camlp5 required) :

./configure -local -debug -opt

  1. check that (nat)dynlink has been selected :

    grep HASNATDYNLINK config/Makefile

  2. launch the build:

    make

This currently fails on file theories/Classes/RelationClasses.v
By default, the build is done via native coqtop.opt. The bytecode version
can be build via "make bin/coqtop.byte" and then used via:
bin/coqtop.byte -l theories/Classes/RelationClasses.v

Best regards,
Pierre Letouzey

File attachments

@vicuna
Copy link
Author

vicuna commented Feb 2, 2009

Comment author: @xavierleroy

Thanks for the nice repro case. I had no problems observing the crash on Linux/amd64. The "value_interp" function in tacinterp.ml receives as argument the integer 0 while it expects a block. Since I'm old and experienced, I grepped "Obj.magic" in contrib/subtac, and lo and behold I found one in subtac_obligations.ml:

let default_tactic_expr : Tacexpr.glob_tactic_expr ref = ref (Obj.magic ())

Naughty, naughty boys :-) Replacing this line with

let default_tactic_expr : Tacexpr.glob_tactic_expr ref = ref (Tacexpr.TacId [])

causes the compilation of RelationClasses.v not to segfault, but report a more meaningful error:

File "/home/estephe/xleroy/coq-11875/theories/Classes/RelationClasses.v",
line 312, characters 2-18:
Error: More than one program with unsolved obligations

My guess is that Subtac_obligations.set_default_tactics is not called at the right times when dynamic loading is activated. I don't know whether that's a bug in Coq's sources or whether it points out to an unwanted semantic difference between Caml's static and dynamic linking. Could you please investigate on Coq's side and let me know what you find?

@vicuna
Copy link
Author

vicuna commented Feb 3, 2009

Comment author: letouzey

Hi Xavier,

Thanks for the help with this issue, which is indeed 100% due to our stuff,
not ocaml: the error you've encountered was caused by Subtac_obligations.init () not being executed, due to its too-late-registration into Coq "summary" mecanism.
A patch is on its way to Coq trunk svn.

Additionally, naughty boys will be dully notified of your discovery of this
jewel in their code ;-)

Sorry for the disturbance...

Pierre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants