Re: PIC is wasteful

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Agner Fog <agner@xxxxxxxxx> writes:

> When a shared object is shared between two processes, there will be
> two instances of the writable data sections, but both mapped to the
> same logical address, as I understand it.

Shared libraries are normally mapped to different virtual addresses in
different processes.  The writable data segment will be mapped to two
different physical addresses as well.  The shared readonly text segment
will be mapped to a single physical address, but will be accessed under
different virtual addresses by all the processes which use it.

> If I compile a shared object with -fno-pic in 32-bit x86 there will be
> absolute addresses in the code section needing relocation. What
> happens if this library is shared between two processes? Will I get
> two instances of the code section, or will the system recognize that
> these relocated references are identical in all processes because they
> refer to data sections that are all mapped to the same logical
> address?

If their are relocations for the code segment, then you will get a
separate instance of it for each process.  The system will not try to
check for the unusual case of two data sections at the same virtual
address.

> In 64 bit mode, I have to compile with -fpie which makes relative
> addresses in the code section. All absolute references are in data
> sections and exception handler tables, so I guess there is no issue
> here.

If there are no relocations in the code segment then it can be shared
among different processes.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux