[syslinux] Makefile race condition with parallel make

Josh Triplett josh at joshtriplett.org
Thu Mar 28 10:47:24 PDT 2013


When attempting to build syslinux in parallel (make -j5), I encountered
the following error at the end:

rm -f liblpxelinux.a
ar cq liblpxelinux.a rawcon.o ./fs/pxe/dhcp_option.o ./fs/pxe/pxe.o ./fs/pxe/tftp.o ./fs/pxe/urlparse.o ./lwip/src/netif/ethernetif.o ./lwip/src/netif/etharp.o ./lwip/src/netif/slipif.o ./lwip/src/netif/ppp/md5.o ./lwip/src/netif/ppp/randm.o ./lwip/src/netif/ppp/chpms.o ./lwip/src/netif/ppp/lcp.o ./lwip/src/netif/ppp/vj.o ./lwip/src/netif/ppp/chap.o ./lwip/src/netif/ppp/ipcp.o ./lwip/src/netif/ppp/auth.o ./lwip/src/netif/ppp/fsm.o ./lwip/src/netif/ppp/ppp.o ./lwip/src/netif/ppp/pap.o ./lwip/src/netif/ppp/magic.o ./lwip/src/netif/ppp/ppp_oe.o ./lwip/src/netif/undiif.o ./lwip/src/core/init.o ./lwip/src/core/mem.o ./lwip/src/core/snmp/mib_structs.o ./lwip/src/core/snmp/asn1_dec.o ./lwip/src/core/snmp/asn1_enc.o ./lwip/src/core/snmp/msg_out.o ./lwip/src/core/snmp/mib2.o ./lwip/src/core/snmp/msg_in.o ./lwip/src/core/def.o ./lwip/src/core/dns.o ./lwip/src/core/sys.o ./lwip/src/core/dhcp.o ./lwip/src/core/ipv4/inet_chksum.o ./lwip/src/core/ipv4/icmp.o ./lwip/src/core/ipv4/autoip.o ./lwip/src/core/ipv4/ip_addr.o ./lwip/src/core/ipv4/inet.o ./lwip/src/core/ipv4/igmp.o ./lwip/src/core/ipv4/ip_frag.o ./lwip/src/core/ipv4/ip.o ./lwip/src/core/udp.o ./lwip/src/core/stats.o ./lwip/src/core/raw.o ./lwip/src/core/tcp.o ./lwip/src/core/netif.o ./lwip/src/core/memp.o ./lwip/src/core/timers.o ./lwip/src/core/pbuf.o ./lwip/src/core/tcp_in.o ./lwip/src/core/tcp_out.o ./lwip/src/api/api_lib.o ./lwip/src/api/netdb.o ./lwip/src/api/tcpip.o ./lwip/src/api/err.o ./lwip/src/api/sockets.o ./lwip/src/api/netifapi.o ./lwip/src/api/netbuf.o ./lwip/src/api/api_msg.o ./lwip/src/arch/sys_arch.o ./fs/pxe/core.o ./fs/pxe/dnsresolv.o ./fs/pxe/ftp.o ./fs/pxe/ftp_readdir.o ./fs/pxe/gpxeurl.o ./fs/pxe/http.o ./fs/pxe/http_readdir.o ./fs/pxe/idle.o ./fs/pxe/isr.o ./fs/pxe/tcp.o
ar: ./fs/pxe/dhcp_option.o: No such file or directory
make[1]: *** [liblpxelinux.a] Error 1

Scanning back through the build log showed that earlier in the build it
built fs/pxe/dhcp_option.o, added it to libpxelinux.a, and then deleted
it.

Looking at core/Makefile shows the race, introduced in commit
16aa878d78086e9bc1c1f1053dc24da295f81e05:

# Legacy network stack
libpxelinux.a: rawcon.o $(PXELINUX_OBJS)
        rm -f $@
        $(AR) cq $@ $^
        $(RANLIB) $@
        rm $(PXELINUX_OBJS)

# LwIP network stack
liblpxelinux.a: rawcon.o
        $(MAKE) CFLAGS="$(CFLAGS) -DIS_LPXELINUX" $(LPXELINUX_OBJS)
        rm -f $@
        $(AR) cq $@ $^ $(LPXELINUX_OBJS)
        $(RANLIB) $@
        rm $(LPXELINUX_OBJS)

PXELINUX_OBJS and LPXELINUX_OBJS contain some common objects, namely
those in CORE_PXE_CSRC:

CORE_PXE_CSRC = \
        $(addprefix ./fs/pxe/, dhcp_option.c pxe.c tftp.c urlparse.c)

So, if those two rules run in parallel, they'll step on each other.
Since they both need to build using different build flags, they need to
produce different object files; each library can then depend on the
corresponding object files (dropping the $(MAKE) from liblpxelinux.a),
and they can stop removing each others' objects.

- Josh Triplett



More information about the Syslinux mailing list