This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Relocation avoidance for function pointers


On 11/04/2016 08:53 AM, Florian Weimer wrote:
On 10/07/2016 09:37 PM, Martin Sebor wrote:
On 10/07/2016 01:28 PM, Florian Weimer wrote:
On 10/07/2016 08:20 PM, Martin Sebor wrote:
On 10/07/2016 09:51 AM, Florian Weimer wrote:
It is possible to compute the difference between two labels and store
the result in a variable.  For PIC code, this can be used to avoid
relocations in jump tables.

I try to do something similar for function pointers.  (Function
pointer
arithmetic is a GCC extension.)  However, GCC rejects that with
“error:
initializer element is not constant”.  Is there any way around this?
The
required relocation should be the same (for static functions anyway).

I can't think of a workaround.  There have been a number of bugs
and enhancement requests to have GCC treat more expressions as
integer or address constant.  Clang users especially expect some
of the basic cases accepted there to work in GCC as well.
A couple of the recent requests I remember are 69960 and 71713.
I don't think they cover your case so opening a new request for
it might be helpful.

Thanks.  I found <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38295>
and reopened it.

I forgot about this one.  Since labels are local to function they're
not subject to the same reordering that functions can be subject to.
Do you not see a potential problem with that or with the relaxation
Andrew mentions?

Quite a few targets support symbol differences in relocations, as long
as they are contained within the same module.  So even if some
relaxation is going on, function pointer differences would still work.
Really? When I looked at this many years ago, none did. Hacking it for the PA (which had proper reloc support for difference of symbols) was painful.

Essentially the only time we could reliably support this was if the result was an assembly-time constant. So the two symbols had to be in same section and if they were text symbols, the target coulnd't support relaxation.

jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]