clangupc / clang-upc

Clang UPC Front-End
https://clangupc.github.io/
Other
16 stars 5 forks source link

Build failure on ppc64/linux w/ clang #27

Closed PHHargrove closed 10 years ago

PHHargrove commented 10 years ago

I am trying to build clang-upc on a ppc64/linux system. I was unsuccessful with gcc-4.4.7, but the system as a Clang installation which reports itself as version "clang version 3.5 (trunk)".

So, I've run cmake with -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++.

The build eventually fails with:

[ 91%] Building C object tools/clang/runtime/libupc/CMakeFiles/upc.dir/smp/upc_allocg.upc.o
In file included from <built-in>:169:
In file included from <command line>:15:
In file included from /home/hargrove/upc2c/src/llvm/tools/clang/runtime/libupc/include/clang-upc.h:15:
/gpfs/vesta-home/hargrove/upc2c/bld/bin/../lib/clang/3.4/include/clang-upc-lib.h:548:58: error: redefinition of parameter 'os_atomic_t'
  extern int __upc_atomic_cas (os_atomic_p, os_atomic_t, os_atomic_t);
                                                         ^
/gpfs/vesta-home/hargrove/upc2c/bld/bin/../lib/clang/3.4/include/clang-upc-lib.h:548:32: error: a parameter list without types is only allowed in a function definition
  extern int __upc_atomic_cas (os_atomic_p, os_atomic_t, os_atomic_t);
                               ^
2 errors generated.
make[2]: *** [tools/clang/runtime/libupc/CMakeFiles/upc.dir/smp/upc_allocg.upc.o] Error 1
make[1]: *** [tools/clang/runtime/libupc/CMakeFiles/upc.dir/all] Error 2
make: *** [all] Error 2

While not straight-forward, these error messages seem to be saying that type os_atomic_p and os_atomic_t have not been defined. The messages are confusing because clang seems to think it might be parsing a K&R-style function definition (the main clues are "redefinition of parameter" in the first message, and "a parameter list without types" in the second message).

gary-funck commented 10 years ago

Looking at the generated clang-upc-lib.h file:

#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) \
    || defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
  /* Use GCC's builtin implementation, if available.  */
  #define __upc_atomic_cas(PTR, OLD_VAL, NEW_VAL) \
    __sync_bool_compare_and_swap (PTR, OLD_VAL, NEW_VAL)
#else
  extern int __upc_atomic_cas (os_atomic_p, os_atomic_t, os_atomic_t);
#endif

It looks as if the "#else" branch is being compiled, which may indicate that the built Clang compiler does not define "__GCC_HAVE_SYNC_COMPARE_ANDSWAP*". Note that "os_atomic_t" and "os_atomic_p" are defined in upc_sysdep.h. Ope fix might be to "#include" upc_sysdep.h there or find other alternatives. This code branch may not have been compiled before on targets that don't support the builtin sync. operations.

PHHargrove commented 10 years ago

Gary,

Not sure how/where/when to include upc_sysdep.h. It is not in the include path when the generated clang-upc-lib.h is being included.

My initial attempts to mess with upc-lib.in didn't work.

-Paul

PHHargrove commented 10 years ago

Ok, I figured out how to get the required piece of upc_sysdep.h inserted into the generated clang-upc-lib.h. However, that just leads to a later failure:

/home/hargrove/upc2c/src/llvm/tools/clang/runtime/libupc/smp/upc_sysdep.c:108:4: error: "__upc_atomic_cas not
      implemented on this target"
  #error "__upc_atomic_cas not implemented on this target"

I will, for now, abandon by attempts to build on this system using clang. However, it looks like this clang might have the atomic but NOT the sync atomic bultins:

$ touch empty.c
$ clang -dM -E empty.c | grep GCC 
#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
#define __GCC_ATOMIC_INT_LOCK_FREE 2
#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
#define __GCC_ATOMIC_LONG_LOCK_FREE 2
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
PHHargrove commented 10 years ago

I am trying now on another ppc64/linux system, this time with a gcc-4.6.0. I am getting stuck at the SAME place.

Using make VERBOSE=1 I see that it is the newly built clang that is failing to to define __GCC_HAVE_SYNC_ATOMIC_COMPARE_AND_SWAP_[48]:

[ 90%] Building C object tools/clang/runtime/libupc/CMakeFiles/upc.dir/smp/upc_allocg.upc.o
cd /home/hargrov1/upc2c/bld/tools/clang/runtime/libupc && /home/hargrov1/upc2c/bld/bin/clang  -DCLANG_ENABLE_ARCMT -DCLANG_ENABLE_REWRITER -DCLANG_ENABLE_STATIC_ANALYZER -DGUPCR_PTS_PACKED_REP=1 -DGUPCR_PTS_PHASE_SIZE=20 -DGUPCR_PTS_THREAD_SIZE=10 -DGUPCR_PTS_VADDR_FIRST=1 -DGUPCR_PTS_VADDR_SIZE=34 -DIN_TARGET_LIBS=1 -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-optimize-sibling-calls -fPIC -Wall -W -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -pedantic -Wno-long-long -I/home/hargrov1/upc2c/bld/tools/clang/runtime/libupc -I/home/hargrov1/upc2c/src/llvm/tools/clang/runtime/libupc -I/home/hargrov1/upc2c/src/llvm/tools/clang/include -I/home/hargrov1/upc2c/bld/tools/clang/include -I/home/hargrov1/upc2c/bld/include -I/home/hargrov1/upc2c/src/llvm/include -I/home/hargrov1/upc2c/src/llvm/tools/clang/runtime/libupc/include -I/home/hargrov1/upc2c/src/llvm/tools/clang/runtime/libupc/collectives    -Wno-gnu -Wno-language-extension-token -fupc-pts=packed -fupc-packed-bits=20,10,34 -fupc-pts-vaddr-order=first -o CMakeFiles/upc.dir/smp/upc_allocg.upc.o   -c /home/hargrov1/upc2c/src/llvm/tools/clang/runtime/libupc/smp/upc_allocg.upc
In file included from <built-in>:169:
In file included from <command line>:15:
In file included from /home/hargrov1/upc2c/src/llvm/tools/clang/runtime/libupc/include/clang-upc.h:15:
/home/hargrov1/upc2c/bld/bin/../lib/clang/3.4/include/clang-upc-lib.h:548:58: error: redefinition of parameter
      'os_atomic_t'
  extern int __upc_atomic_cas (os_atomic_p, os_atomic_t, os_atomic_t);
                                                         ^
/home/hargrov1/upc2c/bld/bin/../lib/clang/3.4/include/clang-upc-lib.h:548:32: error: a parameter list without
      types is only allowed in a function definition
  extern int __upc_atomic_cas (os_atomic_p, os_atomic_t, os_atomic_t);
                               ^
2 errors generated.
make[2]: *** [tools/clang/runtime/libupc/CMakeFiles/upc.dir/smp/upc_allocg.upc.o] Error 1
make[2]: Leaving directory `/home/hargrov1/upc2c/bld'
make[1]: *** [tools/clang/runtime/libupc/CMakeFiles/upc.dir/all] Error 2
make[1]: Leaving directory `/home/hargrov1/upc2c/bld'
make: *** [all] Error 2

So, this is a problem with the PowerPC target for the clang in repo, not for the gcc which does have the support:

$ gcc -dM -E ~/empty.c | grep GCC
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
gary-funck commented 10 years ago

So, this is a problem with the PowerPC target for the clang in repo, not for the gcc which does have the support.

Confirmed. The runtime is compiled with the built Clang UPC compiler and it is Clang that apparently does not define this builtin sync support for PPC64.

gary-funck commented 10 years ago

Also, clang-upc-lib.h will exhibit different behavior depending upon whether Clang UPC is invoked with -O0 (no optimization) or with -ON (N > 0). When optimizing, parts of the SMP-based runtime are inlined. With a recent fix to the runtime build infrastructure, this inlining can be applied to the runtime (*.upc) files themselves.

PHHargrove commented 10 years ago

I am looking at maybe implementing in terms of the __atomic_compare_exchange() which is provided.

PHHargrove commented 10 years ago

I have just pushed to my fork an implementation of __upc_atomic_cas in terms of __atomic_compare_exchange. It is sufficient to let me use upc2c, but I have not yet tested it in "real use".

I will update my pull request if possible, or replace it if not.

nenadv commented 10 years ago

Closed with this commit - https://github.com/Intrepid/clang-upc/commit/8e588bc394f3fb21c66feb0cff6d06b62576c02e