This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Shared library -shared vs. -fpic


> PIC stands for Position-Independent Code. 

Correct.

> Code isn't position-independent (or ``relocatable'') cannot be
> loaded at an arbitrary address;

Wrong.

> it requires some references to be patched at load time.

Correct.

> Shared libraries need to be relocatable because it's not known
> beforehand what address they will be loaded at

Correct, depending on the meaning of "relocatable". PIC code typically
does not contain relocations; that's why its position-independent.

> Just because you don't specify -fPIC doesn't mean that the compiler
> won't emit position-independent code; the option prevents it from
> emitting position-dependent code in situations where it otherwise
> would.

Correct. However, a non-trivial shared library typically won't be
position-independent unless explicitly compiled with
-fPIC. Linux/glibc indeed does not require a shared library to be
position-independent; instead, it will perform the relocations in the
binary, even if they refer to code pages. As a result, those relocated
pages won't be shared across processes, anymore.

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]