Elf linking

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
(Symbols)
(Linking)
Line 29: Line 29:
  
 
==Linking==
 
==Linking==
 +
 +
==Modules==

Revision as of 17:39, 28 June 2009

Adventures in dynamic linking

Contents

What is this

One of the most common concerns when developing on embedded systems is memory limitations. In particular on the NDS there is 4mb of ram which is almost impossible to fit games with rich content. The solution so far is NitroFS where you can store game and application data so that ram only contains the code necessary to run the game and most of the data is loaded as needed from external files. This works great for data but what about code?

To dynamically load code into a running program is a bit more complicated because code segments interact with each other take the functions below:

void someFunc(void) {
  printf("hai2u! \^_^\n");
}

Symbols

In this example there is a function named 'someFunc', some data "hai2u! \^_^\n", and a reference to an external function 'printf'. When that bit of code is loaded the program and data segments may be loaded into some arbitrary unpredictable location, so how does someFunc know the address of printf?? This process is called linking because each section of code needs to be linked to the others.

First it needs some way to identify locations in memory. This is accomplished with symbols. A symbol is a reference to a location in memory and minimally contains location in ram of the symbol, and a textual name for the symbol. It may also contain information about the type of symbol (program, data, global data, etc), who (or which process) owns the symbol, which section of the object file the symbol came from, group it belongs to, etc.

//Typical symbol table
typedef struct _SYMBOL {
	char *name;
	char *value;
	SYM_TYPE  type;
	UINT16    group;
} SYMBOL;

Many schemes exist for symbol table implementation, some use a hash table for quicker lookups, some use linked lists while others have a finite array. They all do the same thing, which is, to provide a database relating addresses to names. But what about linking?

Linking

Modules

Personal tools
irssi scripts
eggdrop scripts