Re: [LTP] Realtime test failure

Mitani
2010-11-16T08:29:04Z

> Sent: Tuesday, November 16, 2010 12:58 AM
> To: Mitani
> Cc: ltp-list@lists.sourceforge.net
> Subject: Re: [LTP] Realtime test failure
>
> On Sun, Nov 14, 2010 at 10:29 PM, Mitani <mitani@ryobi.co.jp> wrote:
> >
> >
> >> -----Original Message-----
> >> From: Garrett Cooper [mailto:yanegomi@gmail.com]
> >> Sent: Monday, November 15, 2010 2:20 PM
> >> To: Mitani
> >> Cc: ltp-list@lists.sourceforge.net; 當座 健市
> >> Subject: Re: [LTP] Realtime test failure
> >>
> >> 2010/11/14 Mitani <mitani@ryobi.co.jp>:
> >> >> -----Original Message-----
> >> >> From: Garrett Cooper [mailto:yanegomi@gmail.com]
> >> >> Sent: Monday, November 15, 2010 12:03 PM
> >> >> To: Mitani
> >> >> Subject: Re: [LTP] Realtime test failure
> >> >>
> >> >> On Sun, Nov 14, 2010 at 6:54 PM, Mitani <mitani@ryobi.co.jp> wrote:
> >> >> > Hi,
> >> >> >
> >> >> > "realtime" build failed in my system with git "ltp-f388d33.tar.gz":
> >> >> > ------------<RHEL4.8 - x86>
> >> >> > make[2]: Entering directory
> >> >> `/home/LTP/ltp-dev-20101112/testcases/realtime'
> >> >> > make -C lib -f
> >> >> "/home/LTP/ltp-dev-20101112/testcases/realtime/lib/Makefile"
> >> >> > all
> >> >> > make[3]: Entering directory
> >> >> > `/home/LTP/ltp-dev-20101112/testcases/realtime/lib'
> >> >> > gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -D_GNU_SOURCE
> >> >> > -I/home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include
> >> >> > -I../../../include -I../../../include -c -o librttest.o
> >> librttest.c
> >> >> > In file included from librttest.c:43:
> >> >> >
> >> >>
> >>
> /home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include/librtte
> >> >> st.h: In
> >> >> > function `atomic_add':
> >> >> >
> >> >>
> >>
> /home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include/librtte
> >> >> st.h:119
> >> >> > : warning: implicit declaration of function `__sync_add_and_fetch'
> >> >> > gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -D_GNU_SOURCE
> >> >> > -I/home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include
> >> >> > -I../../../include -I../../../include -c -o libstats.o
> libstats.c
> >> >> > In file included from libstats.c:47:
> >> >> >
> >> >>
> >>
> /home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include/librtte
> >> >> st.h: In
> >> >> > function `atomic_add':
> >> >> >
> >> >>
> >>
> /home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include/librtte
> >> >> st.h:119
> >> >> > : warning: implicit declaration of function `__sync_add_and_fetch'
> >> >> > if [ -z "librttest.o libstats.o" ] ; then \
> >> >> > echo "Cowardly refusing to create empty archive"; \
> >> >> > exit 1; \
> >> >> > fi
> >> >> > ar -rc "librealtime.a" librttest.o libstats.o
> >> >> > ranlib "librealtime.a"
> >> >> > make[3]: Leaving directory
> >> >> > `/home/LTP/ltp-dev-20101112/testcases/realtime/lib'
> >> >> > make[3]: Entering directory
> >> >> > `/home/LTP/ltp-dev-20101112/testcases/realtime/func'
> >> >> > make[4]: Entering directory
> >> >> >
> >> `/home/LTP/ltp-dev-20101112/testcases/realtime/func/async_handler'
> >> >> > gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -D_GNU_SOURCE
> >> >> > -I/home/LTP/ltp-dev-20101112/testcases/realtime/include
> >> >> > -I../../../../include -I../../../../include
> >> >> > -L/home/LTP/ltp-dev-20101112/testcases/realtime/lib
> >> >> -L../../../../lib
> >> >> > async_handler.c -lrealtime -lpthread -lrt -lm -o async_handler
> >> >> > In file included from async_handler.c:42:
> >> >> >
> >> /home/LTP/ltp-dev-20101112/testcases/realtime/include/librttest.h:
> >> >> In
> >> >> > function `atomic_add':
> >> >> >
> >> >>
> >>
> /home/LTP/ltp-dev-20101112/testcases/realtime/include/librttest.h:11
> >> >> 9:
> >> >> > warning: implicit declaration of function `__sync_add_and_fetch'
> >> >> >
> >> >>
> >>
> /home/LTP/ltp-dev-20101112/testcases/realtime/lib/librealtime.a(libr
> >> >> ttest.o)
> >> >> > (.text+0x1a7): In function `create_thread':
> >> >> >
> >> >>
> >>
> /home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include/librtte
> >> >> st.h:119
> >> >> > : undefined reference to `__sync_add_and_fetch'
> >> >> > collect2: ld returned 1 exit status
> >> >> > make[4]: *** [async_handler] Error 1
> >> >> > make[4]: Leaving directory
> >> >> >
> >> `/home/LTP/ltp-dev-20101112/testcases/realtime/func/async_handler'
> >> >> > make[3]: *** [all] Error 2
> >> >> > make[3]: Leaving directory
> >> >> > `/home/LTP/ltp-dev-20101112/testcases/realtime/func'
> >> >> > make[2]: *** [all] Error 2
> >> >> > make[2]: Leaving directory
> >> >> `/home/LTP/ltp-dev-20101112/testcases/realtime'
> >> >> > make[1]: *** [all] Error 2
> >> >> > make[1]: Leaving directory
> `/home/LTP/ltp-dev-20101112/testcases'
> >> >> > make: *** [testcases-all] Error 2
> >> >> > ------------
> >> >> >
> >> >> > "realtime" build failed in:
> >> >> > ------------
> >> >> > RHEL4.8 -- x86, x86_64, ia64
> >> >> > RHEL5.4 -- x86
> >> >> > ------------
> >> >> >
> >> >> > "realtime" build succeeded in:
> >> >> > ------------
> >> >> > RHEL5.4 -- x86_64, ia64
> >> >> > ------------
> >> >> >
> >> >> > It is caused by "__sync_add_and_fetch".
> >> >> >
> >> >> > In following URL, "__sync_add_and_fetch" is "built-in functions
> for
> >> >> > atomic memory access". And It is provided in "gcc":
> >> >>
> >>
> > http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Atomic-Builtins.html
> >> >> >
> >> >> > There is "__sync_add_and_fetch" in gcc4.1.2 (It is the gcc of
> RHEL5.1
> >> >> -
> >> >> > RHEL5.4).
> >> >> > And there is not "__sync_add_and_fetch" in gcc3.4.6 (It is the
> gcc
> >> of
> >> >> > RHEL4.8)
> >> >> >
> >> >> > In addition, "__sync_add_and_fetch" is for 64 bit environment.
> >> >> >
> >> >> >
> >> >>
> >>
> http://stackoverflow.com/questions/130740/link-error-when-compiling-
> >> >> gcc-atom
> >> >> > ic-operation-in-32-bit-mode
> >> >> >
> >> >> > http://gcc.gnu.org/wiki/Atomic
> >> >> >
> >> >> > Perhaps, the judgment that "realtime" must be built or not depends
> >> on
> >> >> > gcc's version (> 4.0) and 64 bits environment, I think.
> >> >>
> >> >> Could you please attach your testcases/realtime/config.log and
> >> >> testcases/realtime/include/realtime_config.h ?
> >> >> Thanks,
> >> >> -Garrett
> >> >
> >> >
> >> > I understood.
> >> > Thank you and sorry for my insufficient information.
> >> >
> >> > I attach following files:
> >> > - config.log (RHEL4.8-x86)
> >> > - realtime_config.h (RHEL4.8-x86)
> >> > - config.log (RHEL5.5-x86)
> >> > - realtime_config.h (RHEL5.5-x86)
> >>
> >> Could you please try compiling the following C sources in both
> >> scenarios?
> >> Thanks,
> >> -Garrett
> >>
> >> #ifndef _GNU_SOURCE
> >> #define _GNU_SOURCE
> >> #endif
> >> #include <stdlib.h>
> >> int main(void) {
> >> char *c;
> >> return __sync_add_and_fetch(c, 1);
> >> }
> >
> >
> > I was going to compile the sent source in RHEL4.8/5.5-x86, but failed.
> >
> > ------------<RHEL4.8-x86>
> > [root@RHEL48-LTP-x86 async_handler]# cat realtime-test.c
> > #ifndef _GNU_SOURCE
> > #define _GNU_SOURCE
> > #endif
> > #include <stdlib.h>
> > int main(void) {
> > char *c;
> > return __sync_add_and_fetch(c, 1); }
> >
> > [root@RHEL48-LTP-x86 async_handler]# gcc realtime-test.c -o
> realtime-test
> > /tmp/cciHVx8b.o(.text+0x25): In function `main':
> > : undefined reference to `__sync_add_and_fetch'
> > collect2: ld returned 1 exit status
> > [root@RHEL48-LTP-x86 async_handler]#
> > [root@RHEL48-LTP-x86 async_handler]# gcc -g -O2 -g -O2
> -fno-strict-aliasing -pipe -Wall -D
> >
> _GNU_SOURCE -I/home/LTP/ltp-dev-20101112/testcases/realtime/include
> -I../../../../include
> > -I../../../../include -L/home/LTP/ltp-dev-20101112/testcases/re
> altime/lib -L../../../..
> > /lib realtime-test.c -lrealtime -lpthread -lrt -lm -o realtime-test
> > realtime-test.c: In function `main':
> > realtime-test.c:7: warning: implicit declaration of function
> `__sync_add_and_fetch'
> > realtime-test.c:6: warning: 'c' might be used uninitialized in this
> function
> > /tmp/ccIDckLk.o(.text+0x10): In function `main':
> >
> /home/LTP/ltp-dev-20101112/testcases/realtime/func/async_handler/rea
> ltime-test.c:7: undefined reference to `__sync_add_and_fetch'
> > collect2: ld returned 1 exit status
> > [root@RHEL48-LTP-x86 async_handler]#
> > ------------
> >
> > ------------<RHEL5.5-x86>
> > [root@RHEL55-LTP-x86 async_handler]# cat realtime-test.c
> > #ifndef _GNU_SOURCE
> > #define _GNU_SOURCE
> > #endif
> > #include <stdlib.h>
> > int main(void) {
> > char *c;
> > return __sync_add_and_fetch(c, 1); }
> >
> > [root@RHEL55-LTP-x86 async_handler]# gcc realtime-test.c -o
> realtime-test
> > /tmp/ccK8hmPs.o: In function `main':
> > realtime-test.c:(.text+0x20): undefined reference to
> `__sync_add_and_fetch_1'
> > collect2: ld returned 1 exit status
> > [root@RHEL55-LTP-x86 async_handler]# gcc -g -O2 -g -O2
> -fno-strict-aliasing -pipe -Wall -D
> >
> _GNU_SOURCE -I/home/LTP/ltp-dev-20101112/testcases/realtime/include
> -I../../../../include
> > -I../../../../include -L/home/LTP/ltp-dev-20101112/testcases/re
> altime/lib -L../../../..
> > /lib realtime-test.c -lrealtime -lpthread -lrt -lm -o realtime-test
> > realtime-test.c: In function 'main':
> > realtime-test.c:7: warning: 'c' is used uninitialized in this function
> > /tmp/ccKUnocB.o: In function `main':
> >
> /home/LTP/ltp-dev-20101112/testcases/realtime/func/async_handler/rea
> ltime-test.c:7: undefined reference to `__sync_add_and_fetch_1'
> > collect2: ld returned 1 exit status
> > [root@RHEL55-LTP-x86 async_handler]#
>
> Not sure why but it incorrectly passed on your machine:
>
> configure:5186: checking Checking for __sync_add_and_fetch gcc builtin
> function
> configure:5216: gcc -c -g -O2 conftest.c >&5
> configure:5222: $? = 0
>
> 23 AC_MSG_CHECKING([Checking for __sync_add_and_fetch gcc builtin
> function])
> 24 AC_TRY_COMPILE([
> 25 #ifndef _GNU_SOURCE
> 26 #define _GNU_SOURCE
> 27 #endif
> 28 #include <stdlib.h>],[int main(void) {
> 29 char *c;
> 30 return __sync_add_and_fetch(c, 1);
> 31 }],[has___sync_add_and_fetch=yes])
> 32 if test "x$has___sync_add_and_fetch" = xyes; then
> 33 AC_DEFINE(HAVE___SYNC_ADD_AND_FETCH,1,[Define to 1 if you
> have the __ sync_add_and_fetch gcc builtin function])
> 34 AC_MSG_RESULT(yes)
> 35 else
> 36 AC_MSG_RESULT(no)
> 37 fi
>
> Whereas it didn't on mine:
>
> 248 configure:4777: checking Checking for __sync_add_and_fetch gcc
> builtin funct ion
> 249 configure:4797: gcc -c -g -O2 conftest.c >&5
> 250 configure:4797: $? = 0
>
> There was a potential problem with the macro though (I keep on
> forgetting that AC_TRY_COMPILE and AC_COMPILE_IFELSE work predefine
> main() with the block of code provided), so please let me know if
> things work for you.
> Thanks,
> -Garrett

I attached same options by obeying "config.log".
And I confirmed that "conftest.c" could be successfully compiled by
manual operation:
------------
[root@RHEL48-LTP-x86 async_handler]# pwd
/home/LTP/ltp-dev-20101112/testcases/realtime/func/async_handler
[root@RHEL48-LTP-x86 async_handler]# ll
total 36
-rw-rw-r-- 1 root root 1045 Nov 12 02:19 Makefile
-rw-rw-r-- 1 root root 5341 Nov 12 02:19 async_handler.c
-rw-rw-r-- 1 root root 4485 Nov 12 02:19 async_handler_jk.c
-rw-rw-r-- 1 root root 6013 Nov 12 02:19 async_handler_tsc.c
-rw-r--r-- 1 root root 147 Nov 15 15:14 conftest.c
-rwxrwxr-x 1 root root 333 Nov 12 02:19 run_auto.sh
[root@RHEL48-LTP-x86 async_handler]# cat conftest.c
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdlib.h>
int main(void) {
char *c;
return __sync_add_and_fetch(c, 1); }

[root@RHEL48-LTP-x86 async_handler]# gcc -c -g -O2 conftest.c
[root@RHEL48-LTP-x86 async_handler]# echo $?
0
[root@RHEL48-LTP-x86 async_handler]# ll
total 40
-rw-rw-r-- 1 root root 1045 Nov 12 02:19 Makefile
-rw-rw-r-- 1 root root 5341 Nov 12 02:19 async_handler.c
-rw-rw-r-- 1 root root 4485 Nov 12 02:19 async_handler_jk.c
-rw-rw-r-- 1 root root 6013 Nov 12 02:19 async_handler_tsc.c
-rw-r--r-- 1 root root 147 Nov 15 15:14 conftest.c
-rw-r--r-- 1 root root 2596 Nov 16 16:24 conftest.o
-rwxrwxr-x 1 root root 333 Nov 12 02:19 run_auto.sh
[root@RHEL48-LTP-x86 async_handler]#
------------

I tried build async_handler.c with "-c" option by manual operation
according to "conftest.c", and it succeeded:
------------
[root@RHEL48-LTP-x86 async_handler]# gcc -c -g -O2 -fno-strict-aliasing -pipe -Wall -D_GNU_SOURCE -I/home/LTP/ltp-dev-20101112/testcases/realtime/include -I../../../../include -I../../../../include -L/home/LTP/ltp-dev-20101112/testcases/realtime/lib -L../../../../lib async_handler.c -lrealtime -lpthread -lrt -lm -o async_handler
In file included from async_handler.c:42:
/home/LTP/ltp-dev-20101112/testcases/realtime/include/librttest.h: In function `atomic_add':
/home/LTP/ltp-dev-20101112/testcases/realtime/include/librttest.h:119: warning: implicit declaration of function `__sync_add_and_fetch'
gcc: -lrealtime: linker input file unused because linking not done
gcc: -lpthread: linker input file unused because linking not done
gcc: -lrt: linker input file unused because linking not done
gcc: -lm: linker input file unused because linking not done
[root@RHEL48-LTP-x86 async_handler]# echo $?
0
[root@RHEL48-LTP-x86 async_handler]# ll
total 56
-rw-rw-r-- 1 root root 1045 Nov 12 02:19 Makefile
-rw-r--r-- 1 root root 12612 Nov 16 16:27 async_handler
-rw-rw-r-- 1 root root 5341 Nov 12 02:19 async_handler.c
-rw-rw-r-- 1 root root 4485 Nov 12 02:19 async_handler_jk.c
-rw-rw-r-- 1 root root 6013 Nov 12 02:19 async_handler_tsc.c
-rw-r--r-- 1 root root 147 Nov 15 15:14 conftest.c
-rw-r--r-- 1 root root 2596 Nov 16 16:24 conftest.o
-rwxrwxr-x 1 root root 333 Nov 12 02:19 run_auto.sh
[root@RHEL48-LTP-x86 async_handler]#
------------

But above build is not with linkage by "-c" option.
With linkage, it failed:
------------
[root@RHEL48-LTP-x86 async_handler]# gcc -g -O2 -fno-strict-aliasing -pipe -Wall -D_GNU_SOURCE -I/home/LTP/ltp-dev-20101112/testcases/realtime/include -I../../../../include -I../../../../include -L/home/LTP/ltp-dev-20101112/testcases/realtime/lib -L../../../../lib async_handler.c -lrealtime -lpthread -lrt -lm -o async_handler
In file included from async_handler.c:42:
/home/LTP/ltp-dev-20101112/testcases/realtime/include/librttest.h: In function `atomic_add':
/home/LTP/ltp-dev-20101112/testcases/realtime/include/librttest.h:119: warning: implicit declaration of function `__sync_add_and_fetch'
/home/LTP/ltp-dev-20101112/testcases/realtime/lib/librealtime.a(librttest.o)(.text+0x1a7): In function `create_thread':
/home/LTP/ltp-dev-20101112/testcases/realtime/lib/../include/librttest.h:119: undefined reference to `__sync_add_and_fetch'
collect2: ld returned 1 exit status
[root@RHEL48-LTP-x86 async_handler]#
------------

I think that the check of "__sync_add_and_fetch" by "conftest.c" must
be done without "-c" option.

Regards--