Open llvmbot opened 5 years ago
@Simon Atanasyan Thank you very much for your tips. Now I have solved the problem of the HelloWorld (opencl program) program crash in the attachment.At the same time, when running C++ HelloWorld with clang 3.8.1 environment, the "ld-musl-mipsel.so.1" dynamic library can't be found, which can be solved by creating the following software link.
****[loongson@localhost Downloads]$ sudo ln -s /lib64/ld-2.20.so /lib64/ld-musl-mipsel.so.1
Although the problem was solved in this way, I did not understand the mechanism. After many attempts, the last version of mesa I chose was mesa-18.0.5.
For the combination of clang 3.8.1 + mesa 11, if my work plan for the second half of the year goes well, I will do further research, but I don't know what it means? Can you give me some guidance? Should I give up this combination? Looking forward to your reply.
At this point, everything is going well, thank you again for your mention and guidance.
You can choose to turn off this bug or minimize its priority. Thanks.
Your teacher was right - bugs in standard libraries rarely happens. More often the problem is in the code which use/call libraries routines.
As to the "/lib64/ld-musl-mipsel.so.1: bad ELF interpreter: No such file or directory" error - Clang driver passes incorrect arguments to the linker "-dynamic-linker /lib64/ld-musl-mipsel.so.1". This is a bug in the Clang which has been fixed. That's why Clang 8 works ok.
I think you have to resolve problems in compilation your HelloWorld OpneCL example using Clang 8.0. This version of compiler has a lot of fixed bugs in comparison with the Clang 3.0. I'm not an expert in Mesa, but it looks like you need to update its version. The same problem described here https://bugs.freedesktop.org/show_bug.cgi?id=98627.
In the clang 3.8.1 environment, the error reported by the C++ HelloWorld program is maybe related to libstdc++. But the program compiled by clang8.0.0 can run normally, which makes me feel confused? Because during in two compilation, I just updated the llvm+clang rpm packages to 8.0.0 version.
[root@localhost Hello]# clang++ --save-temps -g -o Hello Hello.cpp
[root@localhost Hello]# ./Hello -bash: ./Hello: /lib64/ld-musl-mipsel.so.1: bad ELF interpreter: No such file or directory
(1)https://gist.github.com/mscdex/06e39ba86de0585e92ed (2)https://git.realms.tech/JTRealms/lede- wrt1900v1/commit/5ae9a4f830f369b4e8cf20d5bc569946f7cae06e
Thank you very much for your suggestion. I have never doubted that libstdc++ will have problems. Just because graduated from college, my teacher tole me a "Truth" that the probability of a bug found in the C library code is almost zero. Meantime, this sentence also hampers my thinking.
Compile the C++ Hello World program with a and b respectively. The compilation steps and results are as follows: clang 3.8.1 compiling log
[root@localhost llvm-compile-procedure]# clang --version clang version 3.8.1 (tags/RELEASE_381/final) Target: mips64el-redhat-linux Thread model: posix InstalledDir: /usr/bin [root@localhost llvm-compile-procedure]# clang++ --version clang version 3.8.1 (tags/RELEASE_381/final) Target: mips64el-redhat-linux Thread model: posix InstalledDir: /usr/bin
[root@localhost llvm-compile-procedure]# clang -ccc-print-phases Hello.cpp 0: input, "Hello.cpp", c++ 1: preprocessor, {0}, c++-cpp-output 2: compiler, {1}, ir 3: backend, {2}, assembler 4: assembler, {3}, object 5: linker, {4}, image
[root@localhost llvm-compile-procedure]# clang -### Hello.cpp -o Hello.o clang version 3.8.1 (tags/RELEASE_381/final) Target: mips64el-redhat-linux Thread model: posix InstalledDir: /usr/bin "/usr/bin/clang-3.8" "-cc1" "-triple" "mips64el-redhat-linux" "-S" "-disable-free" "-disable-llvm-verifier" "-main-file-name" "Hello.cpp" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-no-integrated-as" "-mconstructor-aliases" "-fuse-init-array" "-target-cpu" "mips64r2" "-target-abi" "n64" "-mfloat-abi" "hard" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/usr/bin/../lib64/clang/3.8.1" "-c-isystem" "." "-c-isystem" "/usr/include/c++/4.9.3/mips64el-redhat-linux" "-c-isystem" "/usr/include/c++/4.9.3" "-cxx-isystem" "." "-cxx-isystem" "/usr/include/c++/4.9.3/mips64el-redhat-linux" "-cxx-isystem" "/usr/include/c++/4.9.3" "-internal-isystem" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../include/c++/4.9.3" "-internal-isystem" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../include/c++/4.9.3/mips64el-redhat-linux" "-internal-isystem" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../include/c++/4.9.3/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/bin/../lib64/clang/3.8.1/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fno-dwarf-directory-asm" "-fdebug-compilation-dir" "/root/TarAll/llvm-compile-procedure" "-ferror-limit" "19" "-fmessage-length" "132" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/Hello-4888b6.s" "-x" "c++" "Hello.cpp"
"/usr/bin/as" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-KPIC" "-EL" "-o" "/tmp/Hello-c5d20e.o" "/tmp/Hello-4888b6.s"
"/usr/bin/ld" "--eh-frame-hdr" "-m" "elf64ltsmip" "-dynamic-linker" "/lib64/ld-musl-mipsel.so.1" "-o" "Hello.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crt1.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crti.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/crtbegin.o" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64" "-L/usr/bin/../lib64" "-L/lib/../lib64" "-L/usr/lib/../lib64" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../.." "-L/usr/bin/../lib" "-L/lib" "-L/usr/lib" "/tmp/Hello-c5d20e.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/crtend.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crtn.o"
[root@localhost llvm-compile-procedure]# clang++ -E Hello.cpp [root@localhost llvm-compile-procedure]# echo $? 0
[root@localhost llvm-compile-procedure]# clang++ -fmodules -fsyntax-only -Xclang -dump-tokens Hello.cpp [root@localhost llvm-compile-procedure]# echo $? 0
[root@localhost llvm-compile-procedure]# clang++ -fmodules -fsyntax-only -Xclang -ast-dump Hello.cpp [root@localhost llvm-compile-procedure]# echo $? 0
[root@localhost llvm-compile-procedure]# clang++ -emit-llvm -c Hello.cpp -o Hello.bc Opts.Triple is: mips64el-redhat-linux [root@localhost llvm-compile-procedure]# ls Hello.bc Hello.bc [root@localhost llvm-compile-procedure]# file Hello.bc Hello.bc: LLVM IR bitcode
[root@localhost llvm-compile-procedure]# clang++ -O3 -S -emit-llvm Hello.cpp -o Hello.ll Opts.Triple is: mips64el-redhat-linux [root@localhost llvm-compile-procedure]# file Hello.ll Hello.ll: C source, ASCII text, with very long lines
clang++ -S Hello.cpp -o Hello.s
[root@localhost llvm-compile-procedure]# clang++ -g -o Hello Hello.cpp Opts.Triple is: mips64el-redhat-linux [root@localhost llvm-compile-procedure]# ./Hello -bash: ./Hello: /lib64/ld-musl-mipsel.so.1: bad ELF interpreter: No such file or directory
clang++ -save-temps Hello.cpp -o Hello
clang 8.0.0 compiling log
[root@localhost Hello]# clang --version clang version 8.0.0 Target: mips64el-redhat-linux Thread model: posix InstalledDir: /usr/bin [root@localhost Hello]# clang++ --version clang version 8.0.0 Target: mips64el-redhat-linux Thread model: posix InstalledDir: /usr/bin
[root@localhost Hello]# clang -ccc-print-phases Hello.cpp 0: input, "Hello.cpp", c++ 1: preprocessor, {0}, c++-cpp-output 2: compiler, {1}, ir 3: backend, {2}, assembler 4: assembler, {3}, object 5: linker, {4}, image
[root@localhost Hello]# clang -### Hello.cpp -o Hello.o clang version 8.0.0 Target: mips64el-redhat-linux Thread model: posix InstalledDir: /usr/bin "/usr/bin/clang-8" "-cc1" "-triple" "mips64el-redhat-linux" "-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "Hello.cpp" "-mrelocation-model" "pic" "-pic-level" "1" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-fuse-init-array" "-target-cpu" "mips64r2" "-target-feature" "-noabicalls" "-target-abi" "n64" "-mfloat-abi" "hard" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/usr/lib64/clang/8.0.0" "-c-isystem" "." "-c-isystem" "/usr/include/c++/4.9.3/mips64el-redhat-linux" "-c-isystem" "/usr/include/c++/4.9.3" "-cxx-isystem" "." "-cxx-isystem" "/usr/include/c++/4.9.3/mips64el-redhat-linux" "-cxx-isystem" "/usr/include/c++/4.9.3" "-internal-isystem" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../include/c++/4.9.3" "-internal-isystem" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../include/c++/4.9.3/mips64el-redhat-linux" "-internal-isystem" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../include/c++/4.9.3/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib64/clang/8.0.0/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir" "/root/TarAll/llvm-compile-procedure/Hello" "-ferror-limit" "19" "-fmessage-length" "132" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/Hello-99daa5.o" "-x" "c++" "Hello.cpp" "-faddrsig" "/usr/bin/ld" "--eh-frame-hdr" "-m" "elf64ltsmip" "-dynamic-linker" "/lib64/ld.so.1" "-o" "Hello.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crt1.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crti.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/crtbegin.o" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64" "-L/usr/bin/../lib64" "-L/lib/../lib64" "-L/usr/lib/../lib64" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3" "-L/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../.." "-L/usr/bin/../lib" "-L/lib" "-L/usr/lib" "/tmp/Hello-99daa5.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/crtend.o" "/usr/bin/../lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crtn.o"
The operation steps 4-9 are omitted here, but the execution results are correct.
clang++ -save-temps Hello.cpp -o Hello [root@localhost Hello]# clang++ -save-temps Hello.cpp -o Hello [root@localhost Hello]# ./Hello Hello World!
All crashes are related to libstdc++ and unrelated to Mesa and/or OpenCL. Can you:
a) Compile any trivial C++ "hello world" application like below using clang 3.8.1?
using namespace std; int main() { cout << "Hello, World!"; return 0; }
b) Build Clang 8.0 and compile the same trivial application?
@Simon Atanasyan To be honest, this above problem with the Mesa 11 package and is caused by upgrading llvm. Which is the just version of mesa that matches llvm8.0, so that the OpenCL development environment can be successfully built on the Fedora 21 platform.
For the "Free invalid pointer" problem of clang 3.8.1 mentioned in the previous comment, I made the following changes to the source code by patching:
/ Create a default constructor for the TargetOptions class on the mips64el platform, and skip the assignment to Opts.Triple by macro detection in the ParseTargetArgs function of the file CompilerInvocation.cpp./
diff -Nuar a/cfe-3.8.1.src/include/clang/Basic/TargetOptions.h b/cfe-3.8.1.src/include/clang/Basic/TargetOptions.h
--- a/cfe-3.8.1.src/include/clang/Basic/TargetOptions.h 2015-06-11 10:53:41.000000000 -0400
+++ b/cfe-3.8.1.src/include/clang/Basic/TargetOptions.h 2019-07-09 11:29:00.359434024 -0400
@@ -47,6 +47,9 @@
std::vector
std::vector
TargetOptions():Triple("mips64el-redhat-linux"){}; +#endif };
} // end namespace clang
diff -Nuar a/cfe-3.8.1.src/lib/Frontend/CompilerInvocation.cpp b/cfe-3.8.1.src/lib/Frontend/CompilerInvocation.cpp --- a/cfe-3.8.1.src/lib/Frontend/CompilerInvocation.cpp 2016-01-12 16:01:56.000000000 -0500 +++ b/cfe-3.8.1.src/lib/Frontend/CompilerInvocation.cpp 2019-07-09 11:31:14.402400117 -0400 @@ -44,6 +44,7 @@
+#include
//===----------------------------------------------------------------------===// @@ -2027,11 +2028,14 @@ Opts.FPMath = Args.getLastArgValue(OPT_mfpmath); Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature); Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version);
Although the above modification is not flexible enough, it solves the problem of Triple parsing, and the compilation process begins to enter the CodeGeneration phase.
Although the above modification is not flexible enough, it solves the problem of Triple parsing, and the compilation process begins to enter the CodeGeneration phase. The new problems that come with it are as follows: The complete GDB stack information is shown below:
at malloc.c:4974
from /lib64/libLLVM-3.8.so
at /usr/include/c++/4.9.3/bits/basic_string.h:1671
at /usr/include/c++/4.9.3/bits/basic_string.h:1176
at /root/rpmbuild/BUILD/llvm-3.8.1.src/lib/Support/Timer.cpp:99
LangOpts=..., TargetOpts=..., CodeGenOpts=..., PPOpts=..., HeaderSearchOpts=..., Diags=..., Action=clang::Backend_EmitNothing,
this=0x1200f8a20) at /root/rpmbuild/BUILD/cfe-3.8.1.src/lib/CodeGen/CodeGenAction.cpp:78
at /root/rpmbuild/BUILD/cfe-3.8.1.src/lib/CodeGen/CodeGenAction.cpp:723
at /root/rpmbuild/BUILD/cfe-3.8.1.src/lib/Frontend/FrontendAction.cpp:140
at /root/rpmbuild/BUILD/cfe-3.8.1.src/lib/Frontend/FrontendAction.cpp:319
at /root/rpmbuild/BUILD/cfe-3.8.1.src/lib/Frontend/CompilerInstance.cpp:839
source="\n__kernel void hello_kernel(__global const float *a,\n\t\t\t\t\t\t__global const float *b,\n\t\t\t\t\t\t__global float *result)\n{\n int gid = get_global_id(0);\n\n result[gid] = a[gid] + b[gid];\n}\n",
headers=std::vector of length 0, capacity 0, name="input.cl", triple="r600--", processor="caicos", opts="",
address_spaces=..., optimization_level=@0xffffff3a88: 2, r_log="") at llvm/invocation.cpp:259
source="\n__kernel void hello_kernel(__global const float *a,\n\t\t\t\t\t\t__global const float *b,\n\t\t\t\t\t\t__global float *result)\n{\n int gid = get_global_id(0);\n\n result[gid] = a[gid] + b[gid];\n}\n",
headers=std::vector of length 0, capacity 0, ir=<optimized out>, target="caicos-r600--", opts="", r_log="")
at llvm/invocation.cpp:864
headers=std::vector of length 0, capacity 0) at core/program.cpp:63
pfn_notify=0x0, user_data=0x0) at api/program.cpp:184
pfn_notify=0x0, user_data=<optimized out>) at ocl_icd_loader_gen.c:386
at /root/TarAll/src/Chapter_2/HelloWorld/HelloWorld.cpp:158
In response to the above questions, I am still doing source code analysis, trying to solve this problem. Can you give me some good tips? Thanks again.
@Simon Atanasyan Many thanks for your advices. As you can see from Mesa's rpmbuild SPEC file, there is a compilation dependency between the Mesa package and llvm/clang, as shown below.
This compilation dependency causes the high version of the mesa package to be compiled, while the early compilations such as "libclc", "clinfo", and "ocl-icd" will not be available, and there is also no way to accurately determine the version of Mesa that need to compile.
%if 0%{?with_llvm} %if 0%{?with_private_llvm} BuildRequires: mesa-private-llvm-devel %else BuildRequires: llvm-devel >= 3.5.0 %if 0%{?with_opencl} BuildRequires: clang-devel >= 3.0 %endif %endif %endif
At 11 o'clock last night, I completed the compilation of llvm-clang 8.0 and started to compile the mesa 11 package according to your suggestions. However, under the Fedora 21 system, there are too many mesa API compatibility issues, one of which is shown below, and because the mesa needs to be recompiled, the number of available Openc Platform returned by the clinfo command is 0.
[root@localhost ~]# llc -version LLVM (http://llvm.org/): LLVM version 8.0.0 Optimized build. Default target: mips64el-redhat-linux Host CPU: (unknown)
Registered Targets: amdgcn - AMD GCN GPUs mips - MIPS (32-bit big endian) mips64 - MIPS (64-bit big endian) mips64el - MIPS (64-bit little endian) mipsel - MIPS (32-bit little endian) nvptx - NVIDIA PTX 32-bit nvptx64 - NVIDIA PTX 64-bit r600 - AMD GPUs HD2XXX-HD6XXX
[root@localhost ~]# clang++ --version clang version 8.0.0 Target: mips64el-redhat-linux Thread model: posix InstalledDir: /usr/bin
In file included from draw/draw_llvm.c:45:0: ./gallivm/lp_bld_intr.h:63:20: error: unknown type name 'LLVMAttribute' LLVMAttribute attr); ^ draw/draw_llvm.c: In function 'create_jit_sampler_type': draw/draw_llvm.c:178:22: warning: unused variable 'target' [-Wunused-variable] LLVMTargetDataRef target = gallivm->target; ^ draw/draw_llvm.c: In function 'create_jit_context_type': draw/draw_llvm.c:218:22: warning: unused variable 'target' [-Wunused-variable] LLVMTargetDataRef target = gallivm->target; ^ draw/draw_llvm.c: In function 'create_jit_vertex_header': draw/draw_llvm.c:377:22: warning: unused variable 'target' [-Wunused-variable] LLVMTargetDataRef target = gallivm->target; ^ draw/draw_llvm.c: In function 'draw_llvm_generate': draw/draw_llvm.c:1580:10: error: implicit declaration of function 'LLVMAddAttribute' [-Werror=implicit-function-declaration] LLVMAddAttribute(LLVMGetParam(variant_func, i), ^ draw/draw_llvm.c:1581:27: error: 'LLVMNoAliasAttribute' undeclared (first use in this function) LLVMNoAliasAttribute); ^ draw/draw_llvm.c:1581:27: note: each undeclared identifier is reported only once for each function it appears in draw/draw_llvm.c: In function 'draw_gs_llvm_generate': draw/draw_llvm.c:2123:27: error: 'LLVMNoAliasAttribute' undeclared (first use in this function) LLVMNoAliasAttribute); ^ cc1: some warnings being treated as errors Makefile:2115: recipe for target 'draw/draw_llvm.lo' failed make[3]: [draw/draw_llvm.lo] Error 1 make[3]: Waiting for unfinished jobs.... make[3]: Leaving directory '/root/rpmbuild/BUILD/mesa-20151218/src/gallium/auxiliary' Makefile:580: recipe for target 'all-recursive' failed make[2]: [all-recursive] Error 1 make[2]: Leaving directory '/root/rpmbuild/BUILD/mesa-20151218/src/gallium' Makefile:674: recipe for target 'all-recursive' failed make[1]: [all-recursive] Error 1 make[1]: Leaving directory '/root/rpmbuild/BUILD/mesa-20151218/src' Makefile:619: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1 error: Bad exit status from /var/tmp/rpm-tmp.wvfWMM (%build)
RPM build errors: Bad exit status from /var/tmp/rpm-tmp.wvfWMM (%build)
[root@localhost SPECS]# clinfo Number of platforms 0
[root@localhost SPECS]# rpm -qa | grep libOpenCL mesa-libOpenCL-devel-11.1.0-5.20151218.fc21.loongson.6.mips64el mesa-libOpenCL-11.1.0-5.20151218.fc21.loongson.6.mips64el [root@localhost SPECS]# yum info mesa-libOpenCL Loaded plugins: auto-update-debuginfo, langpacks Installed Packages Name : mesa-libOpenCL Arch : mips64el Version : 11.1.0 Release : 5.20151218.fc21.loongson.6 Size : 1.0 M Repo : installed From repo : /mesa-libOpenCL-11.1.0-5.20151218.fc21.loongson.6.mips64el Summary : Mesa OpenCL runtime library URL : http://www.mesa3d.org License : MIT Description : Mesa OpenCL runtime library.
Unfortunately I can not reproduce the bug on the recent version of LLVM/Clang because I have no access to MIPS host with appropriate video subsystem. LLVM/Clang 3.8 was released three years ago. Could you check the problem using LLVM/Clang 7.x or 8.x?
When I compiled the clang package, the following warning message reported. Figuring out the warnings would be my job this Saturday.
[root@localhost SPECS]# rpmbuild -bb clang.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.viOlsk
/usr/bin/cmake -DCMAKE_C_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_Fortran_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr -DINCLUDE_INSTALL_DIR:PATH=/usr/include -DLIB_INSTALL_DIR:PATH=/usr/lib64 -DSYSCONF_INSTALL_DIR:PATH=/etc -DSHARE_INSTALL_PREFIX:PATH=/usr/share -DLIB_SUFFIX=64 -DBUILD_SHARED_LIBS:BOOL=ON .. -DLLVM_LINK_LLVM_DYLIB:BOOL=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_CONFIG:FILEPATH=/usr/bin/llvm-config-64 -DCLANG_ENABLE_ARCMT:BOOL=ON -DCLANG_ENABLE_STATIC_ANALYZER:BOOL=ON -DCLANG_INCLUDE_DOCS:BOOL=ON -DCLANG_INCLUDE_TESTS:BOOL=ON -DCLANG_PLUGIN_SUPPORT:BOOL=ON -DCLANG_BUILD_EXAMPLES:BOOL=OFF -DLIB_SUFFIX= -- The C compiler identification is GNU 4.9.3 -- The CXX compiler identification is GNU 4.9.3 -- Check for working C compiler: /usr/lib64/ccache/cc -- Check for working C compiler: /usr/lib64/ccache/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/lib64/ccache/c++ -- Check for working CXX compiler: /usr/lib64/ccache/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found LLVM_CONFIG as /usr/bin/llvm-config-64 -- Performing Test C_SUPPORTS_FPIC -- Performing Test C_SUPPORTS_FPIC - Success -- Performing Test CXX_SUPPORTS_FPIC -- Performing Test CXX_SUPPORTS_FPIC - Success -- Building with -fPIC -- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG -- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success -- Performing Test C_SUPPORTS_WERROR_DATE_TIME -- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success -- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME -- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success -- Performing Test CXX_SUPPORTS_CXX11 -- Performing Test CXX_SUPPORTS_CXX11 - Success -- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS -- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS - Success -- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS -- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS - Success -- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS -- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS - Success -- Performing Test C_SUPPORTS_FDATA_SECTIONS -- Performing Test C_SUPPORTS_FDATA_SECTIONS - Success -- Performing Test CXX_SUPPORTS_FDATA_SECTIONS -- Performing Test CXX_SUPPORTS_FDATA_SECTIONS - Success -- Found PythonInterp: /usr/bin/python2.7 (found version "2.7.8") -- Clang version: 3.8.1 -- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG -- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Failed -- Configuring done CMake Warning (dev) at /usr/share/llvm/cmake/AddLLVM.cmake:513 (add_dependencies): Policy CMP0046 is not set: Error on non-existent dependency in add_dependencies. Run "cmake --help-policy CMP0046" for policy details. Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "intrinsics_gen" of target "clangFrontend" does not exist. Call Stack (most recent call first): CMakeLists.txt:396 (llvm_add_library) lib/Frontend/CMakeLists.txt:9 (add_clang_library) This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done CMake Warning: Manually-specified variables were not used by the project:
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS_RELEASE
CMAKE_Fortran_FLAGS_RELEASE
INCLUDE_INSTALL_DIR
LIB_INSTALL_DIR
LIB_SUFFIX
SHARE_INSTALL_PREFIX
SYSCONF_INSTALL_DIR
when I debug the "HelloWorld" with GNU debuger, The complete function call stack information is as follows:
(gdb) bt
at malloc.c:4974
at /builddir/build/BUILD/gcc-4.9.3/obj-mips64el-redhat-linux/mips64el-redhat-linux/libstdc++-v3/include/ext/new_allocator.h:110
at /builddir/build/BUILD/gcc-4.9.3/obj-mips64el-redhat-linux/mips64el-redhat-linux/libstdc++-v3/include/bits/basic_string.tcc:449
at /usr/include/c++/4.9.3/bits/basic_string.h:249
at /root/rpmbuild/BUILD/cfe-3.8.1.src/lib/Frontend/CompilerInvocation.cpp:2072
source="\n__kernel void hello_kernel(__global const float *a,\n\t\t\t\t\t\t__global const float *b,\n\t\t\t\t\t\t__global float *result)\n{\n int gid = get_global_id(0);\n\n result[gid] = a[gid] + b[gid];\n}\n",
headers=std::vector of length 0, capacity 0, name="input.cl", triple="r600--", processor="caicos", opts="",
address_spaces=..., optimization_level=@0xffffff3a88: 1437349920, r_log="") at llvm/invocation.cpp:179
source="\n__kernel void hello_kernel(__global const float *a,\n\t\t\t\t\t\t__global const float *b,\n\t\t\t\t\t\t__global float *result)\n{\n int gid = get_global_id(0);\n\n result[gid] = a[gid] + b[gid];\n}\n",
---Type
headers=std::vector of length 0, capacity 0) at core/program.cpp:63
pfn_notify=0x0, user_data=0x0) at api/program.cpp:184
pfn_notify=0x0, user_data=<optimized out>) at ocl_icd_loader_gen.c:386
at /root/TarAll/src/Chapter_2/HelloWorld/HelloWorld.cpp:158
I noticed the Frame 12, Further information is shown below:
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { 2024 using namespace options; 2025 Opts.ABI = Args.getLastArgValue(OPT_target_abi); 2026 Opts.CPU = Args.getLastArgValue(OPT_target_cpu); 2027 Opts.FPMath = Args.getLastArgValue(OPT_mfpmath); 2028 Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature); 2029 Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version); 2030 Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); 2031 Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ); 2032 // Use the default target triple if unspecified. 2033 if (Opts.Triple.empty()) 2034 Opts.Triple = llvm::sys::getDefaultTargetTriple(); 2035 }
In order to get default Triple, the function “llvm::sys::getDefaultTargetTriple()” was called and a c++ string "mips64el-redhat-linux" returned, After the assignment to the variable -- Opts.Triple-- is completed, the program crashes.
@llvm/issue-subscribers-opencl
Author: None (llvmbot)
Extended Description
Recently, I'm learnning the OpenCL Programming Guide adn use clang+llvm3.8.1 to compile the exercise code in Chapter 2 of the book. During the execution of the program, I encountered a serious bug about clang.
My Error info:
[root@localhost HelloWorld]# ./HelloWorld Error in `./HelloWorld': free(): invalid pointer: 0x0000005562f65800 ======= Backtrace: ========= /lib64/libc.so.6(+0x9f854)[0x555fb1b854] /lib64/libc.so.6(__libc_free+0x804)[0x555fb2c22c] /lib64/libstdc++.so.6(_ZdlPv+0x20)[0x555f8128f0] /lib64/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x20)[0x555f8a8298] /lib64/libclangFrontend.so(+0x8401c)[0x555fed001c] ======= Memory map: ======== 120000000-120004000 r-xp 00000000 08:02 4719230 /root/TarAll/src/Chapter_2/HelloWorld/HelloWorld 120010000-120014000 r--p 00000000 08:02 4719230 /root/TarAll/src/Chapter_2/HelloWorld/HelloWorld 120014000-120018000 rw-p 00004000 08:02 4719230 /root/TarAll/src/Chapter_2/HelloWorld/HelloWorld 123604000-1236c8000 rwxp 00000000 00:00 0 [heap] 555f730000-555f758000 r-xp 00000000 08:02 4863976 /usr/lib64/ld-2.20.so 555f758000-555f764000 rw-p 00000000 00:00 0 555f764000-555f768000 rw-p 00024000 08:02 4863976 /usr/lib64/ld-2.20.so 555f784000-555f7a0000 r-xp 00000000 08:02 4863583 /usr/lib64/libOpenCL.so.1.0.0 555f7a0000-555f7ac000 ---p 0001c000 08:02 4863583 /usr/lib64/libOpenCL.so.1.0.0 555f7ac000-555f7b0000 rw-p 00018000 08:02 4863583 /usr/lib64/libOpenCL.so.1.0.0 555f7b0000-555f8e8000 r-xp 00000000 08:02 4862493 /usr/lib64/libstdc++.so.6.0.20 555f8e8000-555f8f4000 ---p 00138000 08:02 4862493 /usr/lib64/libstdc++.so.6.0.20 555f8f4000-555f900000 r--p 00134000 08:02 4862493 /usr/lib64/libstdc++.so.6.0.20 555f900000-555f908000 rw-p 00140000 08:02 4862493 /usr/lib64/libstdc++.so.6.0.20 .... .....
My platform info
architecture info: [root@localhost HelloWorld]# uname -a Linux localhost 3.10.84-21.fc21.loongson.18.mips64el #1 SMP PREEMPT Tue Apr 16 18:41:34 CST 2019 mips64 mips64 mips64 GNU/Linux
[root@localhost HelloWorld]# lscpu Architecture: mips64 Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Model name: ICT Loongson-3A R3 (Loongson-3A3000) @ 1399MHz CPU max MHz: 1399.9860 CPU min MHz: 349.9960 NUMA node0 CPU(s): 0-3 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& rpm packages info: [root@localhost HelloWorld]# rpm -qa | grep llvm llvm-devel-3.8.1-3.fc21.loongson.2.mips64el llvm-static-3.8.1-3.fc21.loongson.2.mips64el llvm-libs-3.8.1-3.fc21.loongson.2.mips64el llvm-3.8.1-3.fc21.loongson.2.mips64el llvm-debuginfo-3.8.1-3.fc21.loongson.2.mips64el
[root@localhost HelloWorld]# rpm -qa | grep clang clang-libs-3.8.1-1.fc21.loongson.2.mips64el clang-devel-3.8.1-1.fc21.loongson.2.mips64el clang-analyzer-3.8.1-1.fc21.loongson.2.noarch clang-debuginfo-3.8.1-1.fc21.loongson.2.mips64el clang-3.8.1-1.fc21.loongson.2.mips64el
[root@localhost HelloWorld]# rpm -qa | grep libclc libclc-0.0.1-11.20150918git4346c30.fc21.loongson.mips64el libclc-devel-0.0.1-11.20150918git4346c30.fc21.loongson.mips64el
[root@localhost HelloWorld]# rpm -qa | grep libOpenCL mesa-libOpenCL-11.1.0-5.20151218.fc21.loongson.6.mips64el mesa-libOpenCL-devel-11.1.0-5.20151218.fc21.loongson.6.mips64el
other info: [root@localhost HelloWorld]# llc -version LLVM (http://llvm.org/): LLVM version 3.8.1 Optimized build. Built Jul 8 2019 (07:52:07). Default target: mips64el-redhat-linux Host CPU: (unknown)
Registered Targets: amdgcn - AMD GCN GPUs bpf - BPF (host endian) bpfeb - BPF (big endian) bpfel - BPF (little endian) cpp - C++ backend mips - Mips mips64 - Mips64 [experimental] mips64el - Mips64el [experimental] mipsel - Mipsel nvptx - NVIDIA PTX 32-bit nvptx64 - NVIDIA PTX 64-bit r600 - AMD GPUs HD2XXX-HD6XXX systemz - SystemZ
[root@localhost HelloWorld]# llc -version LLVM (http://llvm.org/): LLVM version 3.8.1 Optimized build. Built Jul 8 2019 (07:52:07). Default target: mips64el-redhat-linux Host CPU: (unknown)
Registered Targets: amdgcn - AMD GCN GPUs bpf - BPF (host endian) bpfeb - BPF (big endian) bpfel - BPF (little endian) cpp - C++ backend mips - Mips mips64 - Mips64 [experimental] mips64el - Mips64el [experimental] mipsel - Mipsel nvptx - NVIDIA PTX 32-bit nvptx64 - NVIDIA PTX 64-bit r600 - AMD GPUs HD2XXX-HD6XXX systemz - SystemZ [root@localhost HelloWorld]# clinfo Number of platforms 1 Platform Name Clover Platform Vendor Mesa Platform Version OpenCL 1.1 MESA 11.1.0 Platform Profile FULL_PROFILE Platform Extensions cl_khr_icd Platform Extensions function suffix MESA
Platform Name Clover Number of devices 1 Device Name AMD CAICOS (DRM 2.49.0, LLVM 3.8.1) Device Vendor AMD Device Vendor ID 0x1002 Device Version OpenCL 1.1 MESA 11.1.0 Driver Version 11.1.0 Device OpenCL C Version OpenCL C 1.1 Device Type GPU Device Profile FULL_PROFILE Max compute units 2 Max clock frequency 775MHz Max work item dimensions 3 Max work item sizes 256x256x256 Max work group size 256 Preferred work group size multiple 64 Preferred / native vector sizes char 16 / 16 short 8 / 8 int 4 / 4 long 2 / 2 half 0 / 0 (n/a) float 4 / 4 double 0 / 0 (n/a) Half-precision Floating-point support (n/a) Single-precision Floating-point support (core) Denormals No Infinity and NANs Yes Round to nearest Yes Round to zero No Round to infinity No IEEE754-2008 fused multiply-add No Support is emulated in software No Correctly-rounded divide and sqrt operations No Double-precision Floating-point support (n/a) Address bits 32, Little-Endian Global memory size 1073741824 (1024MiB) Error Correction support No Max memory allocation 268435456 (256MiB) Unified memory for Host and Device Yes Minimum alignment for any data type 128 bytes Alignment of base address 1024 bits (128 bytes) Global Memory cache type None Image support No Local memory type Local Local memory size 32768 (32KiB) Max constant buffer size 268435456 (256MiB) Max number of constant args 13 Max size of kernel argument 1024 Queue properties Out-of-order execution No Profiling Yes Profiling timer resolution 0ns Execution capabilities Run OpenCL kernels Yes Run native kernels No Device Available Yes Compiler Available Yes Device Extensions cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store
NULL platform behavior clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) Clover clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) Success [MESA] clCreateContext(NULL, ...) [default] Success [MESA] clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) Success (1) Platform Name Clover Device Name AMD CAICOS (DRM 2.49.0, LLVM 3.8.1) clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) Success (1) Platform Name Clover Device Name AMD CAICOS (DRM 2.49.0, LLVM 3.8.1)
ICD loader properties ICD loader Name OpenCL ICD Loader ICD loader Vendor OCL Icd free software ICD loader Version 2.2.7 ICD loader Profile OpenCL 1.2