CRaC / criu

Other
25 stars 10 forks source link

Parallel make race for lz4 build #18

Open nbuwe opened 4 months ago

nbuwe commented 4 months ago

The lz4 submodule build is defined as:

https://github.com/CRaC/criu/blob/daeef8f9dd173363ca077c18c803478d468fcdf2/Makefile#L248-L253

which is racy if parallel make is used. Since these two targets are independent (as defined), the make considers them to be suitable to run in parallel, so two identical make jobs will simultaneously run in the lz4 directory, stepping on each other toes. The likely result is a cryptic message from the linker in one of the jobs that tries to use an object file (that that job has previously built) while the other jobs starts writing to that same object file and truncates it. (The message is cryptic b/c linker tries to interpret an empty file as a linker script, but by the time you take a look, the other job has done writing out the object file, so it's seemingly back to normal).

nbuwe commented 4 months ago

The dependency can be introduced with something like (untested):

.PHONY: git-submodules
git-submodules:
    git submodule init
    git submodule update

lz4/lib/liblz4.a: git-submodules
    $(Q) env -i PATH="$$PATH" make CC=$(CC) CFLAGS="$(CFLAGS)" V="$(V)" -C lz4 lib

criu/liblz4io.a: lz4/lib/liblz4.a
    $(Q) env -i PATH="$$PATH" make CC=$(CC) CFLAGS="$(CFLAGS)" V="$(V)" -C lz4 lz4
    $(Q) $(AR) rcs criu/liblz4io.a lz4/programs/lz4io.o