[Mono-list] Static CIL Libraries

Jonathan Pryor jonpryor@vt.edu
18 Oct 2002 11:57:34 -0400


Actually, from chatting off-list with Dan, it sounds like he's really
after a way to create *something* that can be used by other assemblies
without requiring that the types of *something* be public.

For example, we have our internal-use-only code (which we don't want
others to use) in `shared.cs'.  OK, simple enough: mark the types in
`shared.cs' as `internal'.  Ah, but what if you want to use `shared.cs'
in lots of different DLLs and EXEs?  Simple enough: compile `shared.cs'
into each assembly that needs the shared code.

But what if another group is responsible for the source code, or
`shared.cs' is actually dozens of source files.  Do you really want to
recompile all these files for each different assembly they logically
belong to?

The .NET way to do this is with modules.  A module is a file that
contains IL code but *doesn't* contain a `.assembly' CIL directive.  In
other words, it's an assembly-less unit of IL code.  Being assembly-less
is important: it allows the classes of the module to be `internal', yet
shared among multiple different assemblies.

On .NET, this would be done by:

	# create shared module code shared.netmodule
	csc /t:module shared.cs

	# create app which uses shared module
	csc /t:exe /addmodule:shared.netmodule app.cs

This is fully supported by ECMA-335: it creates a multi-file assembly. 
See ECMA-335, Partition 2, Section 6 (page 11).

See also: 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconbuildingmulti-fileassembly.asp

Mono appears to support multi-file assemblies (at least, it ran the
test-case I created with .NET).  MCS doesn't; using the `/t:module'
compile flag creates a .dll with a .assembly directive.

It's interesting to create a .netmodule file and run monodis on the
resulting output.  It looks like normal CIL code, but it's missing the
.assembly directive.

 - Jon

On Thu, 2002-10-17 at 18:56, Miguel de Icaza wrote:
> Hello!
> 
> > Can mono/mcs create and use static CIL libraries?
> > 
> > If so, how do you create the static CIL libraries?
> > How do you link these static CIL libraries with something you are bulding?
> > 
> > What about Microsoft .NET, Rotor, or Portable.Net?
> > 
> > If not, can we persuade the Mono team, the Microsoft .NET team, the Rotor
> > team, the Portable.Net team, the ECMA standards people, and others to
> > include standard static CIL libraries support in their C# compiler and CLR
> > runtime?
> 
> The question really is what do you mean by a static CIL library.  
> 
> In the Unix world you have two kinds of libraries: static and dynamic. 
> The difference being that the dynamic libraries contain code that can
> cope with  position-independent layout of the code and can be loaded at
> different addresses, hence allowing dynamically linked executables to
> work.
> 
> So the concept does not really apply to .NET, as there is no machine
> code in the actual assembly, so the assembly is always relocatable.
> 
> Maybe you are thinking of some kind of support to *embed* a library into
> an executable.   If you are looking at that, you should be thinking in
> terms of assemblies.
> 
> Miguel.
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list