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] |
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.
I have tried to find a target were *label* differences do not work, but it doesn't seem to be easy to come up with an example (you need such a target in the first place, and then do something that causes the difference to remain until link time).
Florian
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |