On Fri, Aug 04, 2017 at 06:13:42PM +0100, Daniel P. Berrange wrote: > Currently any mockable functions are marked with attributes > noinline, noclone and weak. This prevents the compiler from > optimizing away the impl of these functions. > > It has an unfortunate side effect with the libtool convenience > libraries, if executables directly link to them. For example > virlockd, virlogd both link to libvirt_util.la When this is > done, the linker does not consider weak symbols as being > undefined, so it never copies them into the final executable. > > In this new approach, we stop annotating the headers entirely. > Instead we create a weak function alias in the source. > > int fooImpl(void) { > ..the real code.. > } > > int foo(void) __attribute__((noinline, noclone, weak, alias("fooImpl")) > > If any functions in the same file call "foo", this prevents the > optimizer from inlining any part of fooImpl. When linking to the > libtool convenience static library, we also get all the symbols > present. Finally the test suite can just directly define a > 'foo' function in its source, removing the need to use LD_PRELOAD > (though removal of LD_PRELOADS is left for a future patch). > > Signed-off-by: Daniel P. Berrange <berra...@redhat.com>
Self-NACK. This breaks on OS-X because the linker doesn't support 'alias' or 'weak'. For that matter it doesn't support LD_PRELOAD either, so we need to avoid wrapping the functions on this platform. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list