because that is what the language standard says.

In general, the difference between two global pointers is something
known only to the linker -- too late to evaluate as constant
expression.
In the particular case of two static functions or two static global
pointers, it is possible for the compiler to compute it. Isn't it? I
think that the linker will reorder the sections, but not the functions
inside a section.

The reason why I want to do this is to avoid relocations when a dso is
loaded. Using the difference of two pointer I could build a constant
table and add one of the pointers at runtime.

Do you think that a GCC extension to allow the computation of the
difference of two pointers in the same section is a good thing? Do you
think that it is hard to implement? This extension would probally be
broken by the LTO work, since then only the linker would know the size
and addresses of the functions.

Maybe the best solution is to add two GCC buildtins. Something like
intptr_t  __builtin_obj_offset(intptr_t)
intptr_t  __builtin_obj_addr(intptr_t)

The first one would (in compile time) return the offset of a given
addres from an arbitrary point in the object file. This would need to
be supported in the assembler and linker.

The second one would (in run time) add the arbitrary point to produce
once more a valid pointer.

This extension can also be implemented with LTO.

-- Gaby

Thanks for the comments,
Rafael

Reply via email to