Relocation avoidance for function pointers

Florian Weimer fweimer@redhat.com
Fri Oct 7 19:28:00 GMT 2016


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.

Florian



More information about the Gcc-help mailing list