我有一个c和c ++混合大代码,它被编译成静态库。我从给定程序中调用simgms静态库中的函数 - main.cpp很简单,但可执行文件不运行并抛出运行时错误Illegal指令。 gdb从第一行-inside main中的main()退出。
搜索问题暗示这可能是由于gcc版本或库与intel_mkl的不兼容。如果有人遇到类似的问题,欢迎提出建议。谢谢!
#include "simgms_scf.h"
#define c_version
#include <iostream>
int main()
{
double ex[] = {130.7093200, 23.8088610, 6.4436083, 5.0331513, 1.1695961, 0.3803890, 3.42525091, 0.62391373, 0.16885540 };
double cs[] = { 0.15432897, 0.53532814, 0.44463454, -0.09996723, 0.39951283, 0.70011547, 0.15591627, 0.60768372, 0.39195739};
double *cp = cs, *cd = cs, *cf = cs, *cg = cs, *ch = cs, *ci = cs;
.
.
.
simgms_scf_c(ex, numBFunc, numOccAlpha, 0, atomCoordinates, nuclearCharges, 0);
return 0;
}
(这个程序在windows / Visual Studio上没有问题。我移植并更改了代码以便在linux64上运行)
这是构建静态库simgms的值得注意的一步
%.o: ../%.cpp
@echo 'Building file: $<'
@echo 'Invoking: G++ Compiler'
g++ -Wall -mavx -g -O -O1 -std=c++11 -lgfortran -L/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/lib64 -libstdc -libsupc++ -libtsan -libubsan -libvtv -libquadmath -libgcc_s -libgcj -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -lmkl_mc -lmkl_sequential -lmkl_gf_ilp64 -lmkl_avx -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core -L/home/..mypath/simint/lib -lsimint -I/opt/intel/composer_xe_2013.5.192/mkl/include -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -I/home/..mypath/simint/include -I/home/..mypath/include/simint/debug -DDEBUG -DMKL_ILP64 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -c -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
%.o: ../%.c
@echo 'Building file: $<'
@echo 'Invoking: GCC Compiler'
gcc -Wall -mavx -g -O -O1 -lgfortran -L/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/lib64 -libstdc -libsupc++ -libtsan -libubsan -libvtv -libquadmath -libgcc_s -libgcj -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -lmkl_mc -lmkl_sequential -lmkl_gf_ilp64 -lmkl_avx -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core -L/home/..mypath/simint/lib -lsimint -I/opt/intel/composer_xe_2013.5.192/mkl/include -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -I/home/..mypath/simint/include -I/home/..mypath/include/simint/debug -DDEBUG -DMKL_ILP64 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -c -o "$@" "$<"
@echo 'Finished building:
$<' @echo ' '
以下是我如何从main.cpp
创建主要可执行文件 gcc -Wall -mavx -g -O -O1 -o main -lgfortran ../main.cpp -L/home/..mypath/Debug -lsimgms -L/home/..mypath/simint -lsimint -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -lmkl_mc -lmkl_sequential -lmkl_gf_ilp64 -lmkl_avx -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core -I/home/..mypath/simint -I/home/..mypath/include -I/opt/intel/composer_xe_2013.5.192/mkl/include -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -lpthread -lm -ldl
这是gdb跟踪(我能得到什么)
(gdb) bt main
No stack.
(gdb) b main
Breakpoint 1 at 0x401906: file ../main.cpp, line 12.
(gdb) run
Starting program: /home/...mypah/simgms/Debug/main
Breakpoint 1, main () at ../main.cpp:12
12 {
(gdb) step
15 double ex[] = {130.7093200, 23.8088610, 6.4436083, 5.0331513, 1.1695961, 0.3803890, 3.42525091, 0.62391373, 0.16885540 };
(gdb) step
Program received signal SIGILL, Illegal instruction.
main () at ../main.cpp:15
15 double ex[] = {130.7093200, 23.8088610, 6.4436083, 5.0331513, 1.1695961, 0.3803890, 3.42525091, 0.62391373, 0.16885540 };
汇编代码转储
Breakpoint 1, 0x0000000000401906 in main ()
(gdb) info line 1
Line number 1 is out of range for "<built-in>".
(gdb) disassemble /m
Dump of assembler code for function main:
=> 0x0000000000401906 <+0>: sub $0x1d8,%rsp
0x000000000040190d <+7>: vmovsd 0x5b613(%rip),%xmm1 # 0x45cf28
0x0000000000401915 <+15>: vmovsd %xmm1,0x180(%rsp)
0x000000000040191e <+24>: vmovsd 0x5b60a(%rip),%xmm2 # 0x45cf30
0x0000000000401926 <+32>: vmovsd %xmm2,0x188(%rsp)
0x000000000040192f <+41>: vmovsd 0x5b601(%rip),%xmm3 # 0x45cf38
0x0000000000401937 <+49>: vmovsd %xmm3,0x190(%rsp)
0x0000000000401940 <+58>: vmovsd 0x5b5f8(%rip),%xmm4 # 0x45cf40
0x0000000000401948 <+66>: vmovsd %xmm4,0x198(%rsp)
0x0000000000401951 <+75>: vmovsd 0x5b5ef(%rip),%xmm5 # 0x45cf48
0x0000000000401959 <+83>: vmovsd %xmm5,0x1a0(%rsp)
0x0000000000401962 <+92>: vmovsd 0x5b5e6(%rip),%xmm6 # 0x45cf50
0x000000000040196a <+100>: vmovsd %xmm6,0x1a8(%rsp)
0x0000000000401973 <+109>: vmovsd 0x5b5dd(%rip),%xmm7 # 0x45cf58
0x000000000040197b <+117>: vmovsd %xmm7,0x1b0(%rsp)
0x0000000000401984 <+126>: vmovsd 0x5b5d4(%rip),%xmm1 # 0x45cf60
0x000000000040198c <+134>: vmovsd %xmm1,0x1b8(%rsp)
0x0000000000401995 <+143>: vmovsd 0x5b5cb(%rip),%xmm2 # 0x45cf68
0x000000000040199d <+151>: vmovsd %xmm2,0x1c0(%rsp)
0x00000000004019a6 <+160>: vmovsd 0x5b5c2(%rip),%xmm3 # 0x45cf70
0x00000000004019ae <+168>: vmovsd %xmm3,0x130(%rsp)
0x00000000004019b7 <+177>: vmovsd 0x5b5b9(%rip),%xmm4 # 0x45cf78
0x00000000004019bf <+185>: vmovsd %xmm4,0x138(%rsp)
0x00000000004019c8 <+194>: vmovsd 0x5b5b0(%rip),%xmm5 # 0x45cf80
0x00000000004019d0 <+202>: vmovsd %xmm5,0x140(%rsp)
0x00000000004019d9 <+211>: vmovsd 0x5b5a7(%rip),%xmm6 # 0x45cf88
0x00000000004019e1 <+219>: vmovsd %xmm6,0x148(%rsp)
0x00000000004019ea <+228>: vmovsd 0x5b59e(%rip),%xmm7 # 0x45cf90
0x00000000004019f2 <+236>: vmovsd %xmm7,0x150(%rsp)
0x00000000004019fb <+245>: vmovsd 0x5b595(%rip),%xmm1 # 0x45cf98
0x0000000000401a03 <+253>: vmovsd %xmm1,0x158(%rsp)
0x0000000000401a0c <+262>: vmovsd 0x5b58c(%rip),%xmm2 # 0x45cfa0
0x0000000000401a14 <+270>: vmovsd %xmm2,0x160(%rsp)
0x0000000000401a1d <+279>: vmovsd 0x5b583(%rip),%xmm3 # 0x45cfa8
0x0000000000401a25 <+287>: vmovsd %xmm3,0x168(%rsp)
0x0000000000401a2e <+296>: vmovsd 0x5b57a(%rip),%xmm4 # 0x45cfb0
0x0000000000401a36 <+304>: vmovsd %xmm4,0x170(%rsp)
0x0000000000401a3f <+313>: movq $0x1,0x100(%rsp)
0x0000000000401a4b <+325>: movq $0x1,0x108(%rsp)
0x0000000000401a57 <+337>: movq $0x1,0x110(%rsp)
0x0000000000401a63 <+349>: movq $0x2,0x118(%rsp)
0x0000000000401a6f <+361>: movq $0x2,0x120(%rsp)
0x0000000000401a7b <+373>: movq $0x2,0x128(%rsp)
0x0000000000401a87 <+385>: movq $0x1,0xd0(%rsp)
0x0000000000401a93 <+397>: movq $0x1,0xd8(%rsp)
0x0000000000401a9f <+409>: movq $0x4,0xe0(%rsp)
0x0000000000401aab <+421>: movq $0x4,0xe8(%rsp)
0x0000000000401ab7 <+433>: movq $0x7,0xf0(%rsp)
0x0000000000401ac3 <+445>: movq $0x7,0xf8(%rsp)
0x0000000000401acf <+457>: movq $0x1,0xa0(%rsp)
0x0000000000401adb <+469>: movq $0x1,0xa8(%rsp)
0x0000000000401ae7 <+481>: movq $0x2,0xb0(%rsp)
0x0000000000401af3 <+493>: movq $0x2,0xb8(%rsp)
0x0000000000401aff <+505>: movq $0x1,0xc0(%rsp)
0x0000000000401b0b <+517>: movq $0x1,0xc8(%rsp)
0x0000000000401b17 <+529>: movq $0xd,0x70(%rsp)
0x0000000000401b20 <+538>: movq $0x0,0x78(%rsp)
---Type <return> to continue, or q <return> to quit---
0x0000000000401b29 <+547>: movq $0x0,0x80(%rsp)
0x0000000000401b35 <+559>: movq $0x0,0x88(%rsp)
0x0000000000401b41 <+571>: movq $0x0,0x90(%rsp)
0x0000000000401b4d <+583>: movq $0x0,0x98(%rsp)
0x0000000000401b59 <+595>: movq $0x3,0x40(%rsp)
0x0000000000401b62 <+604>: movq $0x3,0x48(%rsp)
0x0000000000401b6b <+613>: movq $0x3,0x50(%rsp)
0x0000000000401b74 <+622>: movq $0x3,0x58(%rsp)
0x0000000000401b7d <+631>: movq $0x3,0x60(%rsp)
0x0000000000401b86 <+640>: movq $0x3,0x68(%rsp)
0x0000000000401b8f <+649>: vxorpd %xmm0,%xmm0,%xmm0
0x0000000000401b93 <+653>: vmovsd %xmm0,0x10(%rsp)
0x0000000000401b99 <+659>: vmovsd 0x5b417(%rip),%xmm5 # 0x45cfb8
0x0000000000401ba1 <+667>: vmovsd %xmm5,0x18(%rsp)
0x0000000000401ba7 <+673>: vmovsd %xmm0,0x20(%rsp)
0x0000000000401bad <+679>: vmovsd 0x5b40b(%rip),%xmm6 # 0x45cfc0
0x0000000000401bb5 <+687>: vmovsd %xmm6,0x28(%rsp)
0x0000000000401bbb <+693>: vmovsd 0x5b405(%rip),%xmm7 # 0x45cfc8
0x0000000000401bc3 <+701>: vmovsd %xmm7,0x30(%rsp)
0x0000000000401bc9 <+707>: vmovsd %xmm0,0x38(%rsp)
0x0000000000401bcf <+713>: vmovsd 0x5b3f9(%rip),%xmm1 # 0x45cfd0
0x0000000000401bd7 <+721>: vmovsd %xmm1,(%rsp)
0x0000000000401bdc <+726>: vmovsd 0x5b3f4(%rip),%xmm2 # 0x45cfd8
0x0000000000401be4 <+734>: vmovsd %xmm2,0x8(%rsp)
0x0000000000401bea <+740>: lea 0x130(%rsp),%rsi
0x0000000000401bf2 <+748>: push %rsp
0x0000000000401bf3 <+749>: lea 0x18(%rsp),%rax
0x0000000000401bf8 <+754>: push %rax
0x0000000000401bf9 <+755>: pushq $0x0
0x0000000000401bfb <+757>: pushq $0x4
0x0000000000401bfd <+759>: pushq $0x6
0x0000000000401bff <+761>: pushq $0x1
0x0000000000401c01 <+763>: pushq $0x6
0x0000000000401c03 <+765>: lea 0xa8(%rsp),%rax
0x0000000000401c0b <+773>: push %rax
0x0000000000401c0c <+774>: lea 0x80(%rsp),%rax
0x0000000000401c14 <+782>: push %rax
0x0000000000401c15 <+783>: lea 0xe8(%rsp),%rax
0x0000000000401c1d <+791>: push %rax
0x0000000000401c1e <+792>: lea 0x150(%rsp),%rax
0x0000000000401c26 <+800>: push %rax
0x0000000000401c27 <+801>: lea 0x128(%rsp),%rax
0x0000000000401c2f <+809>: push %rax
0x0000000000401c30 <+810>: push %rsi
0x0000000000401c31 <+811>: push %rsi
0x0000000000401c32 <+812>: mov %rsi,%r9
0x0000000000401c35 <+815>: mov %rsi,%r8
0x0000000000401c38 <+818>: mov %rsi,%rcx
0x0000000000401c3b <+821>: mov %rsi,%rdx
0x0000000000401c3e <+824>: lea 0x1f0(%rsp),%rdi
0x0000000000401c46 <+832>: callq 0x401caa <simgms_scf_c>
0x0000000000401c4b <+837>: mov $0x0,%eax
0x0000000000401c50 <+842>: add $0x248,%rsp
0x0000000000401c57 <+849>: retq
End of assembler dump.
(gdb)
崩溃后的汇编程序转储:
Program received signal SIGILL, Illegal instruction.
0x000000000040190d in main ()
(gdb) disassemble /m
Dump of assembler code for function main:
0x0000000000401906 <+0>: sub rsp,0x1d8
=> 0x000000000040190d <+7>: vmovsd xmm1,QWORD PTR [rip+0x5b613] # 0x45cf28
0x0000000000401915 <+15>: vmovsd QWORD PTR [rsp+0x180],xmm1
0x000000000040191e <+24>: vmovsd xmm2,QWORD PTR [rip+0x5b60a] # 0x45cf30
0x0000000000401926 <+32>: vmovsd QWORD PTR [rsp+0x188],xmm2
0x000000000040192f <+41>: vmovsd xmm3,QWORD PTR [rip+0x5b601] # 0x45cf38
0x0000000000401937 <+49>: vmovsd QWORD PTR [rsp+0x190],xmm3
0x0000000000401940 <+58>: vmovsd xmm4,QWORD PTR [rip+0x5b5f8] # 0x45cf40
0x0000000000401948 <+66>: vmovsd QWORD PTR [rsp+0x198],xmm4
0x0000000000401951 <+75>: vmovsd xmm5,QWORD PTR [rip+0x5b5ef] # 0x45cf48
0x0000000000401959 <+83>: vmovsd QWORD PTR [rsp+0x1a0],xmm5
0x0000000000401962 <+92>: vmovsd xmm6,QWORD PTR [rip+0x5b5e6] # 0x45cf50
0x000000000040196a <+100>: vmovsd QWORD PTR [rsp+0x1a8],xmm6
0x0000000000401973 <+109>: vmovsd xmm7,QWORD PTR [rip+0x5b5dd] # 0x45cf58
0x000000000040197b <+117>: vmovsd QWORD PTR [rsp+0x1b0],xmm7
0x0000000000401984 <+126>: vmovsd xmm1,QWORD PTR [rip+0x5b5d4] # 0x45cf60
0x000000000040198c <+134>: vmovsd QWORD PTR [rsp+0x1b8],xmm1
0x0000000000401995 <+143>: vmovsd xmm2,QWORD PTR [rip+0x5b5cb] # 0x45cf68
0x000000000040199d <+151>: vmovsd QWORD PTR [rsp+0x1c0],xmm2
0x00000000004019a6 <+160>: vmovsd xmm3,QWORD PTR [rip+0x5b5c2] # 0x45cf70
0x00000000004019ae <+168>: vmovsd QWORD PTR [rsp+0x130],xmm3
0x00000000004019b7 <+177>: vmovsd xmm4,QWORD PTR [rip+0x5b5b9] # 0x45cf78
0x00000000004019bf <+185>: vmovsd QWORD PTR [rsp+0x138],xmm4
0x00000000004019c8 <+194>: vmovsd xmm5,QWORD PTR [rip+0x5b5b0] # 0x45cf80
0x00000000004019d0 <+202>: vmovsd QWORD PTR [rsp+0x140],xmm5
0x00000000004019d9 <+211>: vmovsd xmm6,QWORD PTR [rip+0x5b5a7] # 0x45cf88
0x00000000004019e1 <+219>: vmovsd QWORD PTR [rsp+0x148],xmm6
0x00000000004019ea <+228>: vmovsd xmm7,QWORD PTR [rip+0x5b59e] # 0x45cf90
0x00000000004019f2 <+236>: vmovsd QWORD PTR [rsp+0x150],xmm7
0x00000000004019fb <+245>: vmovsd xmm1,QWORD PTR [rip+0x5b595] # 0x45cf98
0x0000000000401a03 <+253>: vmovsd QWORD PTR [rsp+0x158],xmm1
0x0000000000401a0c <+262>: vmovsd xmm2,QWORD PTR [rip+0x5b58c] # 0x45cfa0
答案 0 :(得分:3)
您在第一条AVX指令(SIGILL
)上使用vmovsd
编程崩溃。这意味着您的硬件,管理程序或内核不支持AVX。如果您的硬件支持AVX,您可以通过软件升级(虚拟机管理程序和内核)使其工作。如果您使用虚拟化,则可能必须指示管理程序也将AVX支持传递给guest虚拟机。 (最近足够的内核会自动支持AVX。)