Jay Shenawy
Jay Shenawy

Reputation: 1033

Embedded systems: static or dynamic linking

For Embedded systems where the program runs independently on a micro-controller :

Are the programs always static linked ? or in certain occasions it may be dynamic linked ?

Upvotes: 5

Views: 5397

Answers (3)

too honest for this site
too honest for this site

Reputation: 12263

Simply put: if there is a full-grown operation system like Linux running on the microcontroller, then dynamic linking is possible (and common).

Without such an OS, you very, very likely use static linking. For this the linker will (basically) not only link the modules and libraries, but also includes the functions which are done by the OS program loader.

Lets stay at these (smaller) embedded systems for now.

Apart from static or dynamic linking, the linker also does relocation. This does - simply put - change internal (relative) addresses of the program to the absolute addresses on the target device.

Upvotes: 3

Clifford
Clifford

Reputation: 93534

It is not common on simple embedded systems primarily because it is neither necessary nor supported by the operating system (if any). Dynamic linking implies a certain amount of runtime operating system support.

The embedded systems RTOS VxWorks supports dynamic linking in the sense that it can load and link partially linked object code from a network or file system at runtime. Similarly Larger embedded RTOSs such as QNX support dynamic linking, as does embedded Linux.

So yes large embedded systems may support dynamic linking. In many cases it is used primarily as a means to link LGPL licensed code to a closed source application. It can also be used as a means of simplifying and minimising the impact of deploying changes and updates to large systems.

Upvotes: 4

Eugene Sh.
Eugene Sh.

Reputation: 18371

From Wikipedia:

a dynamic linker is the part of an operating system that loads and links the shared libraries needed by an executable when it is executed (at "run time"), by copying the content of libraries from persistent storage to RAM, and filling jump tables and relocating pointers.

So it implies that dynamic linking is possible only if:
1) You have a some kind of OS
2) You have some kind of persistent storage / file system.

On a bare-metal micros it is usually not the case.

Upvotes: 5

Related Questions