Relocation avoidance for function pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Here's what I've got so far:

int f (void);

static int
g (void)
{
  static const int label_offset = &&a - &&b;
 a:
  f ();
 b:
  return label_offset;
}

static int
h (void)
{
  static const long function_offset = &f - &g;
  return function_offset;
}

int
g_wrapper (void)
{
  return g ();
}

int
h_wrapper (void)
{
  return h ();
}


Thanks,
Florian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux