Resolve link errors on Mac OS X
cover Resolve link errors on Mac OS X
Hi list,
I recently tried to build Qemu on Mac and ran into a couple of trivial issues that I've provided patches for. I suppose that normally people just use 'brew install qemu', but there is really no reason that it can't be built from source, particularly for those modifying Qemu regularly.
In any case, the first change moves to using 'libtool -static' to create libraries on Mac OS X. If one attempts to use ar and ranlib, then the final link will fail with error messages resembling the following:
ld: warning: ignoring file libqemuutil.a, file was built for archive which is not the architecture being linked (x86_64): libqemuutil.a Undefined symbols for architecture x86_64:
...
Notice ld (Apple's ld64) presumes the static library is a relocatable with architecture 'archive' rather than x86_64, in this case.
A similar fix is required for dtc - again quite trivial, but I can provide that if necessary.
The second patch removes the preprocessor conditional around the function event_notifier_init_fd() in util/event_notifier-posix.c so that the link does not fail on systems where CONFIG_POSIX is defined but CONFIG_EVENTFD is not (such as under Mac OS X).
There is more information in each of the commits that follows.
Please feel free to comment.
Cheers,
C
Christopher Friedt (2):
Use libtool instead of ar to create static libraries on Darwin. Remove unnecessary CONFIG_EVENTFD preprocessor conditional to satisfy
link
rules.mak | 4 ++++ util/event_notifier-posix.c | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.6.4 (Apple Git-63)
PATCH 1/2 Use libtool instead of ar to create static libraries on Darwin.
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
One of those reasons is that Apple's ld (at least ld64) does not properly process archive files created with ar (even Apple's ar).
After some RTFM'ing, I came upon this tidbit, which is unfortunate. Luckily, autotools packages are not broken.
"Libtool with -static is intended to replace ar(5) and ranlib."
http://www.manpages.info/macosx/libtool.1.html
In any case, this change takes Apple's recommendations into account and allows Qemu to build on Mac OS X El Capitan.
--- rules.mak | 4 ++++ 1 file changed, 4 insertions(+)
rules.mak +4 -0
@@ -105,7 +105,11 @@ modules: $(call LINK,$(filter %.o %.a %.mo, $^)) %.a: +ifeq ($(shell uname),Darwin) + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^," libtool $(TARGET_DIR)$@") +else $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") +endif quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Re: [Qemu-devel] [PATCH 1/2] Use libtool instead of ar to create static libraries on Darwin.
Quoted 3 lines · Christopher Friedt
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
I guess this is a new-in-ElCapitan thing? I run Yosemite, which is fine.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 1/2] Use libtool instead of ar to create static libraries on Darwin.
Quoted 7 lines · Peter Maydell
Quoted 3 lines · Christopher Friedt
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
I guess this is a new-in-ElCapitan thing? I run Yosemite, which is fine.
I think you're partially correct, although the information on the man page dates back to at least Snow Leopard (10.6.2) [1], so Apple has preferred the libtool method for a very long time.
It's possible that it only finally broke in El Capitan.
Re: [Qemu-devel] [PATCH 1/2] Use libtool instead of ar to create static libraries on Darwin.
In reply to Christopher FriedtCc'ing Peter Maydell, who must have better ideas than me on building on Mac.
Quoted 23 lines · Christopher Friedt
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
One of those reasons is that Apple's ld (at least ld64) does not properly process archive files created with ar (even Apple's ar).
After some RTFM'ing, I came upon this tidbit, which is unfortunate. Luckily, autotools packages are not broken.
"Libtool with -static is intended to replace ar(5) and ranlib."
http://www.manpages.info/macosx/libtool.1.htmlIn any case, this change takes Apple's recommendations into account and allows Qemu to build on Mac OS X El Capitan.
Signed-off-by Christopher Friedt <[email protected]>--- rules.mak | 4 ++++ 1 file changed, 4 insertions(+)rules.mak +0
-0
rules.mak modules: · line 108
Quoted 4 lines
rules.mak +1
-0@@ -105,7 +105,11 @@ modules: $(call LINK,$(filter %.o %.a %.mo, $^)) %.a: +ifeq ($(shell uname),Darwin)
I think you can use "ifdef CONFIG_DARWIN" here.
rules.mak modules: · line 109
Quoted 1 line
rules.mak +1
-0+ $(call quiet-command,rm -f $@ && libtool -static -o $@ $^," libtool $(TARGET_DIR)$@")
Is libtool always available on Mac OS X? If not, we may need to add the detection to ./configure.
Fam
Quoted 6 lines
rules.mak +2
-0+else $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") +endif quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Re: [Qemu-devel] [PATCH 1/2] Use libtool instead of ar to create static libraries on Darwin.
Quoted 28 lines · Fam Zheng
Cc'ing Peter Maydell, who must have better ideas than me on building on Mac.
Quoted 25 lines · Christopher Friedt
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
One of those reasons is that Apple's ld (at least ld64) does not properly process archive files created with ar (even Apple's ar).
After some RTFM'ing, I came upon this tidbit, which is unfortunate. Luckily, autotools packages are not broken.
"Libtool with -static is intended to replace ar(5) and ranlib."
http://www.manpages.info/macosx/libtool.1.htmlIn any case, this change takes Apple's recommendations into account and allows Qemu to build on Mac OS X El Capitan.
Signed-off-by Christopher Friedt <[email protected]>--- rules.mak | 4 ++++ 1 file changed, 4 insertions(+)rules.mak +0
-0@@ -105,7 +105,11 @@ modules: $(call LINK,$(filter %.o %.a %.mo, $^))
Quoted 4 lines
rules.mak modules: · line 108
Quoted 2 lines
rules.mak +1
-0%.a: +ifeq ($(shell uname),Darwin)I think you can use "ifdef
CONFIG_DARWIN" here.
Good suggestion. I missed that entirely.
Quoted 4 lines
rules.mak modules: · line 109
Quoted 1 line
rules.mak +1
-0+ $(call quiet-command,rm -f $@ && libtool -static -o $@ $^," libtool $(TARGET_DIR)$@")Is libtool always available on Mac OS X? If not, we may need to add the detection to ./configure.
Apple's libtool should be installed with their command line tools, at least as far back as Snow Leopard.
Re: [Qemu-devel] [PATCH 1/2] Use libtool instead of ar to create static libraries on Darwin.
In reply to Christopher FriedtHmm. We removed libtool support just two moths ago... :)
/mjt
Re: [Qemu-devel] [PATCH 1/2] Use libtool instead of ar to create static libraries on Darwin.
Quoted 1 line · Michael Tokarev
Hmm. We removed libtool support just two moths ago... :)
That was GNU libtool, which is a completely different thing from OSX libtool. They just have an unhelpful name clash.
thanks
-- PMM
PATCH 2/2 Remove unnecessary CONFIG_EVENTFD preprocessor conditional to satisfy link
In reply to Christopher FriedtThe file ivshmem.c unconditionally references event_notifier_init_fd() in util/event_notifier-posix.c, even if CONFIG_EVENTFD is not defined. On platforms where CONFIG_POSIX is defined, but CONFIG_EVENTFD is not defined, that results in an undefined symbol referenced from ivshmem.c and the link fails. That applies to Mac OS X, but possibly other BSD-based distros.
Note: there is nothing specific to eventfd inside and event_notifier_init() also fails unconditionally if CONFIG_EVENTFD is not defined.
--- util/event_notifier-posix.c | 2 -- 1 file changed, 2 deletions(-)
util/event_notifier-posix.c +0 -2
@@ -21,7 +21,6 @@#include <sys/eventfd.h> #endif -#ifdef CONFIG_EVENTFD /* * Initialize @e with existing file descriptor @fd. * @fd must be a genuine eventfd object, emulation with pipe won't do.
@@ -31,7 +30,6 @@ void event_notifier_init_fd(EventNotifier *e, int fd) e->rfd = fd; e->wfd = fd; } -#endif int event_notifier_init (EventNotifier *e,int active) {
Re: [Qemu-devel] [PATCH 2/2] Remove unnecessary CONFIG_EVENTFD preprocessor conditional to satisfy link
[ccing somebody else who ran into this, since I've figured out why.]
Quoted 2 lines · Christopher Friedt
The file
ivshmem.cunconditionally referencesevent_notifier_init_fd()inutil/event_notifier-posix.c, even ifCONFIG_EVENTFDis not defined.
Yes, but ivshmem.c is only built if CONFIG_IVSHMEM, and CONFIG_IVSHMEM is set (in default-configs/pci.mak) to CONFIG_EVENTFD. So if CONFIG_EVENTFD is not defined then we should never build ivshmem.o.
The problem here is that you've run into a bug in QEMU's makefiles, where a change in an included .mak file in default-configs fails to cause the config-devices.mak file to be rebuilt. In commit 330b583 we changed pci.mak so that CONFIG_IVSHMEM is set to CONFIG_EVENTFD rather than CONFIG_POSIX, so if your config-devices.mak predates that commit then it will have incorrectly not been recreated and so your build will still try to build ivshmem.c.
You can check whether this is true by looking at (for instance) x86_64-softmmu/config-devices.mak in your build
tree: if it has a line "CONFIG_IVSHMEM=$(CONFIG_POSIX)" in it then it's the out of date version.
You should be able to fix this by deleting */config-devices.mak from your build tree (or by blowing away the build tree entirely and recreating it.) Then try rebuilding -- ivshmem.c should not be compiled.
We really must track down this dependency bug, it is very confusing when it bites people.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 2/2] Remove unnecessary CONFIG_EVENTFD preprocessor conditional to satisfy link
Quoted 11 lines · Peter Maydell
[ccing somebody else who ran into this, since I've figured out why.]
Quoted 2 lines · Christopher Friedt
The file
ivshmem.cunconditionally referencesevent_notifier_init_fd()inutil/event_notifier-posix.c, even ifCONFIG_EVENTFDis not defined.Yes, but
ivshmem.cis only built ifCONFIG_IVSHMEM, andCONFIG_IVSHMEMis set (in default-configs/pci.mak) toCONFIG_EVENTFD. So ifCONFIG_EVENTFDis not defined then we should never build ivshmem.o.The problem here is that you've run into a bug in QEMU's makefiles,
That would explain things.
Quoted 11 lines
where a change in an included .mak file in default-configs fails to cause the config-devices.mak file to be rebuilt. In commit 330b583 we changed pci.mak so that
CONFIG_IVSHMEMis set toCONFIG_EVENTFDrather thanCONFIG_POSIX, so if your config-devices.mak predates that commit then it will have incorrectly not been recreated and so your build will still try to buildivshmem.c.You can check whether this is true by looking at (for instance) x86_64-softmmu/config-devices.mak in your build
tree: if it has a line "CONFIG_IVSHMEM=$(CONFIG_POSIX)" in it then it's the out of date version.
$ grep "CONFIG_IVSHMEM" x86_64-softmmu/config-devices.mak CONFIG_IVSHMEM=$(CONFIG_EVENTFD)
I have been re-configuring on every build, just to eliminate that potential error source.
Quoted 4 lines
You should be able to fix this by deleting */config-devices.mak from your build tree (or by blowing away the build tree entirely and recreating it.) Then try rebuilding --
ivshmem.cshould not be compiled.
I'll give that a go anyway.
Re: [Qemu-devel] [PATCH 2/2] Remove unnecessary CONFIG_EVENTFD preprocessor conditional to satisfy link
Quoted 22 lines · Christopher Friedt
Quoted 11 lines · Peter Maydell
[ccing somebody else who ran into this, since I've figured out why.]
Quoted 2 lines · Christopher Friedt
The file
ivshmem.cunconditionally referencesevent_notifier_init_fd()inutil/event_notifier-posix.c, even ifCONFIG_EVENTFDis not defined.Yes, but
ivshmem.cis only built ifCONFIG_IVSHMEM, andCONFIG_IVSHMEMis set (in default-configs/pci.mak) toCONFIG_EVENTFD. So ifCONFIG_EVENTFDis not defined then we should never build ivshmem.o.The problem here is that you've run into a bug in QEMU's makefiles,
That would explain things.
Quoted 7 lines
where a change in an included .mak file in default-configs fails to cause the config-devices.mak file to be rebuilt. In commit 330b583 we changed pci.mak so that
CONFIG_IVSHMEMis set toCONFIG_EVENTFDrather thanCONFIG_POSIX, so if your config-devices.mak predates that commit then it will have incorrectly not been recreated and so your build will still try to buildivshmem.c.
Quoted 7 lines
Quoted 4 lines
You can check whether this is true by looking at (for instance) x86_64-softmmu/config-devices.mak in your build
tree: if it has a line "CONFIG_IVSHMEM=$(CONFIG_POSIX)" in it then it's the out of date version.$ grep "CONFIG_IVSHMEM" x86_64-softmmu/config-devices.mak CONFIG_IVSHMEM=$(CONFIG_EVENTFD)
Hmm. (Is it set the same for every config-devices.mak for every target you're trying to build?)
Next things to check: is CONFIG_EVENTFD definitely not set in config-host.mak (it shouldn't be)? hw/misc/Makefile.objs ought to say "obj-$(CONFIG_IVSHMEM) += ivshmem.o", and that should mean that we don't try to build it...
thanks
-- PMM
Re: [Qemu-devel] [PATCH 2/2] Remove unnecessary CONFIG_EVENTFD preprocessor conditional to satisfy link
Quoted 12 lines · Peter Maydell
Quoted 11 lines · Christopher Friedt
Quoted 10 lines · Peter Maydell
[ccing somebody else who ran into this, since I've figured out why.]
Quoted 2 lines · Christopher Friedt
The file
ivshmem.cunconditionally referencesevent_notifier_init_fd()inutil/event_notifier-posix.c, even ifCONFIG_EVENTFDis not defined.Yes, but
ivshmem.cis only built ifCONFIG_IVSHMEM, andCONFIG_IVSHMEMis set (in default-configs/pci.mak) toCONFIG_EVENTFD. So ifCONFIG_EVENTFDis not defined then we should never build ivshmem.o.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
The problem here is that you've run into a bug in QEMU's makefiles,
That would explain things.
Hmm. (Is it set the same for every config-devices.mak for every target you're trying to build?)
Ack - too late! I manually removed all of the *-softmmu/ directories after doing a make clean, because they were still hanging around. Rebuilding worked fine without PATCH 2/2.
Thanks!
Re: [Qemu-devel] [PATCH 2/2] Remove unnecessary CONFIG_EVENTFD preprocessor conditional to satisfy link
Quoted 3 lines · Christopher Friedt
Ack - too late! I manually removed all of the *-softmmu/ directories after doing a make clean, because they were still hanging around. Rebuilding worked fine without PATCH 2/2.
Oh well. If blowing away the build dirs fixed it then it seems pretty likely that the makefile bug is what you were running into.
thanks
-- PMM