Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic linking vs Static linking vs PIC vs non PIC

Let us have a quick review of the cases for:

  • Not combining dynamic linking with position independent code. I might dare telling this is an impossible case, but as I dive in to the subject am less sure.
  • Combining static linking with position independent code. I believe this totally make sense as a valid combination.

But both options are actually correct, aren't them?

I would like to glance a four square map showing relevant cases, but have not found any at all.

like image 544
1737973 Avatar asked Sep 02 '25 16:09

1737973


1 Answers

While PIC/non-PIC and dynamic/static linking are independent concepts, there is an "affinity" between PIC and dynamic linking. However, beside a small performance penalty, there is no reason against using PIC in static libraries as well.

Furthermore, also dynamic libraries can be made relocatable. This approach is often done in MIPS systems. For static linking, relocatable code is frequently used anyway.

In addition, in the times of MMUs, the relation of PIC/nonPIC and static/dynamic linking is decoupled, or more precise: PIC becomes less significant.

To summarize: any combination is possible.

like image 71
Matthias Avatar answered Sep 05 '25 16:09

Matthias