Patchwork BR2_PREFER_STATIC_LIB and LDFLAGS+= -static

login
register
mail settings
Submitter ANDY KENNEDY
Date Nov. 5, 2012, 4:55 p.m.
Message ID <F9C551623D2CBB4C9488801D14F864C628A986@ex-mb1.corp.adtran.com>
Download mbox | patch
Permalink /patch/197224/
State Accepted
Headers show

Comments

ANDY KENNEDY - Nov. 5, 2012, 4:55 p.m.
The following changes LDFLAGS from += -static to += --static if building
with BR2_PREFER_STATIC_LIB so that various components actually build
statically.

Signed-off-by: Andy Kennedy <andy.kennedy@adtran.com>
---
Arnout Vandecappelle - Nov. 5, 2012, 11:35 p.m.
On 11/05/12 17:55, ANDY KENNEDY wrote:
> The following changes LDFLAGS from += -static to += --static if building
> with BR2_PREFER_STATIC_LIB so that various components actually build
> statically.
>
> Signed-off-by: Andy Kennedy<andy.kennedy@adtran.com>

  Although I'm OK with this patch, I have been unable to reproduce the problem
and I'd like to know why it is going wrong with -static.  Can you post a
defconfig that I can rebuild and that exposes the problem?

  Note: a few autobuilders with BR2_PREFER_STATIC_LIB enabled could be nice -
or maybe not, because many packages _will_break.

  Regards,
  Arnout

> ---
> diff -Naur a/package/Makefile.in b/package/Makefile.in
> --- a/package/Makefile.in       2012-08-31 03:49:41.000000000 -0500
> +++ b/package/Makefile.in       2012-11-05 10:45:45.000000000 -0600
> @@ -299,7 +299,7 @@
>
>   ifeq ($(BR2_PREFER_STATIC_LIB),y)
>   SHARED_STATIC_LIBS_OPTS=--enable-static --disable-shared
> -TARGET_LDFLAGS += -static
> +TARGET_LDFLAGS += --static
>   else
>   SHARED_STATIC_LIBS_OPTS=--enable-static --enable-shared
>   endif
>
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
>
Thomas Petazzoni - Nov. 6, 2012, 7:14 a.m.
On Tue, 06 Nov 2012 00:35:51 +0100, Arnout Vandecappelle wrote:

>   Although I'm OK with this patch, I have been unable to reproduce the problem
> and I'd like to know why it is going wrong with -static.  Can you post a
> defconfig that I can rebuild and that exposes the problem?

Yes, I also would like more details about why this is needed. I think
the TARGET_LDFLAGS thing is currently quite confusing: some packages
are using it as flags for gcc at the link stage, some other packages
are using it as flags for ld directly. Maybe this is what should be
clarified somehow?

>   Note: a few autobuilders with BR2_PREFER_STATIC_LIB enabled could be nice -
> or maybe not, because many packages _will_break.

I intended to make my autobuilder script randomly select
BR2_PREFER_STATIC_LIB, BR2_CCACHE and a few other "big" options, but
until now, I had the feeling that the autobuilder results already
provided enough failures to keep us busy :-)

Thomas
ANDY KENNEDY - Nov. 6, 2012, 3:06 p.m.
> 
>   Although I'm OK with this patch, I have been unable to reproduce the problem
> and I'd like to know why it is going wrong with -static.  Can you post a
> defconfig that I can rebuild and that exposes the problem?
> 
>   Note: a few autobuilders with BR2_PREFER_STATIC_LIB enabled could be nice -
> or maybe not, because many packages _will_break.
> 
>   Regards,
>   Arnout

First off, I built again with a clean copy of BuildRoot (2012.08) and
produced this output this time:

root@akennedy_lin:~/deleteme/buildroot-2012.08# find output/target/ \
-exec file {} \; 2>&1 | grep dynamic | awk -F: '{print $1}'
output/target/usr/bin/ldd
output/target/usr/bin/htop
output/target/usr/bin/getconf
output/target/usr/sbin/kdump
output/target/usr/sbin/proftpd
output/target/sbin/ldconfig

Note that htop and proftpd got linked dynamically.  The odd part is
that kexec built static this time.  What's up with that?  I repeated
this twice and kexec builds static every time. . . though I really
thought I did this last week and it was dynamically linked.  Perhaps
I'm smokin' something. . .  BTW, I have _NEVER_ been able to build
kdump static through their build.  I can reproduce it manually, but
there seems to be no way to do it with their current Makefile.

Attached is the config file.  You may want to change the primary
download site as I have it set to ftp://localhost/pub/dl.

Andy
Arnout Vandecappelle - Nov. 6, 2012, 10:32 p.m.
On 11/06/12 16:06, ANDY KENNEDY wrote:
>> >     Although I'm OK with this patch, I have been unable to reproduce the problem
>> >  and I'd like to know why it is going wrong with -static.  Can you post a
>> >  defconfig that I can rebuild and that exposes the problem?
>> >
>> >     Note: a few autobuilders with BR2_PREFER_STATIC_LIB enabled could be nice -
>> >  or maybe not, because many packages _will_break.
>> >
>> >     Regards,
>> >     Arnout
> First off, I built again with a clean copy of BuildRoot (2012.08) and
> produced this output this time:
>
> root@akennedy_lin:~/deleteme/buildroot-2012.08#  find output/target/ \
> -exec file {} \; 2>&1 | grep dynamic | awk -F: '{print $1}'
> output/target/usr/bin/ldd
> output/target/usr/bin/htop
> output/target/usr/bin/getconf
> output/target/usr/sbin/kdump
> output/target/usr/sbin/proftpd
> output/target/sbin/ldconfig

  I finally understand what's going on - it's exactly what Andy said in his
first mail :-)

  libtool interpret -static as linking statically with libraries that will not
be installed to the libdir; you have to pass it -all-static to force static
linking.  Or, as Andy proposes, pass --static, which libtool passes on blindly
to gcc.  gcc and (GNU) ld both interpret --static the same as -static (although
this isn't documented).

  Therefore, this gets my
Acked-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>


  Regards,
  Arnout
ANDY KENNEDY - Jan. 14, 2013, 6:51 p.m.
All,

I just pulled the latest snapshot (buildroot-20130114.tar.bz2), did a
quick grep to see if the patch was applied:

buildroot/package# grep static *
Makefile.in:SHARED_STATIC_LIBS_OPTS=--enable-static --disable-shared
Makefile.in:TARGET_LDFLAGS += -static
Makefile.in:SHARED_STATIC_LIBS_OPTS=--enable-static --enable-shared
pkg-autotools.mk:               --enable-shared --disable-static \

and see that it wasn't.  Is it on anyone's tree right now or did it
get lost in the shuffle?

Thanks!
Andy

> -----Original Message-----
> From: ANDY KENNEDY
> Sent: Monday, November 05, 2012 10:55 AM
> To: 'buildroot@busybox.net'
> Subject: [PATCH] BR2_PREFER_STATIC_LIB and LDFLAGS+= -static
> 
> The following changes LDFLAGS from += -static to += --static if building
> with BR2_PREFER_STATIC_LIB so that various components actually build
> statically.
> 
> Signed-off-by: Andy Kennedy <andy.kennedy@adtran.com>
> Acked-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> ---
> diff -Naur a/package/Makefile.in b/package/Makefile.in
> --- a/package/Makefile.in       2012-08-31 03:49:41.000000000 -0500
> +++ b/package/Makefile.in       2012-11-05 10:45:45.000000000 -0600
> @@ -299,7 +299,7 @@
> 
>  ifeq ($(BR2_PREFER_STATIC_LIB),y)
>  SHARED_STATIC_LIBS_OPTS=--enable-static --disable-shared
> -TARGET_LDFLAGS += -static
> +TARGET_LDFLAGS += --static
>  else
>  SHARED_STATIC_LIBS_OPTS=--enable-static --enable-shared
>  endif
>
Peter Korsgaard - Jan. 14, 2013, 7:36 p.m.
>>>>> "ANDY" == ANDY KENNEDY <ANDY.KENNEDY@adtran.com> writes:

 ANDY> All,
 ANDY> I just pulled the latest snapshot (buildroot-20130114.tar.bz2), did a
 ANDY> quick grep to see if the patch was applied:

 ANDY> buildroot/package# grep static *
 ANDY> Makefile.in:SHARED_STATIC_LIBS_OPTS=--enable-static --disable-shared
 ANDY> Makefile.in:TARGET_LDFLAGS += -static
 ANDY> Makefile.in:SHARED_STATIC_LIBS_OPTS=--enable-static --enable-shared
 ANDY> pkg-autotools.mk:               --enable-shared --disable-static \

 ANDY> and see that it wasn't.  Is it on anyone's tree right now or did it
 ANDY> get lost in the shuffle?

Committed now with Arnout's explanation about why it is needed. Please
consider documenting WHY a change is needed rather than just what the
change is to get this kind of patches merged faster in the future.
ANDY KENNEDY - Jan. 14, 2013, 7:39 p.m.
> 
> Committed now with Arnout's explanation about why it is needed. Please
> consider documenting WHY a change is needed rather than just what the
> change is to get this kind of patches merged faster in the future.

My bad.  I'll try to be more verbose next time!

Andy

> 
> --
> Bye, Peter Korsgaard

Patch

diff -Naur a/package/Makefile.in b/package/Makefile.in
--- a/package/Makefile.in       2012-08-31 03:49:41.000000000 -0500
+++ b/package/Makefile.in       2012-11-05 10:45:45.000000000 -0600
@@ -299,7 +299,7 @@ 

 ifeq ($(BR2_PREFER_STATIC_LIB),y)
 SHARED_STATIC_LIBS_OPTS=--enable-static --disable-shared
-TARGET_LDFLAGS += -static
+TARGET_LDFLAGS += --static
 else
 SHARED_STATIC_LIBS_OPTS=--enable-static --enable-shared
 endif