caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chris Hecker <checker@d6.com>
To: Xavier Leroy <xavier.leroy@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] ocamlc linking loads dlls?
Date: Thu, 14 Nov 2002 10:21:12 -0800	[thread overview]
Message-ID: <4.3.2.7.2.20021114100219.041968b0@localhost> (raw)
In-Reply-To: <20021114160348.B9597@pauillac.inria.fr>


> > ocamlopt doesn't do it, for what it's worth.
>Sure: ocamlopt links statically the Caml/C stub code.  It doesn't use
>the DLLs.

Right, but the problem I'm running into is I've got a C interface library 
between caml and another C dll, and that interface is compiled to a DLL on 
bytecode builds (like it's supposed to be since you implemented 
cma+dll).  The interface defines all the caml functions, but it in turn 
loads the C dll when it's loaded during link because it's a 
dependency.  So, the problem dll isn't even a dll that's needed by caml 
directly, but it's getting loaded anyway.  This could get really bad in the 
case of a big set of dependencies.  Or, imagine the case where there was a 
strict ordering of DLLs that needed to be loaded or another process that 
had to be running that the dllmain connected to, and it failed dllmain if 
that process wasn't running (like a license server).

> > a) dlls that aren't in the path during build, and
> > b) dlls that do complex stuff in their dllmain
>I agree b) is a bit of a problem, but I don't know of any portable way
>to test whether DLL x.dll defines symbol "foo" than to link x.dll and
>query the address of "foo".

I actually think a) is important as well, for modularity reasons.  In my 
above case, the interface dll only needed the import library from the C dll 
to link since it was done with the C linker.  This means I don't even need 
access to the real C dll to build, just its import library and a 
header.  In the case of something restrictive with security or licenses, I 
might not even have the C dll around until I move onto a test machine or 
something.

There's also the security problem of a _link_ now can run arbitrary code 
because the dllmain gets called, but I didn't bother mentioning that before 
because it's not like caml is trying to be high-security.  However, it is 
still an issue (imagine an app that needs to be built as root but run as 
another user...the dllmain is now run as root by ocamlrun...very irregular).

I understand your desire to fail early during link instead of at runtime, 
but I think this solution causes more problems, and more serious problems, 
than it solves.  Plus, the app will fail at load time, not in the middle of 
running (usually the cmas are all resolved at load, right?), and developers 
are "used to" dll's failing at load time during test if there's a 
versioning issue or something.

If you really must check this at link time (like I said, it's a worthy 
goal, it's just a question of tradeoffs), the right thing to do is write 
the imagehlp code to check the export without loading the dll.  It's pretty 
short.  I assume there's a similar thing on unix.  Until that code gets 
written, I think the better tradeoff is to disable checking during link.

Chris


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-11-14 18:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-14  6:25 Chris Hecker
2002-11-14 15:03 ` Xavier Leroy
2002-11-14 18:21   ` Chris Hecker [this message]
2002-11-14 20:16   ` Nicolas Cannasse
2002-11-14 19:21     ` Chris Hecker
2002-11-15  0:55       ` Jacques Garrigue
2002-11-15  1:53         ` Gerd Stolpmann
2002-11-15  6:59         ` Chris Hecker
2002-11-15  7:07           ` Jacques Garrigue
2002-11-15  8:00             ` Chris Hecker

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=4.3.2.7.2.20021114100219.041968b0@localhost \
    --to=checker@d6.com \
    --cc=caml-list@inria.fr \
    --cc=xavier.leroy@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).