diff mbox

[1/2v2,RESENT-INLINE] Use libtool instead of ar to create static libraries on Darwin.

Message ID 1462237852-61856-1-git-send-email-chrisfriedt@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Christopher Friedt May 3, 2016, 1:10 a.m. UTC
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.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
---
 rules.mak | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Richard Henderson May 3, 2016, 7:06 a.m. UTC | #1
On 05/02/2016 03:10 PM, Christopher Friedt wrote:
>  %.a:
> +ifdef CONFIG_DARWIN
> +	$(call quiet-command,rm -f $@ && libtool -static -o $@ $^,"  libtool    $(TARGET_DIR)$@")
> +else
>  	$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR    $(TARGET_DIR)$@")
> +endif
>

Does it work to use libtool -static everywhere?


r~
Christopher Friedt May 3, 2016, 1:50 p.m. UTC | #2
On Tue, May 3, 2016 at 3:06 AM, Richard Henderson <rth@twiddle.net> wrote:
> On 05/02/2016 03:10 PM, Christopher Friedt wrote:
>>
>>  %.a:
>> +ifdef CONFIG_DARWIN
>> +       $(call quiet-command,rm -f $@ && libtool -static -o $@ $^,"
>> libtool    $(TARGET_DIR)$@")
>> +else
>>         $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR
>> $(TARGET_DIR)$@")
>> +endif
>>
>
> Does it work to use libtool -static everywhere?

That *would* be nice... yeah, it would be nice if Apple's tools could
work the same as *all* of the other unices out there. Unfortunately,
that's not the case, since at least GNU libtool does *not* accept the
"-static" argument.

To be honest, if it weren't for the man page for libtool on Mac OS X
[1] dating all the way back to Snow Leopard saying that libtool is the
preferred tool on Mac for creating static archives, I'm left wondering
if this is just a massive oversight / bug in Apple's ld64.

[1] http://www.unix.com/man-page/osx/1/libtool/
Peter Maydell May 3, 2016, 2:12 p.m. UTC | #3
On 3 May 2016 at 14:50, Christopher Friedt <chrisfriedt@gmail.com> wrote:
> To be honest, if it weren't for the man page for libtool on Mac OS X
> [1] dating all the way back to Snow Leopard saying that libtool is the
> preferred tool on Mac for creating static archives, I'm left wondering
> if this is just a massive oversight / bug in Apple's ld64.

I think it's definitely a bug -- if "ar" and "ld" don't work
together Apple should remove "ar", not just unhelpfully break it.
We probably need to work around the bug anyway though.

thanks
-- PMM
Christopher Friedt May 4, 2016, 12:07 a.m. UTC | #4
On May 3, 2016 9:50 AM, "Christopher Friedt" <chrisfriedt@gmail.com> wrote:
>
> On Tue, May 3, 2016 at 3:06 AM, Richard Henderson <rth@twiddle.net> wrote:
> > On 05/02/2016 03:10 PM, Christopher Friedt wrote:
> >>
> >>  %.a:
> >> +ifdef CONFIG_DARWIN
> >> +       $(call quiet-command,rm -f $@ && libtool -static -o $@ $^,"
> >> libtool    $(TARGET_DIR)$@")
> >> +else
> >>         $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR
> >> $(TARGET_DIR)$@")
> >> +endif
> >>
> >
> > Does it work to use libtool -static everywhere?

One possibility for future-proofing the link stage that applies to most
(all?) platforms that Qemu runs on would be to switch to libtool for all
arch's and just adjust the "libtool flags" as necessary.

Would require checking for libtool.

Fallback to ar?

©

Sent from my Android
Peter Maydell May 4, 2016, 9:03 a.m. UTC | #5
On 4 May 2016 at 01:07, Christopher Friedt <chrisfriedt@gmail.com> wrote:
>
> On May 3, 2016 9:50 AM, "Christopher Friedt" <chrisfriedt@gmail.com> wrote:
>>
>> On Tue, May 3, 2016 at 3:06 AM, Richard Henderson <rth@twiddle.net> wrote:
>> > On 05/02/2016 03:10 PM, Christopher Friedt wrote:
>> >>
>> >>  %.a:
>> >> +ifdef CONFIG_DARWIN
>> >> +       $(call quiet-command,rm -f $@ && libtool -static -o $@ $^,"
>> >> libtool    $(TARGET_DIR)$@")
>> >> +else
>> >>         $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR
>> >> $(TARGET_DIR)$@")
>> >> +endif
>> >>
>> >
>> > Does it work to use libtool -static everywhere?
>
> One possibility for future-proofing the link stage that applies to most
> (all?) platforms that Qemu runs on would be to switch to libtool for all
> arch's and just adjust the "libtool flags" as necessary.
>
> Would require checking for libtool.

This is more complicated than we need. OSX "libtool" and GNU
"libtool" are really completely different things. We don't
(these days) do anything that we need GNU libtool for, so
there's no need to depend on it or use it optionally -- we should
just use "ar". If we need to special case the "program for creating
static libraries" for OSX that's annoying but we can do that.

thanks
-- PMM
Michael Tokarev Sept. 14, 2016, 7:30 a.m. UTC | #6
03.05.2016 04:10, Christopher Friedt wrote:
> 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.
>
> Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
> ---
>  rules.mak | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/rules.mak b/rules.mak
> index d1ff311..44421af 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -105,7 +105,11 @@ modules:
>  	$(call LINK,$(filter %.o %.a %.mo, $^))
>
>  %.a:
> +ifdef CONFIG_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))

Hmm.  Is this patch still relevant?  Apparently I missed it back then.

Thanks,

/mjt
Peter Maydell Sept. 20, 2016, 5:58 p.m. UTC | #7
On 14 September 2016 at 08:30, Michael Tokarev <mjt@tls.msk.ru> wrote:
> 03.05.2016 04:10, Christopher Friedt wrote:
>>
>> 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.
>>
>> Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
>> ---
>>  rules.mak | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/rules.mak b/rules.mak
>> index d1ff311..44421af 100644
>> --- a/rules.mak
>> +++ b/rules.mak
>> @@ -105,7 +105,11 @@ modules:
>>         $(call LINK,$(filter %.o %.a %.mo, $^))
>>
>>  %.a:
>> +ifdef CONFIG_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))
>
>
> Hmm.  Is this patch still relevant?  Apparently I missed it back then.

I don't have El Capitan, but I can confirm that it doesn't break
the build on Yosemite, so I guess we should have it.

I'd like to know the error message the linker produces first,
though (and we should put that in the commit message).

The progress string argument to quiet-command is slightly wrong:
we capitalize the shortname of the command being run, so it
ought to look like "  LIBTOOL $(TARGET_DIR)$@" so it lines up
and looks nice with the other output.

thanks
-- PMM
diff mbox

Patch

diff --git a/rules.mak b/rules.mak
index d1ff311..44421af 100644
--- a/rules.mak
+++ b/rules.mak
@@ -105,7 +105,11 @@  modules:
 	$(call LINK,$(filter %.o %.a %.mo, $^))
 
 %.a:
+ifdef CONFIG_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))