caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oleg@okmij.org
To: paulfsnively@gmail.com
Cc: caml-list@inria.fr
Subject: [Caml-list] Delimcc.0 OPAM Package Difficulty on Mac OS X
Date: 9 Apr 2013 11:08:45 -0000	[thread overview]
Message-ID: <20130409110845.30459.qmail@www1.g3.pair.com> (raw)



Perhaps the following comment from delimcc:stacks.c will help:

/* This function is defined in stacks.h and implemented in the ocamlrun.
   We re-define it here with the weak attribute: although 
   the function is implemented by ocamlrun and so will be available
   at run-time, it is not exported by ocamlc. Unfortunately, ocamlc, 
   when linking the bytecode executable and checking dlls requires 
   that all symbols imported by dlls be satisfied at link time.
*/
void caml_realloc_stack (asize_t required_size)
  __attribute__ ((weak));


To elaborate: caml_realloc_stack is part of OCaml run-time, that is,
byte code interpreter. On my FreeBSD system:

nm -D /usr/local/bin/ocamlrun 
...
0000000000409ae0 T caml_realloc_stack
...

So, caml_realloc_stack exists and it is global (that is, exported and
available for linking). 

So, when testd0 is invoked, the bytecode interpreter ocamlrun starts,
loads eventually dlldelimcc.so. The latter needs caml_realloc_stack,
and it can find it in ocamlrun. Everything should work...

You might have noticed the strange thing that the error is reported
before testd0 gets to run -- by the compiler itself. This is because
ocamlc is a little bit too helpful. When it links the bytecode
executable, it loads all referenced dll -- at link time -- and checks
that all needed symbols _will_ be satisfied at run-time. (More
precisely, it does ldopen with the flag RTLD_NOW). Normally it
is not ordinary linker's job to simulate run-time linking. After all, the
run-time environment may be different from link-time
environment. And in our case, it is different indeed. If your ocamlc
is natively compiled, it does not use ocamlrun. And natively compiled
ocamlc does _not_ export caml_realloc_stack. So, the premature, too
helpful check really goes wrong here: caml_realloc_stack will be found
at run-time but cannot be found at link time (where it is not really
needed). 

The weak subterfuge was sufficient to keep ocamlc happy. 

nm -D dlldelimcc.so 
                 w caml_realloc_stack

The weak reference should never cause an error (even if it remains
unresolved) -- according to my man pages.  Apparently MacOS thinks
different. Or findlib may set some flag that cause dlopen
to behave differently. I don't have access to MacOS. I guess I would
first check that dlldelimcc.so  does indeed refers to
caml_realloc_stack as a weak symbol, and then ask around as to why it
causes the problems on MacOS specifically.

Of course I'd be happier if ocamlc didn't use the RTLD_NOW flag.




             reply	other threads:[~2013-04-09 11:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 11:08 oleg [this message]
2013-04-12  8:56 oleg
2013-04-16  6:01 oleg

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=20130409110845.30459.qmail@www1.g3.pair.com \
    --to=oleg@okmij.org \
    --cc=caml-list@inria.fr \
    --cc=paulfsnively@gmail.com \
    /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).