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. Martin