short pointers (32 bit) in 64 bit apps

phi benard phi.benard@gmail.com
Wed May 19 21:29:00 GMT 2010


On a 64bits system, how an ILP64 (or LP64) compiled application can be
sure that returned addr from the operating system can be squeezed?

Are you assuming a flat virtual address space for a given process, and
al your memory request (sbrk/malloc/mmap) will fit into 4Gb fir a
while before exceeding this limit? because if so, I think it is a
wrong start many architecture out there are segmented, i.e there are
some bits in the MSB of a pointer that define what so called
space/region/segment name-it, so on some architecture doing an mmap()
can return various kind of address like 0x100012345678 for data
segment 0x200012345678 for a shared memory segment etc..., squeezing
from 64 bits to 32 bits mean keeping the MSB, since from architecture
to architecture this number of bits vary the remaining bits for
'offset' must be assumed not to be bigger than the smallest possible
offset, for instance there are archi with 2 bits space registers
index, and architecture with 3 bits space register, so assuming the
biggest (3 bits), this mean that the offset part of  a pointer can be
no bigger that 32-3 29bits. So since this is unknown from start, it is
unsafe to assume that any program can be coded with shortened pointer
and think they willl be portable, it could be only a special case for
a given flat architecture.

On such segmented architecture, even an mmap() with MAP_SHARED32 in an
LP64 process return and addr with segment bit setup, so a 32bit app
and a 64 bit app on this OS can share the same area in memory, the
size of the shared memory segment is then by nature smaller than 4Gb,
it is generally up to the offset size 2^(32-2) or 2^(32-3) etc...

In short, this idea is a false good idea I guess :)

Furthermore, memory is ship nowaday, and the backing store even
cheaper. Who would take the risk to implement something in the
compiler that is by nature non portable and would requier much more
than just 'short' as a keyword but would require a short pointer to be
a struct of 2 member some bits for teh segment selection, and the rest
for offset selection, and possibly way to setup region register (that
many os don't allow) etc....

I guess you better stay away from this, are code indeed the
compress/decompress of your data structure as needed.

Cheers,
Phi



More information about the Gcc-help mailing list