I know both are used to make code that can be placed in different locations, but how does each work, and why?
Asked
Active
Viewed 324 times
1 Answers
2
For starters, they are options to different parts of the toolchain:
-fpic
and-fPIC
are GCC options that generates position-independent code. This affects the actual instructions chosen, to make the code run regardless of where it is located in memory. This requires support by the operating system's dynamic loader to actually make it runnable once loaded.-r
is a linker option that makes it emit relocatable code, i.e. code that can be linked again later on. It's part of ld's support for incremental linking.
I think their usage doesn't overlap, you can create relocatable (library) code without using ld -r
.

unwind
- 391,730
- 64
- 469
- 606
-
@MarkYisri Yes, that's in the GCC documentation link above, and I also mention it now. – unwind Nov 23 '16 at 15:09
-
okay, so is there a way to be position independent and not need relocation code. 'Cuz I want to do this on a non-MMU board and run apps seperate from my homemade kernel. – Nov 23 '16 at 15:50