ifunc attribute in C++

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

 



Does the ifunc attribute work in C++, and if so can somebody please
show me a working example?  I found several examples that work in C,
but none in C++.  For example, the below file works fine in C:

#include <stdio.h>

typedef int foo_t(int);

int foo (int) __attribute__ ((ifunc ("foo_ifunc")));

static int global = 1;

static int
f1 (int x)
{
  return x;
}

static int
f2 (int x)
{
  return x + 1;
}

foo_t *
foo_ifunc (void)
{
  return global == 1 ? f1 : f2;
}

int
main (int argc, char** argv __attribute__((unused)))
{
  printf ("%d\n", foo(argc));
  return (0);
}


But when compiled with g++, it gives the following error:

$ g++ -g -Wall -Wextra -Werror foo.cc -o foo
foo.cc:5:5: error: ‘int foo(int)’ aliased to undefined symbol ‘foo_ifunc’
 int foo (int) __attribute__ ((ifunc ("foo_ifunc")));

-Alan





[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