PIC code generation in gcc/binutils
Quoted 7 lines
I was hoping to write up a preliminary ABI specification based on the 64-bit ELF implementation on HP/UX, so I've been trying to find detailed specifications on how the ELF64 ABI actually works but so far have not come up with much information from HP's documentation. The 64-bit runtime architecture document has some useful information, but I suspect I'll have to look at the actual implementation to nail down the details.
As the HP-UX Runtime Architect, I'll be happy to answer any questions you may have on the runtime architecture. I realize that the 64-bit runtime architecture is weak in the dynamic loading area, but I'll try to make up for that by answering questions in this forum.
Quoted 9 lines
One thing I am sure of is that if we try to follow the HP/UX ELF64 specification for dynamic linking on 32-bit Linux we are going to be substantially different from other Linux/ELF platforms. In particular, the handling of inter-module calls and function pointers, and the management of the GP, are done in a totally different way from all the other platforms I've encountered (i386, m68k, alpha). (i.e. inter-module calls are handled by another set of stubs, and GP management is done by the caller via the function descriptors, rather than by the callee with GPDISP and similar relocations)
The model used for PA-RISC is a a consequence of the segmented architecture, where the text and data segments are not adjacent. Since the PA-RISC sharing model is based on global virtual addresses, the text and data segment are loaded in separate quadrants of the address space so that the text can be shared and the data can be process-private. As a result, a procedure cannot materialize its own gp, since there is no fixed pc-relative offset between the text and data. This means that the caller must materialize the gp prior to the call, or as part of the call.
By the way, this model is also being used for IA-64. You may be able to leverage some of the work being done for ld.so on that platform.
It shouldn't really complicate the dynamic loader that much, though. A function pointer is still essentially a function pointer, and behaves the same as in the other model, even though it points to a 128-bit descriptor rather than an actual function. The linker needs to allocate a GOT entry for each import stub (aka "proxy") it creates, and attach a dynamic FPTR relocation to that GOT entry. The dynamic loader needs to create the function descriptor when it processes the FPTR relocation.
Lazy binding requires a bit of cleverness. We do it by dynamically creating lazy-binding stubs that load a module id and a PLT index into registers, then branch to a common bind-on-reference routine.
Cary Coutant
HP-UX Runtime Architect
Quoted 3 lines · Cary Coutant
Lazy binding requires a bit of cleverness. We do it by dynamically creating lazy-binding stubs that load a module id and a PLT index into registers, then branch to a common bind-on-reference routine.
We will have our own lazy-binding mechanisms (close to Sun's approach). So don't plan to bring this in. You can live without it for now.
Signature · 3 lines
---------------. ,-. 1325 Chesapeake Terrace Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com `------------------------
Quoted 2 lines · Cary Coutant
The model used for PA-RISC is a a consequence of the segmented architecture, where the text and data segments are not adjacent.
For what it's worth our ELF32 runtime conventions do not use segmentation at all. That is, in user space, %sr0 and %sr4 through %sr7 are all set to the same space identifier.
This is in keeping with accepted practice on other 32-bit Linux platforms where segmentation is used only to provide separate 4G address spaces for the kernel and userland.
Quoted 4 lines
As a result, a procedure cannot materialize its own gp, since there is no fixed pc-relative offset between the text and data. This means that the caller must materialize the gp prior to the call, or as part of the call.
I can see some advantages in this even with a non-segmented runtime architecture - theoretically, having the GP be managed by the caller rather than the callee should make intramodule calls in position-independent code more efficient. (I think so at least)
One thing I have not figured out is how the GP is "bootstrapped" in the startup code for the dynamic linker itself - how does ELF64 on HP/UX deal with this problem?
Quoted 2 lines
By the way, this model is also being used for IA-64. You may be able to leverage some of the work being done for ld.so on that platform.
Thanks for the tip... as it turns out, the author of the dynamic linker support for GNU libc on IA-64 sits two cubes away from me, so that should be quite helpful indeed :-)
Quoted 3 lines
Lazy binding requires a bit of cleverness. We do it by dynamically creating lazy-binding stubs that load a module id and a PLT index into registers, then branch to a common bind-on-reference routine.
For the moment I am not going to worry about lazy binding at all, though it is certainly a requirement in the future.
Signature · 2 lines
[email protected], http://www.linuxcare.com/ Linuxcare. Support for the revolution.
Quoted 8 lines · David Huggins-Daines
Quoted 2 lines · Cary Coutant
The model used for PA-RISC is a a consequence of the segmented architecture, where the text and data segments are not adjacent.
For what it's worth our ELF32 runtime conventions do not use segmentation at all. That is, in user space, %sr0 and %sr4 through %sr7 are all set to the same space identifier.
Hmm, I haven't been making this assumption in the elf32-hppa binutils shared lib support. If userland uses the same space id, then import stubs can be simplified quite a bit, and there's no need for export stubs.
Quoted 3 lines
This is in keeping with accepted practice on other 32-bit Linux platforms where segmentation is used only to provide separate 4G address spaces for the kernel and userland.
On parisc, doesn't a single space id limit your address space to 1G?
Alan Modra
Signature · 1 line
Linuxcare. Support for the Revolution.
Quoted 1 line · Alan Modra
On parisc, doesn't a single space id limit your address space to 1G?
that was what I thought too, but it turns out that the quarter of the space which is addressed is the same as the top 2 bits of the data register. ie, if we were using 4 distinct spaces, we would see the following usage pattern:
xx......
..xx....
....xx..
......xx
so using just one space register for the entire process doesn't affect us at all.
http://devresource.hp.com/devresource/Docs/Refs/PA1_1/acd-17.html
is an authoritive source for this information:
"Only one fourth of the space is directly addressable by the base register with short pointers and corresponds to the quadrant selected by the upper two bits."
Signature · 1 line
Revolutions do not require corporate support.
Quoted 1 line · Alan Modra
On parisc, doesn't a single space id limit your address space to 1G?
that was what I thought too, but it turns out that the quarter of the space which is addressed is the same as the top 2 bits of the data register. ie, if we were using 4 distinct spaces, we would see the following usage pattern:
xx......
..xx....
....xx..
......xx
so using just one space register for the entire process doesn't affect us at all.
http://devresource.hp.com/devresource/Docs/Refs/PA1_1/acd-17.html
is an authoritive source for this information:
"Only one fourth of the space is directly addressable by the base register with short pointers and corresponds to the quadrant selected by the upper two bits."
Signature · 1 line
Revolutions do not require corporate support.