

GCC Function Multiversioning - unwind
https://gcc.gnu.org/wiki/FunctionMultiVersioning

======
wazari972
I wanted to give it a try, but if fails without considering the target
attribute ...

> gcc test.c -g > test.c:9:5: error: redefinition of ‘foo’ > int foo () > gcc
> version 4.9.2 (GCC) (archlinux)

~~~
nkurz
It's not entirely clear, but I think this is a C++ only feature that is only
available when using the GCC C++ front end (g++). The linked document includes
the ambiguous "Support is only available in C++ for i386 targets", but other
sources (such as the GCC 4.9.2 documentation) have clarified this to "With the
GNU C++ front end, for target i386, you may specify multiple versions of a
function".

[https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-
Multiv...](https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-
Multiversioning.html)

~~~
wazari972
indeed, my bad! to my defense, the code looks a lot like C code ;-)

------
opk
Looks like gcc is also generating a dispatcher function. This should really be
the runtime linker's job. Solaris has been able to do this for as long as I
can remember.

~~~
glandium
One problem with doing it in the runtime linker is that the implementation
needs to get it right to allow programs to run with a runtime linker that
doesn't support it. And that would not work on e.g. Windows.

