caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Adrien <camaradetux@gmail.com>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Timing module initializations (working but crashy)
Date: Mon, 9 Apr 2012 00:30:03 +0200	[thread overview]
Message-ID: <CAP5QFJnwf88ov00cjoXNBYDPj9P6r6nXHJdn_5Yp+i6stX6o-Q@mail.gmail.com> (raw)

Hi,

A few months ago I think I saw some module initializations in lablgtk2
take a lot of time. By module initializations, I mean the evaluation of
toplevel expressions from source files at application startup.

I found out about ld's --wrap option which can wrap a symbol. I then
wrap all the camlSomeModule__entry symbols into a C function. When I
start the program, I get an output like:

  Initialiazing Pervasives.
  Done initializing Pervasives in 0.236261 milliseconds.
  Initialiazing Array.
  Done initializing Array in 21.480000 microseconds.
  [...]
  Initialiazing Random.
  Done initializing �H in 11.417000 microseconds.
  [...]
  Initialiazing GPack.
  Done initializing g in 2.782904 milliseconds.
  Initialiazing GButton.

  Program received signal SIGSEGV, Segmentation fault.
  0x000000000057618b in caml_oldify_local_roots ()

The bogus module name after module initialization is the first sign that
something has gone wrong (the string has not been changed: it's the char*
_pointer_ to the module name which has been changed).

My program is an ocaml wrapper to GCC (as a linker) which generates
wrapper functions for the modules named in the environment variable
"MODULES" (space-separated). The code is (currently) at:
  http://notk.org/~adrien/link.ml
You can build with: "ocamlopt unix.cmxa str.cmxa link.ml -o gcc".
Now, make sure that the directory with this "gcc" executable is in your
PATH and is the first element (I never said this was very clean :-) ).

In the output C code, commenting out the two lines which change indent,
makes the segfault go away but the memory corruption still happens.

How could I fix this code? And what are the constraints which I should
have taken into account?

I've managed to make the program survive long enough to finish starting
by setting the minor heap to 10M words with OCAMLRUNPARAM but I'd
really prefer something clean.


PS: In order to put all possible module names in the MODULES environment
variable, I use the following:
  pmake \
  && MODULES="$(nm caravel.native | grep 'T caml.*__entry$' \
    | cut -f3 -d' ' | sed -e 's/caml\(.*\)__entry/\1/g' | xargs)" \
  && rm src/_build/browser/caravel.native \
  && MODULES="${MODULES}" pmake \
  && gdb ./caravel.native
This builds the project, finds all the camlSomeModule__entry symbols
which are referenced in the output (native code) binary, removes the
final binary and builds the project again, thereby forcing a relink,
with MODULES set.

PS2: most initializations are very fast but I've already found some like
GWindow which takes 22ms here, 1000 times more than most other modules.
And less than 5% of the modules seem to be responsible for almost all
the initialization time.


Thanks,
Adrien Nader


             reply	other threads:[~2012-04-08 22:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-08 22:30 Adrien [this message]
2012-04-10 16:25 ` Adrien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAP5QFJnwf88ov00cjoXNBYDPj9P6r6nXHJdn_5Yp+i6stX6o-Q@mail.gmail.com \
    --to=camaradetux@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).