jacob navia said:
Position independent code is assembly that can be loaded at any address
for execution.
It's more than that. Position independent code can be
loaded at any address and later it can be moved/copied
(in its entirety) to another address, and it will run
correctly from that new address.
Most compile/link procedures will generate internal
constants in the object code that are called "relocatable
address constants" (RAC). When a program is loaded into
memory for execution, the loader will "fix up" all of
the RAC fields by adding the base address of the program
to each RAC field, thus yielding a "position dependent"
address constant field that the program can use.
If such a program were copied to another memory location,
the RAC fields would have the old address values and the
program would misbehave in strange and usually disastrous
ways.
A position independent program does not have RAC fields.
Thus, it can be loaded at one memory address and later
copied to another memory address, and it will still run
at the new address. All memory references in the program
are calculated at run-time according to its current
location in memory, rather than loading RAC fields.
There is no way you can do that in C, since the objective of writing in
C is to avoid writing in assembly language. Some compilers support this,
and there are compile time flags to direct the compiler to generate that
kind of code.
There is nothing in the C language that pertains to
position dependent/independent programs, or to
programs that can loaded anywhere (also called
"relocatable") or must be loaded at a specific memory
address (usually device drivers must live at a specific
memory address and refer to specific memory locations
which outside the C language).
--
----------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!