CHIP-SPV / chipStar

chipStar is a tool for compiling and running HIP/CUDA on SPIR-V via OpenCL or Level Zero APIs.
Other
225 stars 33 forks source link

chipStar builds without linking to pthread (on some systems) then fails to run tests with "undefined reference to pthread_create" #708

Closed franz closed 11 months ago

franz commented 11 months ago

While trying to update chipStar to 1.1 on PoCL CI, 19 tests failed:

The following tests FAILED:
    846 - hipcc-TestHipComplexInclude (Failed)
    847 - hipcc-TestHipccAcceptCcFiles (Failed)
    848 - hipcc-TestHipccAcceptCppFiles (Failed)
    849 - hipcc-Test513Regression (Failed)
    850 - TestHipccNeedsDashO (Failed)
    851 - hipcc-TestHipVersion (Failed)
    852 - TestHipccHalfConversions (Failed)
    853 - TestHipccHalfOperators (Failed)
    858 - TestHipccCompileAndLink (Failed)
    859 - TestHipccCompileThenLink (Failed)
    861 - TestHipcc621 (Failed)
    862 - TestHipccAcceptCFiles (Failed)
    863 - TestRDCWithSingleHipccCmd (Failed)
    864 - TestRDCWithMultipleHipccCmds (Failed)
    865 - TestWholeProgramCompilation (Failed)
    867 - TestHipccFp16Include (Failed)
    869 - TestHipccMultiSource (Failed)
    888 - TestForgottenModuleUnload (Failed)
    891 - TestRuntimeWarnings (Failed)
Errors while running CTest

all errors were similar to this:

/usr/bin/ld: /home/github/examples/build_chipstar/chipStar/src/chipStar-build/libCHIP.so: undefined reference to `pthread_create'
/usr/bin/ld: /home/github/examples/build_chipstar/chipStar/src/chipStar-build/libCHIP.so: undefined reference to `pthread_yield'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

failed to execute:/usr/lib/llvm-17/bin/clang++ -include /home/github/examples/build_chipstar/chipStar/src/chipStar/include/hip/spirv_fixups.h -I//home/github/examples/build_chipstar/chipStar/src/chipStar-build/include -D__HIP_NO_HALF_OPERATORS__=1 -x hip /home/github/examples/build_chipstar/chipStar/src/chipStar/tests/compiler/TestHipccHalfConversions.cc -D__HIP_PLATFORM_SPIRV__= --offload=spirv64 -nohipwrapperinc --hip-path=/home/github/examples/build_chipstar/chipStar/src/chipStar-build --target=x86_64-pc-linux-gnu   -I/home/github/examples/build_chipstar/chipStar/src/chipStar/include -I/home/github/examples/build_chipstar/chipStar/src/chipStar/HIP/include -I/home/github/examples/build_chipstar/chipStar/src/chipStar-build/include -L/home/github/examples/build_chipstar/chipStar/src/chipStar-build -lCHIP -Wl,-rpath,/home/github/examples/build_chipstar/chipStar/src/chipStar-build

I suspect the reason is related to CI not having libze_loader.so only libOpenCL.so. libCHIP.so does not link to pthread directly, only indirectly through libze_loader.so:

readelf -d libCHIP.so

Dynamic section at offset 0x187530 contains 32 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libOpenCL.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libze_loader.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
 0x000000000000000e (SONAME)             Library soname: [libCHIP.so]
 0x000000000000001d (RUNPATH)            Library runpath: [/usr/lib/x86_64-linux-gnu]

readelf -d /usr/lib/x86_64-linux-gnu/libze_loader.so.1

Dynamic section at offset 0x45d50 contains 30 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
...