>>junky_fellow wrote:
What is a position independent code ? What are the basic guidelines to
keep in mind while writing a position independent code ?
I was not going to say anything, because (as xarax notes) Standard
C insulates one entirely from the position-independence issues:
you write your code in Standard C and it "just works". If you need
the stuff that PIC may provide, you will not be writing Standard
C, and any non-standard compiler flags (such as -fpic) and/or
C-callable functions (such as mmap()) that you may need are, well,
non-standard -- you will have to investigate the details elsewhere.
"jacob navia" <ja***@jacob.remcomp.fr> wrote in message
news:41**********************@news.wanadoo.fr.. . Position independent code is assembly that can be loaded at any address
for execution.
In article <kO******************@newsread1.news.pas.earthlink .net>,
xarax <xa***@email.com> wrote: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.
PIC *used* to mean that, back when I wrote such things by hand.
These days the term has been taken over, at least on Unix-like
systems, to refer to code that is relocatable but not actually
"position independent", even though it will be run inside a
virtual-memory process, so that a dynamic loader can load new code
at run-time. GCC's "-fpic" and/or "-fPIC" flags (which may or may
not have subtly different meanings, depending on processor architecture
-- typically the uppercase version gives you larger displacements,
if "small+fast" and "large+slow" are both offered on the architecture)
tell it to build dynamic-relocation tables for this sort of
not-really-position-independent-code.
In other words, the meaning of "PIC" is now at best muddy: not only
is it off-topic in comp.lang.c, but different people will have
different ideas of what it *should* mean, on different systems. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.