CIL(Linker)

πŸ“¦
version 6.14.1 Β· 2 versions
, in alpine 3.24, epel 10, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– CIL(Linker) πŸ’–

okay so bestie, welcome to the monolinker page β€” the CIL(Linker) manual, literally the glow-up guide for your assemblies. sit down, grab a boba, and let's get into it πŸ§‹βœ¨


✨ NAME ✨

Mono CIL Linker β€” that's the whole name, no notes πŸ’…


🌸 SYNOPSIS 🌸

monolinker [-o output_directory][-l i18n_assemblies][-c skip | copy |
link] -x descriptor | -a assembly | -i info_file ...

πŸ¦‹ DESCRIPTION πŸ¦‹

so monolinker is a CIL Linker. what does that even mean? okay so basically it's a tool you use to ship only the absolute bare minimum set of functions that a set of programs might need to run, instead of dragging the entire full libraries along with you. minimalism era, we love to see it πŸŽ€

The linker analyzes the intermediate code (CIL) that every compiler targeting the Mono platform produces β€” think mcs, gmcs, vbnc, booc or whatever else you got. It walks through all the code you hand it and removes every unused method and class. The way it does this is a mark and sweep operation on all the code that's referenced. mark, sweep, slay. πŸ”₯

The output that monolinker generates can later be processed by the mkbundle tool to generate small native self-contained executables. cute AND functional ✨

not me needing to say this but: do not confuse this with the Assembly Linker (al), which creates assemblies from manifests, modules and resource files. different tool, different vibe, don't mix them up πŸ™ˆ

πŸ‘‘ OPTIONS πŸ‘‘

  • -d search_directory β€” tell the linker which directory to look in when it's hunting for assemblies. like, "the girlies are over here" πŸ“
  • -o output_directory β€” specify the output directory. default is 'output'.
okay important: if you set this directory to '.', please make sure you're not about to write over important assemblies of yours. no cap, protect your files πŸ’€
  • -b true | false β€” whether to generate debug symbols or not. default is false.
  • -g true | false β€” whether to generate a new guid for each linked module, or reuse the existing one. default is true.
  • -l i18n_assemblies β€” specify what to do with the region-specific assemblies.

Mono has a few assemblies that contain everything region specific:

I18N.CJK.dll
I18N.MidEast.dll
I18N.Other.dll
I18N.Rare.dll
I18N.West.dll

By default they all get copied to the output directory, but you can pick which ones you want with this command. The choice can be: none, all, cjk, mideast, other, rare or west. You can combine values with a comma. pick your faves, build your own roster πŸ’…

  • -c action β€” specify the action to apply to the core assemblies.

Core assemblies are the assemblies that belong to the base class library, like mscorlib.dll, System.dll or System.Windows.Forms.dll.

The linker supports three operations on these assemblies, and you pick one:

  • skip β€” this tells the linker to skip them and do nothing with them. hands off, not my business πŸ™…
  • copy β€” this tells the linker to copy them to the output directory.
  • link β€” this tells the linker to apply the linking process and reduce their size. the full glam treatment ✨
  • -p action assembly β€” specify per assembly which action to apply. one rule for everybody? no ma'am, custom rules per assembly πŸ’–
  • -x descriptor β€” use an XML descriptor as a source for the linker.

Here's an example that shows all the possibilities of this format:

<linker>
     <assembly fullname="Library">
          <type fullname="Foo" />
          <type fullname="Bar" preserve="nothing" required="false" />
          <type fullname="Baz" preserve="fields" required="false" />
          <type fullname="Gazonk">
               <method signature="System.Void .ctor(System.String)" />
               <field signature="System.String _blah" />
               <field name="someFieldName" />
          </type>
     </assembly>
</linker>

In this example, the linker will link the types Foo, Bar, Baz and Gazonk.

The preserve attribute makes sure that all the fields of the type Baz will always be linked, no matter if they're used or not β€” but that neither the fields nor the methods of Bar will be linked if they're not used. Not specifying a preserve attribute implies that we're preserving everything in the specified type. all of it, every crumb πŸ“

The required attribute specifies that if the type is not marked, during the mark operation, it will not be linked.

The type Gazonk will be linked, as well as its constructor taking a string as a parameter, and it's _blah field.

You can have multiple assembly nodes. go off, stack them up πŸ“š

  • -a assemblies β€” use an assembly as a source for the linker.

The linker will walk through all the methods of the assembly to generate only what is necessary for this assembly to run.

  • -i info_file β€” use a .info xml file as a source for the linker.

An info file is a file produced by the tool mono-api-info. The linker will use it to generate an assembly that contains only what the public API defined in the info file needs.

  • -s [StepBefore:]StepFullName,StepAssembly[:StepAfter]

You can ask the linker to execute custom steps by using the -s command. This command takes the standard TypeFullName,Assembly format to locate the step. You can customize its position in the pipeline by either adding it before a step, or after. main character energy, choosing your own placement πŸ’…

Example:

using System;

using Mono.Linker;
using Mono.Linker.Steps;

namespace Foo {

     public class FooStep : IStep {

          public void Process (LinkContext context)
          {
               foreach (IStep step in context.Pipeline.GetSteps ()) {
                    Console.WriteLine (step.GetType ().Name);
               }
          }
     }
}

If you compile this custom against monolinker to a Foo.dll assembly, you can use the -s switch as follows. To add the FooStep at the end of the pipeline:

monolinker -s Foo.FooStep,Foo -a program.exe

This commanand will add the FooStep after the MarkStep:

monolinker -s MarkStep:Foo.FooStep,Foo -a program.exe

This command will add the FooStep before the MarkStep:

monolinker -s Foo.FooStep,Foo:MarkStep -a program.exe

This command will add the FooStep before the MarkStep

  • -m CustomParam ParamValue β€” specify a parameter for a custom step. custom step, custom param, custom everything πŸŽ€

Copyright (C) 2007 Novell, Inc (http://www.novell.com)


πŸ’€ BUGS πŸ’€

Bugs report are welcome at https://github.com/mono/linker/issues

Product Mono Tools, Component linker.

fr fr, if something's busted, tell the girlies at the issue tracker 🫢

🌈 MAILING LISTS 🌈

Mailing lists are listed at http://www.mono-project.com/community/help/mailing-lists/


⭐ WEB SITE ⭐

http://www.mono-project.com/docs/tools+libraries/tools/linker/


🧚 AUTHORS 🧚

The linker has been written by Jb Evain, and have been partially founded by the Google Summer of Code. iconic origin story honestly πŸ‘‘


🌸 LICENSE 🌸

The linker is licensed under the MIT/X11 license. Please read the accompayning MIT.X11 file for details.


πŸŽ€ SEE ALSO πŸŽ€

al(1), mkbundle(1), mono(1), mcs(1)


okay that's the whole thing bestie, you're officially a linker expert πŸ’…βœ¨ this was the monolinker page from the CIL(Linker) manual β€” go forth and link responsibly, ily πŸ«ΆπŸ’–

πŸ“¦ where this page comes from