Saturday, July 28, 2012

On linkers


Linker is a program that converts the object files into executables and shared libraries.

What a linker does? can be summarized into the following steps:
  • Parse options on the command line
  • Parse link scripts to read commands of linking
  • Symbol resolution
  • Relocation of instructions, data, symbols and sections
  • Output the linked file

Let's see the working of some existing linkers such as GNU ld, gold and MCLinker.

GNU ld
In the linking flow of GNU ld, the following steps are done iteratively:
  • Read and load the input files.
  • Do format checking.
  • Perform symbol resolution.
  • Apply relocation.

gold
gold separates the linking processes into two stages as follows:
  • stage 1: Do the following steps iteratively until all the files are read.
    • Read and load the input files.
    • Resolve symbols while checking the formats of the input files.
  • stage 2: Perform relocation in parallel.

MCLinker
MCLinker separated the linking processes into three stages as follows:
  • stage 1: Read and load input files. Check the formats.
  • stage 2: Symbol resolution.
  • stage 3: Perform relocation.

Click here for the reference of the above discussed linkers.
Click here for the what and how of linkers by Ian Lance Taylor.

Tuesday, July 3, 2012

Packager for binaries on any UNIX-compatible system


You may require to bundle the binaries built on any UNIX-compatible system for distribution.

For example, say, you have built a compiler using GCC compiler generation framework. And you need to distribute the built compiler binaries to some user. That means here you are required to distribute your gcc compiler installation directory to the user. How would you do that?

You can make a tar of the installation directory and distribute it to the user. But here you have to educate the user on how to untar and where to untar the provided tar file. And this way the user has to put some "extra" effort for using the binary distributed to him. Wouldn't it be better to provide the user with a self-extracting package of binaries?

Yes, you can provide the user with a self-extracting package of binaries. And the user has to just run it to extract the binaries into his desired directory. How to create a self-extracting package of binaries?

There is tool called "makeself". This is a very simple tool that does the job for you. Install this tool in your system and use it for creating the self-extracting package of binaries. For more information on "makeself", refer http://megastep.org/makeself/.

So for our example, assuming "myCompiler" as the installation directory to be distributed, create the self-extracting package "myCompiler.run" as follows:

makeself.sh --notemp myCompiler myCompiler.run "myCompiler generated from GCC framework" echo "myCompiler has been installed"