Re: illegal instruction - create compile variants ?

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

 



On Mon, 02 May 2011 17:24:53 +0200, Kevin Kofler wrote:
> Jan Kratochvil wrote:
> > There is the STT_GNU_IFUNC feature implemented for it - the indirect is
> > handled by linker without an additional indirect overhead if applied for a
> > shared library function. For apps it works in a similar way as normal
> > indirect.
> 
> Are there any caveats (initialization order or so) when using this feature? 

Yes, a bit.  STT_GNU_IFUNC relocations are sorted as last in the library to be
relocated.  But still they are called before any static initializers (static
constructors), the sample code below outputs:
	resolver
	constructor
	main
	func1
	destructor


> E.g. would one get away with calling something like
> http://api.kde.org/4.0-api/kdelibs-apidocs/solid/html/tutorial3.html (i.e. 
> Solid::Processor::instructionSets) in the ifunc or would trying to call such 
> C++ classes lead to errors or unpredictable behavior?

Unless there are static initializers it should work.


> And I presume this is available on ELF glibc targets only, isn't it?

It is GNU/Linux feature, unrelated to glibc (glibc is just one of its users).

STT_GNU_IFUNC is ELF feature and it is in STT_LOOS..STT_HIOS, therefore it
needs ELFOSABI_LINUX.


Thanks,
Jan


------------------------------------------------------------------------------

#include <stdio.h>
#include <time.h>

class C
{
public:
  C() { puts ("constructor"); }
  ~C() { puts ("destructor"); }
} c;

static void
func1 (void)
{
  puts ("func1");
}

static void
func2 (void)
{
  puts ("func2");
}

typedef void (*func_t) (void);

asm (".type _Z9gnu_ifuncv, @gnu_indirect_function");

func_t
gnu_ifunc (void)
{
  puts ("resolver");
  return time (NULL) & 1 ? func1 : func2;
}

int
main (void)
{
  puts ("main");
  gnu_ifunc ();
  return 0;
}
-- 
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/devel


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux