摘要:当我-mcmodel=large
在使用clang编译时设置标志时,我的应用程序在访问线程本地存储时出现段错误。使用 gcc 编译时不会发生这种情况。这是clang的错误还是我做错了什么?
详情:
以下代码段在设置-mcmodel
标志时使用clang编译时崩溃,但使用gcc编译时运行良好
#include <stdio.h>
#include <pthread.h>
__thread int tlsTest;
int main(int argc, char **argv) {
printf("&tlsTest is %p\n", &tlsTest);
tlsTest = argc;
printf("tlsTest is %d\n", tlsTest);
return 0;
}
当我编译时:clang test.c -pthread -mcmodel=large
结果是:
&tlsTest is 0x7fd24262c6fc
Segmentation fault (core dumped)
但是:gcc test.c -pthread -mcmodel=large
结果是:
&tlsTest is 0x7f1cf785c6fc
tlsTest is 1
该程序在编译时也可以正常工作:clang test.c -pthread
我阅读了有关 mcmodel的以下链接,但我不确定这与我观察到的段错误有何关系。请注意,问题也会发生-mcmodel=medium
,但不会发生-mcmodel=small
。
这是 clang/llvm 的错误,还是对标准或某些未实现功能的不同解释?
我的系统也是 Ubuntu 12.04。我的gcc版本是4.6.3,我测试的clang/llvm版本是3.3开发的最新快照,我也用clang 3.2测试过。