Re: Info on PIC code

Ian Lance Taylor <ian@cygnus.com>
13 Jun 1997 22:01:44 -0400

          From comp.compilers

Related articles
Info on PIC code dwyatt@lcs.mit.edu (Doug Wyatt) (1997-06-10)
Re: Info on PIC code ian@cygnus.com (Ian Lance Taylor) (1997-06-13)
| List of all articles for this month |
From: Ian Lance Taylor <ian@cygnus.com>
Newsgroups: comp.compilers
Date: 13 Jun 1997 22:01:44 -0400
Organization: Compilers Central
References: 97-06-024
Keywords: code, architecture

In comp.compilers Doug Wyatt <dwyatt@lcs.mit.edu> writes:


>Are there any good references on the specifics on PIC code
>implementations? In particular, I'm interested in PIC from gcc in x86
>machines. I need info such as persistency of the PIC register,
>when/where PIC register values are calculated, offset formulas for
>symbols at runtime, etc.


The version of PIC implemented on ELF based systems (such as
GNU/Linux) is documented in two books: System V Application Binary
Interface and System V Application Binary Interface Intel386 Processor
Supplement.


The %ebx register holds the address of the global offset table. It is
normally calculated in the prologue of each function; this makes it
possible to easily call a function in another object via a function
pointer. I don't know what you mean by offset formulas.


>I am currently trying to build some shared libraries for an OS we are
>developing and need to know what sort of register manipulations are
>legal and where. I tried to munge through the source to gcc but that
>was getting me nowhere.


gcc will only give you 1/3 of the story. You must also understand
what the assembler and linker do.


>[A quick look at the code suggests that it uses a procedure lookup table
>and global offset table like the ones that Sun's shared libraries do, and
>that %bx is reserved to hold the address of the PLT. I also note that on
>my BSD/OS 2.1 box, the assembler can't assemble the compiler's output when
>you tell it to generate PIC. -John]


The ELF PIC system was based on the SunOS system. It has the
advantage of being thoroughly documented. I've never seen any
technical documentation on SunOS shared libraries; I implemented it in
the GNU linker by reading the ELF specs and reverse engineering.


I don't know what BSD/OS does.


Ian Taylor
ian@cygnus.com
[Oops, those two SysV books happen to be on a shelf about three feet
from my desk. BSD/OS doesn't use PIC, since their shared library
scheme doesn't use dynamic linking. -John]




--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.