Bug #43740 Sometimes "make -jX" may generate wrong binary
Submitted: 19 Mar 2009 0:49 Modified: 12 Aug 2009 13:29
Reporter: Yasufumi Kinoshita Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB Plugin storage engine Severity:S3 (Non-critical)
Version:1.0.3 OS:Any
Assigned to: Vasil Dimov CPU Architecture:Any

[19 Mar 2009 0:49] Yasufumi Kinoshita
Description:
Parallel building may generate wrong binary, sometimes.
The wrong binary seems to be that,,,
most of *.o are compiled with "#define HAVE_ATOMIC_PTHREAD_T",
but some of files (e.g. *btr0*.o) are not compiled with "#define HAVE_ATOMIC_PTHREAD_T".
It is unsafe and wrong binary.

How to repeat:
(build plugin as innodb (--with-innodb))

make clean
rm storage/innobase/include/ut0auxconf.h    (for detection of this problem)
make -j2

Sometimes we may get the following results:

make[2]: ディレクトリ `/home/kinoyasu/mysql-5.1.29-rc-innodb-1.0.2/storage/innobase' に入ります
if gcc -DHAVE_CONFIG_H -I. -I../../include -I../../include -I../../include -I../../regex -I../../storage/innobase/include -I../../sql -I.    -O2 -g -fmessage-length=0 -D_FORTIFY_SOURCE=2   -DUNIV_LINUX ut/ut0auxconf.c -o /dev/null ; then \
                echo '#define HAVE_ATOMIC_PTHREAD_T' > include/ut0auxconf.h ; \
        fi
gcc -DHAVE_CONFIG_H -I. -I../../include -I../../include -I../../include -I../../regex -I../../storage/innobase/include -I../../sql -I.    -O2 -g -fmessage-length=0 -D_FORTIFY_SOURCE=2   -DUNIV_LINUX -MT libinnobase_a-btr0btr.o -MD -MP -MF .deps/libinnobase_a-btr0btr.Tpo -c -o libinnobase_a-btr0btr.o `test -f 'btr/btr0btr.c' || echo './'`btr/btr0btr.c
In file included from ../../storage/innobase/include/btr0btr.h:28,
                 from btr/btr0btr.c:25:
../../storage/innobase/include/univ.i:125:26: error: ut0auxconf.h: そのようなファイルやディレクトリはありません
gcc -DHAVE_CONFIG_H -I. -I../../include -I../../include -I../../include -I../../regex -I../../storage/innobase/include -I../../sql -I.    -O2 -g -fmessage-length=0 -D_FORTIFY_SOURCE=2   -DUNIV_LINUX -MT libinnobase_a-btr0cur.o -MD -MP -MF .deps/libinnobase_a-btr0cur.Tpo -c -o libinnobase_a-btr0cur.o `test -f 'btr/btr0cur.c' || echo './'`btr/btr0cur.c

(Sorry for messages in Japanese..)

The error proves that btr0btr.c is compiled before the generation of include/ut0auxconf.h !

Suggested fix:
to move the HAVE_ATOMIC_PTHREAD_T test to the other Makefile (e.g. include/Makefile ?)
[19 Mar 2009 8:32] Sveta Smirnova
Thank you for the report.

I can not repeat described behavior. Please indicate accurate version of MySQL you use and provide all configure options
[19 Mar 2009 15:23] Vasil Dimov
Grab!
[20 Mar 2009 8:48] Vasil Dimov
Allright, now I know how to say "No such file or directory" in Japanese ;-)
[20 Mar 2009 9:16] Vasil Dimov
There are a few approaches:

1. Disable any parallelism:

--- cut ---
--- Makefile.in.orig	2009-03-19 18:26:03.000000000 +0200
+++ Makefile.in	2009-03-20 09:36:32.000000000 +0200
@@ -708,6 +708,8 @@
 			pars/make_bison.sh pars/make_flex.sh \
 			pars/pars0grm.y pars/pars0lex.l
 
+.NOTPARALLEL:
+
 check_have_atomic_pthread_t:
 	if $(COMPILE) ut/ut0auxconf.c -o /dev/null ; then \
 		echo '#define HAVE_ATOMIC_PTHREAD_T' > include/ut0auxconf.h ; \
--- cut ---

2. Build all-am after the check using sub-make:

--- cut ---
--- Makefile.in.orig	2009-03-19 18:26:03.000000000 +0200
+++ Makefile.in	2009-03-20 10:26:50.000000000 +0200
@@ -712,8 +712,9 @@
 	if $(COMPILE) ut/ut0auxconf.c -o /dev/null ; then \
 		echo '#define HAVE_ATOMIC_PTHREAD_T' > include/ut0auxconf.h ; \
 	fi
+	$(MAKE) all-am
 
-all: check_have_atomic_pthread_t all-am
+all: check_have_atomic_pthread_t
 
 .SUFFIXES:
 .SUFFIXES: .c .cc .lo .o .obj
--- cut ---

3. Hook the check target as a dependency for every object file instead of a dependency for "all":

--- cut ---
--- Makefile.in.orig	2009-03-19 18:26:03.000000000 +0200
+++ Makefile.in	2009-03-20 10:50:46.000000000 +0200
@@ -713,7 +713,9 @@
 		echo '#define HAVE_ATOMIC_PTHREAD_T' > include/ut0auxconf.h ; \
 	fi
 
-all: check_have_atomic_pthread_t all-am
+am_libinnobase_a_OBJECTS: check_have_atomic_pthread_t
+
+all: all-am
 
 .SUFFIXES:
 .SUFFIXES: .c .cc .lo .o .obj
--- cut ---
[12 Aug 2009 13:29] Calvin Sun
Fixed in 1.0.4.