On Wed, Aug 26, 2015 at 09:25:39AM -0600, Eric Blake wrote: > On 08/26/2015 09:05 AM, Daniel P. Berrange wrote: > > The libqemuutil.a archive may contain QOM objects which are > > only indirectly referenced via __attribute__((constructor)) > > annotations. Despite the constructor annotation the linker > > will think these objects are unused by the executable and > > so drop them when linking, to the system emulator. As a > > result the objects in question will be missing from QOM. > > > > Using the -Wl,--whole-archive flag instructs the linker > > to pull in everything in libqemuutil.a regardless of > > whether it thinks it is used or not. > > > > Signed-off-by: Daniel P. Berrange <berra...@redhat.com> > > --- > > Makefile.target | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/Makefile.target b/Makefile.target > > index 3e7aafd..5b08f0f 100644 > > --- a/Makefile.target > > +++ b/Makefile.target > > @@ -180,8 +180,13 @@ all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) > > $(QEMU_PROG_BUILD): config-devices.mak > > > > # build either PROG or PROGW > > +# We must use --whole-archive with libqemuutil.a otherwise the > > +# linker will drop any objects from the archive which are only > > +# indirectly referenced via __attribute__(constructor) annotations > > $(QEMU_PROG_BUILD): $(all-obj-y) ../libqemuutil.a ../libqemustub.a > > - $(call LINK, $(filter-out %.mak, $^)) > > + $(call LINK, $(filter-out %.mak, $(sort $(all-obj-y)))) \ > > Why the added $(sort)? Should that be a separate patch?
$(all-obj-y) has some .o's listed multiple times. $^ removes duplicates, avoiding this problem, but if we use $(all-obj-y) we must now remove duplicates ourselves. $(sort) removes duplicates and AFAICT, there's no built-in make function that can remove duplicates without sorting. > > > + -Wl,--whole-archive ../libqemuutil.a -Wl,--no-whole-archive \ > > + ../libqemustub.a > > Otherwise makes sense to me. > Reviewed-by: Eric Blake <ebl...@redhat.com> Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|