diff mbox

openssh: fix static linking

Message ID F9C551623D2CBB4C9488801D14F864C68C8AE2F4@ex-mb3.corp.adtran.com
State Rejected
Headers show

Commit Message

ANDY KENNEDY Sept. 9, 2014, 6:29 p.m. UTC
When BR2_PREFER_STATIC_LIB is set, openssl is a static library, openssh
attempts to build dynamically as the LDFLAGS are dropped out of this build.
If PREFER_STATIC is set, add back in --static to the LDFLAGS of openssh
to make the linker happy.

Signed-off-by:  Andy Kennedy <andy.kennedy@adtran.com>
---

Comments

Baruch Siach Sept. 9, 2014, 6:37 p.m. UTC | #1
Hi Andy,

On Tue, Sep 09, 2014 at 06:29:31PM +0000, ANDY KENNEDY wrote:
> When BR2_PREFER_STATIC_LIB is set, openssl is a static library, openssh
> attempts to build dynamically as the LDFLAGS are dropped out of this build.
> If PREFER_STATIC is set, add back in --static to the LDFLAGS of openssh
> to make the linker happy.
> 
> Signed-off-by:  Andy Kennedy <andy.kennedy@adtran.com>
> ---
> diff -Naur a/package/openssh/openssh.mk b/package/openssh/openssh.mk
> --- a/package/openssh/openssh.mk	2014-02-27 14:51:23.000000000 -0600
> +++ b/package/openssh/openssh.mk	2014-09-09 12:09:57.043850866 -0500
> @@ -6,10 +6,18 @@
>  
>  OPENSSH_VERSION = 6.5p1
>  OPENSSH_SITE = http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable
> -OPENSSH_CONF_ENV = LD="$(TARGET_CC)" LDFLAGS="$(TARGET_CFLAGS)"
> +OPENSSH_CONF_ENV = LD="$(TARGET_CC)"
>  OPENSSH_CONF_OPT = --disable-lastlog --disable-utmp \
>  		--disable-utmpx --disable-wtmp --disable-wtmpx --disable-strip
>  
> +OPENSSH_LDFLAGS_FOR_CONF = $(TARGET_CFLAGS)
> +
> +ifeq ($(BR2_PREFER_STATIC_LIB),y)
> +OPENSSH_LDFLAGS_FOR_CONF += --static
> +endif
> +
> +OPENSSH_CONFIGURE_ENV += LDFLAGS="$(OPENSSH_LDFLAGS_FOR_CONF)"

Shouldn't this be OPENSSH_CONF_ENV? Have you tested this?

baruch

> +
>  OPENSSH_DEPENDENCIES = zlib openssl
>  
>  ifeq ($(BR2_PACKAGE_LINUX_PAM),y)
ANDY KENNEDY Sept. 9, 2014, 7:17 p.m. UTC | #2
> > -OPENSSH_CONF_ENV = LD="$(TARGET_CC)" LDFLAGS="$(TARGET_CFLAGS)"
> > +OPENSSH_CONF_ENV = LD="$(TARGET_CC)"
> >  OPENSSH_CONF_OPT = --disable-lastlog --disable-utmp \

> > +OPENSSH_CONFIGURE_ENV += LDFLAGS="$(OPENSSH_LDFLAGS_FOR_CONF)"
> 
> Shouldn't this be OPENSSH_CONF_ENV? Have you tested this?
> 
> baruch

Yes, and yes.  Hmmm, that's strange.  Kinda makes me wonder why
that worked at all.  Made that modification and retesting.

Like I said in the other thread, this works about once out of
three times anyway.  So, maybe I didn't do what I thought I did.

I assume that the LDFLAGS=$(TARGET_CFLAGS) are needed, and that
it _could_ break the build on other platforms.  I don't understand
why that would have worked for this particular platform I'm on.

I'll resubmit when I verify the fix.

Andy
Thomas Petazzoni Sept. 9, 2014, 7:34 p.m. UTC | #3
Hello,

On Tue, 9 Sep 2014 18:29:31 +0000, ANDY KENNEDY wrote:

> When BR2_PREFER_STATIC_LIB is set, openssl is a static library, openssh
> attempts to build dynamically as the LDFLAGS are dropped out of this build.
> If PREFER_STATIC is set, add back in --static to the LDFLAGS of openssh
> to make the linker happy.
> 
> Signed-off-by:  Andy Kennedy <andy.kennedy@adtran.com>

Sorry, but it does not make sense, because:

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

So, TARGET_CFLAGS does have -static.

Please make sure to test your patches against the latest master. I'm
sure you're again testing against 2014.02, and there has been quite a
few changes since then in terms of static library support.

Best regards,

Thomas
ANDY KENNEDY Sept. 9, 2014, 7:40 p.m. UTC | #4
> ifeq ($(BR2_PREFER_STATIC_LIB),y)
> SHARED_STATIC_LIBS_OPTS = --enable-static --disable-shared
> TARGET_CFLAGS += -static
> TARGET_CXXFLAGS += -static
> TARGET_LDFLAGS += -static
> else
> SHARED_STATIC_LIBS_OPTS = --enable-static --enable-shared
> endif
> 
> So, TARGET_CFLAGS does have -static.

OOOHHHH!!  Maybe that is the problem.  I changed this a few
years back:

-static gets eaten by autoconf.  --static doesn't.  I wonder if
that has been the problem the whole time?

> 
> Please make sure to test your patches against the latest master. I'm
> sure you're again testing against 2014.02, and there has been quite a
> few changes since then in terms of static library support.

Yeah, I hear ya.  I'll get to it eventually.  I've done too much
testing with 2014.02 and we're getting ready for a release.

I'll bump that rev later and may have to go through all this again.

Till then, I'll quit submitting patches until I'm at tip again :).

Andy
Thomas Petazzoni Sept. 9, 2014, 8:18 p.m. UTC | #5
Dear ANDY KENNEDY,

On Tue, 9 Sep 2014 19:40:01 +0000, ANDY KENNEDY wrote:

> OOOHHHH!!  Maybe that is the problem.  I changed this a few
> years back:
> 
> -static gets eaten by autoconf.  --static doesn't.  I wonder if
> that has been the problem the whole time?

Yes, but we reverted this change. Now we're back to using -static
instead of --static. And we've patched libtool so that -static is
actually understood as -all-static. See commits
8d764327a697a2572bba96878972c1a469f864f3 and
5d66a9b1fb67cf009fe4f15028c02a8386109dc5, as well as
97703978ac870ce2b14ad144f8e082de82aa2c64.

> Yeah, I hear ya.  I'll get to it eventually.  I've done too much
> testing with 2014.02 and we're getting ready for a release.
> 
> I'll bump that rev later and may have to go through all this again.
> 
> Till then, I'll quit submitting patches until I'm at tip again :).

Yes, before sending patches, please test them on top of the latest
master. Patches against 2014.02 are generally a bit useless, due to the
fairly high rate of changes occurring these days in Buildroot.

Thanks!

Thomas
diff mbox

Patch

diff -Naur a/package/openssh/openssh.mk b/package/openssh/openssh.mk
--- a/package/openssh/openssh.mk	2014-02-27 14:51:23.000000000 -0600
+++ b/package/openssh/openssh.mk	2014-09-09 12:09:57.043850866 -0500
@@ -6,10 +6,18 @@ 
 
 OPENSSH_VERSION = 6.5p1
 OPENSSH_SITE = http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable
-OPENSSH_CONF_ENV = LD="$(TARGET_CC)" LDFLAGS="$(TARGET_CFLAGS)"
+OPENSSH_CONF_ENV = LD="$(TARGET_CC)"
 OPENSSH_CONF_OPT = --disable-lastlog --disable-utmp \
 		--disable-utmpx --disable-wtmp --disable-wtmpx --disable-strip
 
+OPENSSH_LDFLAGS_FOR_CONF = $(TARGET_CFLAGS)
+
+ifeq ($(BR2_PREFER_STATIC_LIB),y)
+OPENSSH_LDFLAGS_FOR_CONF += --static
+endif
+
+OPENSSH_CONFIGURE_ENV += LDFLAGS="$(OPENSSH_LDFLAGS_FOR_CONF)"
+
 OPENSSH_DEPENDENCIES = zlib openssl
 
 ifeq ($(BR2_PACKAGE_LINUX_PAM),y)