Modify

Opened 3 years ago

Last modified 19 months ago

#19066 reopened defect

netifd fails to build with musl

Reported by: daniel.petre Owned by: developers
Priority: high Milestone: Chaos Calmer 15.05
Component: base system Version: Trunk
Keywords: netifd, musl Cc:

Description

make[3]: Entering directory '/home/dani/openwrt/package/network/config/netifd'
CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -mips16 -minterlink-mips16 -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include/libnl-tiny -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/include -I/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/usr/include -I/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include " CXXFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -mips16 -minterlink-mips16 -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include/libnl-tiny -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/include -I/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/usr/include -I/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include " LDFLAGS="-L/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/lib -L/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/lib -L/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/usr/lib -L/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/lib " make -C /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/. AR="mips-openwrt-linux-musl-gcc-ar" AS="mips-openwrt-linux-musl-gcc -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include/libnl-tiny -I/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/usr/include" LD=mips-openwrt-linux-musl-ld NM="mips-openwrt-linux-musl-gcc-nm" CC="mips-openwrt-linux-musl-gcc" GCC="mips-openwrt-linux-musl-gcc" CXX="mips-openwrt-linux-musl-g++" RANLIB="mips-openwrt-linux-musl-gcc-ranlib" STRIP=mips-openwrt-linux-musl-strip OBJCOPY=mips-openwrt-linux-musl-objcopy OBJDUMP=mips-openwrt-linux-musl-objdump SIZE=mips-openwrt-linux-musl-size CROSS="mips-openwrt-linux-musl-" ARCH="mips" ;
make[4]: Entering directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
make[5]: Entering directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
make[6]: Entering directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
make[6]: Leaving directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
make[6]: Entering directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
[ 4%] Building C object CMakeFiles/netifd.dir/system-linux.c.o
In file included from /home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/linux/if_bridge.h:18:0,

from /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/system-linux.c:35:

/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/linux/in6.h:32:8: error: redefinition of 'struct in6_addr'

struct in6_addr {


In file included from /home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/arpa/inet.h:9:0,

from /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/system-linux.c:27:

/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/netinet/in.h:24:8: note: originally defined here

struct in6_addr


In file included from /home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/linux/if_bridge.h:18:0,

from /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/system-linux.c:35:

/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/linux/in6.h:49:8: error: redefinition of 'struct sockaddr_in6'

struct sockaddr_in6 {


In file included from /home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/arpa/inet.h:9:0,

from /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/system-linux.c:27:

/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/netinet/in.h:36:8: note: originally defined here

struct sockaddr_in6


In file included from /home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/linux/if_bridge.h:18:0,

from /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/system-linux.c:35:

/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/linux/in6.h:59:8: error: redefinition of 'struct ipv6_mreq'

struct ipv6_mreq {


In file included from /home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/arpa/inet.h:9:0,

from /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/system-linux.c:27:

/home/dani/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.6/include/netinet/in.h:45:8: note: originally defined here

struct ipv6_mreq


CMakeFiles/netifd.dir/build.make:540: recipe for target 'CMakeFiles/netifd.dir/system-linux.c.o' failed
make[6]: * [CMakeFiles/netifd.dir/system-linux.c.o] Error 1
make[6]: Leaving directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
CMakeFiles/Makefile2:63: recipe for target 'CMakeFiles/netifd.dir/all' failed
make[5]:
* [CMakeFiles/netifd.dir/all] Error 2
make[5]: Leaving directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
Makefile:116: recipe for target 'all' failed
make[4]: * [all] Error 2
make[4]: Leaving directory '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17'
Makefile:46: recipe for target '/home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/.built' failed
make[3]:
* /home/dani/openwrt/build_dir/target-mips_34kc_musl-1.1.6/netifd-2015-02-17/.built Error 2
make[3]: Leaving directory '/home/dani/openwrt/package/network/config/netifd'
package/Makefile:174: recipe for target 'package/network/config/netifd/compile' failed
make[2]: * [package/network/config/netifd/compile] Error 2
make[2]: Leaving directory '/home/dani/openwrt'
package/Makefile:171: recipe for target '/home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/stamp/.package_compile' failed
make[1]:
* /home/dani/openwrt/staging_dir/target-mips_34kc_musl-1.1.6/stamp/.package_compile Error 2
make[1]: Leaving directory '/home/dani/openwrt'
/home/dani/openwrt/include/toplevel.mk:179: recipe for target 'world' failed
make: * [world] Error 2

Attachments (1)

910-define-glibc-hack.patch (126 bytes) - added by anonymous 3 years ago.
add #define GLIBC to musl/include/features.h

Download all attachments as: .zip

Change History (9)

comment:1 Changed 3 years ago by anonymous

I worked around this issue by adding the following code:

#ifndef __GLIBC__
#define __GLIBC__
#endif

just after

#include <arpa/inet.h>
#include <netinet/in.h>

in netifd-2015-02-17/system-linux.c

This works because the kernel headers check for previous libc definitions by including include/linux/libc-compat.h.

IOW in that header you will find:

/* We have included glibc headers... */
#if defined(__GLIBC__)

/* Coordinate with glibc netinet/in.h header. */
#if defined(_NETINET_IN_H)

/* GLIBC headers included first so don't define anything
 * that would already be defined. */
#define __UAPI_DEF_IN6_ADDR		0
/* The exception is the in6_addr macros which must be defined
 * if the glibc code didn't define them. This guard matches
 * the guard in glibc/inet/netinet/in.h which defines the
 * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
#if defined(__USE_MISC) || defined (__USE_GNU)
#define __UAPI_DEF_IN6_ADDR_ALT		0
#else
#define __UAPI_DEF_IN6_ADDR_ALT		1
#endif
#define __UAPI_DEF_SOCKADDR_IN6		0
#define __UAPI_DEF_IPV6_MREQ		0
#define __UAPI_DEF_IPPROTO_V6		0
#define __UAPI_DEF_IPV6_OPTIONS		0
...

comment:2 Changed 3 years ago by daniel.petre

thanks, it worked but now i can't compile mjpg-streamer nor iproute2.. :)

comment:3 Changed 3 years ago by anonymous

Yes I noticed, event hostapd doesn't work.

Now I'm trying a slight different approach: #define __GLIBC__ in musl/include/features.h

I'm compiling a new toolchain right now, it should work... Patch attached, YMMV.

Changed 3 years ago by anonymous

add #define GLIBC to musl/include/features.h

comment:4 Changed 3 years ago by anonymous

unfortunately that patch doesn't work... more investigation is needed

comment:5 Changed 3 years ago by anonymous

I worked around this issue by adding #define __GLIBC__ 0 in staging_dir/toolchain.*/include/features.h right before the last #endif

However this is not a proper fix and I fear it may have unwanted side effects (some code has glibc specific code paths).

BTW the issue is a known FAQ for musl libc: http://wiki.musl-libc.org/wiki/FAQ#Q:_why_am_i_getting_.22error:_redefinition_of_struct_ethhdr.2Ftcphdr.2Fetc.22_.3F

and the best solution is to provide sanitized kernel headers instead of relying on the kernel source.

Now that I have built the image successfully, I only need to test if it really works on the bare hardware. But I don't feel brave enough to do it now... maybe later... :-)

comment:6 Changed 3 years ago by nbd

  • Resolution set to fixed
  • Status changed from new to closed

fixed in r44553

comment:7 follow-up: Changed 19 months ago by mouse

  • Resolution fixed deleted
  • Status changed from closed to reopened

Those patches has been missed on recent git version 70069b0f57bb2f1721fbf8393985c13c7800f66f. Building with kernel-4.4.

comment:8 in reply to: ↑ 7 Changed 19 months ago by rileyporter@…

Replying to mouse:

Those patches has been missed on recent git version 70069b0f57bb2f1721fbf8393985c13c7800f66f. Building with kernel-4.4.

Ditto!

Git commit 0b4cf150b54a8a037d0c825e5b7336b3987e9b58 still does not have these changes.

Add Comment

Modify Ticket

Action
as reopened .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.