Skip to contentSkip to conversation

package/exim: Adjust libnsl detection to include musl

PATCH New Bernd Kuhls 3 participants 6 messages Apr 12, 2015 – Jul 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 package/exim: Adjust libnsl detection to include musl

Only (e)glibc provides libnsl, uclibc provides only a stub

Fixes compilation using this defconfig

    BR2_arm=y
    BR2_cortex_a7=y
    BR2_STATIC_LIBS=y
    BR2_TOOLCHAIN_EXTERNAL=y
    BR2_PACKAGE_OPENSSL=y
    BR2_PACKAGE_EXIM=y
---
 package/exim/exim.mk |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
package/exim/exim.mk +3 -2
index 0a70c42..fcf2be5 100644
@@ -81,8 +81,9 @@ define EXIM_USE_DEFAULT_CONFIG_FILE_OPENSSL
 endef
 endif
 
-# this specific toolchain lacks libnsl
-ifeq ($(BR2_TOOLCHAIN_EXTERNAL_SYNOPSYS_ARC_2014_12),y)
+# only (e)glibc provides libnsl, remove -lnsl for all other toolchains
+# http://bugs.exim.org/show_bug.cgi?id=1564
+ifeq ($(BR2_TOOLCHAIN_USES_GLIBC),)
 define EXIM_REMOVE_LIBNSL_FROM_MAKEFILE
 	$(SED) 's/-lnsl//g' $(@D)/OS/Makefile-Linux
 endef
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 package/exim: Fix compilation error with musl

Fixes
smtp_in.c: In function ?smtp_start_session?:
smtp_in.c:1976:36: error: invalid application of ?sizeof? to incomplete type ?struct options?

     EXIM_SOCKLEN_T optlen = sizeof(struct ip_options) + MAX_IPOPTLEN;

smtp_in.c misdetects the needed style for ip_options, only OPTSTYLE == 2 works. Since musl does not provide any macro[1] to detect it we need to pretend to be darwin in order to fix the compile bug.

In order to do so we need the generated os.h before building start, therefore add some make subtargets to the configure step.

[1] http://wiki.musl-libc.org/wiki/FAQ#Q:_why_is_there_no_MUSL_macro_.3F

---
 package/exim/exim.mk |   10 ++++++++++
 1 file changed, 10 insertions(+)
package/exim/exim.mk +10 -0
index fcf2be5..d7c61db 100644
@@ -89,6 +89,13 @@ define EXIM_REMOVE_LIBNSL_FROM_MAKEFILE
 endef
 endif
 
+ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
+define EXIM_PRETEND_TO_BE_DARWIN_TO_FIX_IP_OPTIONS
+	echo "#undef GLIBC_IP_OPTIONS" >> $(@D)/build-br/os.h
+	echo "#define DARWIN_IP_OPTIONS" >> $(@D)/build-br/os.h
+endef
+endif
+
 define EXIM_CONFIGURE_TOOLCHAIN
 	$(call exim-config-add,CC,$(TARGET_CC))
 	$(call exim-config-add,CFLAGS,$(TARGET_CFLAGS))
@@ -97,6 +104,9 @@ define EXIM_CONFIGURE_TOOLCHAIN
 	$(call exim-config-add,HOSTCC,$(HOSTCC))
 	$(call exim-config-add,HOSTCFLAGS,$(HOSTCFLAGS))
 	$(EXIM_REMOVE_LIBNSL_FROM_MAKEFILE)
+	$(TARGET_MAKE_ENV) build=br $(MAKE1) -C $(@D) configure
+	$(TARGET_MAKE_ENV) build=br $(MAKE1) -C $(@D)/build-br config
+	$(EXIM_PRETEND_TO_BE_DARWIN_TO_FIX_IP_OPTIONS)
 endef
 
 ifneq ($(call qstrip,$(BR2_PACKAGE_EXIM_CUSTOM_CONFIG_FILE)),)
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/2 package/exim: Fix compilation error with musl

Dear Bernd,

Quoted 12 lines · Bernd Kuhls

Fixes
smtp_in.c: In function ?smtp_start_session?:
smtp_in.c:1976:36: error: invalid application of ?sizeof? to incomplete type ?struct options?

      EXIM_SOCKLEN_T optlen = sizeof(struct ip_options) + MAX_IPOPTLEN;

smtp_in.c misdetects the needed style for ip_options, only OPTSTYLE == 2 works. Since musl does not provide any macro[1] to detect it we need to pretend to be darwin in order to fix the compile bug.

In order to do so we need the generated os.h before building start, therefore add some make subtargets to the configure step.

I confirm the bug, but I would prefer a slightly cleaner fix, see below.

Quoted 12 lines

[1] http://wiki.musl-libc.org/wiki/FAQ#Q:_why_is_there_no_MUSL_macro_.3F

---
  package/exim/exim.mk |   10 ++++++++++
  1 file changed, 10 insertions(+)
package/exim/exim.mk +0 -0
index fcf2be5..d7c61db 100644

package/exim/exim.mk define EXIM_REMOVE_LIBNSL_FROM_MAKEFILE · line 95

Quoted 7 lines
package/exim/exim.mk +4 -0
@@ -89,6 +89,13 @@ define EXIM_REMOVE_LIBNSL_FROM_MAKEFILE
  endef
  endif
 
+ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
+define EXIM_PRETEND_TO_BE_DARWIN_TO_FIX_IP_OPTIONS
+	echo "#undef GLIBC_IP_OPTIONS" >> $(@D)/build-br/os.h
+	echo "#define DARWIN_IP_OPTIONS" >> $(@D)/build-br/os.h

I'd rename to EXIM_TWEAK_IP_OPTIONS or similar, and use sed instead of the two echos, but it's a matter of taste:

   $(SED) 's/#define GLIBC_IP_OPTIONS/#define DARWIN_IP_OPTIONS/' \
          $(@D)/OS/os.h-Linux

package/exim/exim.mk define EXIM_CONFIGURE_TOOLCHAIN · line 109

Quoted 13 lines
package/exim/exim.mk +6 -0
+endef
+endif
+
  define EXIM_CONFIGURE_TOOLCHAIN
  	$(call exim-config-add,CC,$(TARGET_CC))
  	$(call exim-config-add,CFLAGS,$(TARGET_CFLAGS))
@@ -97,6 +104,9 @@ define EXIM_CONFIGURE_TOOLCHAIN
  	$(call exim-config-add,HOSTCC,$(HOSTCC))
  	$(call exim-config-add,HOSTCFLAGS,$(HOSTCFLAGS))
  	$(EXIM_REMOVE_LIBNSL_FROM_MAKEFILE)
+	$(TARGET_MAKE_ENV) build=br $(MAKE1) -C $(@D) configure
+	$(TARGET_MAKE_ENV) build=br $(MAKE1) -C $(@D)/build-br config
+	$(EXIM_PRETEND_TO_BE_DARWIN_TO_FIX_IP_OPTIONS)

Just patch $(@D)/OS/os.h-Linux, and you can remove the two $(MAKE1) invocations.

Signature · 1 line
Luca
#3 lore raw

PATCH 1/2 package/exim: Adjust libnsl detection to include musl

In reply to Bernd Kuhls

Dear Bernd Kuhls,

Quoted 1 line · Bernd Kuhls

Only (e)glibc provides libnsl, uclibc provides only a stub

True, but uClibc provides the functionality, no? Or is the stub actually not working at runtime? Could you be a bit more specific here?

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#4 lore raw

PATCH 1/2 package/exim: Adjust libnsl detection to include musl

Thomas Petazzoni <thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8 @public.gmane.org> wrote in news:20150412185443.08512d17 at free-electrons.com:

Quoted 7 lines

Dear Bernd Kuhls,

Quoted 1 line · Bernd Kuhls

Only (e)glibc provides libnsl, uclibc provides only a stub

True, but uClibc provides the functionality, no? Or is the stub actually not working at runtime? Could you be a bit more specific here?

Hi,

http://git.uclibc.org/uClibc/tree/libnsl/nsl.c

Uclibc provides only stub code, libnsl has no functionality there ;)

Regards, Bernd

#5 lore raw

PATCH 1/2 package/exim: Adjust libnsl detection to include musl

In reply to Bernd Kuhls

Dear Bernd Kuhls,

Quoted 11 lines · Bernd Kuhls

Only (e)glibc provides libnsl, uclibc provides only a stub

Fixes compilation using this defconfig

    BR2_arm=y
    BR2_cortex_a7=y
    BR2_STATIC_LIBS=y
    BR2_TOOLCHAIN_EXTERNAL=y
    BR2_PACKAGE_OPENSSL=y
    BR2_PACKAGE_EXIM=y
Quoted 4 lines
---
 package/exim/exim.mk |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Applied after rebasing on master, thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com