英文:
nvcc (cuda8, gcc 5.3) no longer compiles with -O1 on Ubuntu 22.04
问题
我有一个在Ubuntu 22.04上编译良好的CUDA-8
程序(使用nvcc
编译),距今7个月,遵循此过程,底层编译器为gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413
。
在我(不确定是何时)升级了Ubuntu 22上的一些软件包后,该程序现在只能在将优化标志设置为-O0
时才能编译。
具有文件test.cpp
的最小复现:
int
main(int argc, char* argv[]) {
return 1;
}
然后运行:
/opt/cuda-8.0/bin/nvcc -w --use_fast_math -Wno-deprecated-gpu-targets -O0 -x cu -c test.cpp
可以成功编译!
/opt/cuda-8.0/bin/nvcc -w --use_fast_math -Wno-deprecated-gpu-targets -O1 -x cu -c test.cpp
/usr/include/x86_64-linux-gnu/bits/string_fortified.h(104): error: identifier "__builtin___stpncpy_chk" 未定义
7个月前,两个变体都能正常工作。
我想问一下,是否有办法通过修改文件string_fortified.h
来解决这个问题。
英文:
I have a CUDA-8
program which compiled (nvcc
) well 7 months ago on Ubuntu 22.04, following this procedure, the underlying compiler being gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413
.
After (not sure when) I upgraded some packages on Ubuntu 22, the program now only compiles if the optimization flag is set to -O0
.
The minimal reproducer with file test.cpp
:
int
main(int argc, char* argv[]) {
return 1;
}
And then run:
/opt/cuda-8.0/bin/nvcc -w --use_fast_math -Wno-deprecated-gpu-targets -O0 -x cu -c test.cpp
Compiles fine!
/opt/cuda-8.0/bin/nvcc -w --use_fast_math -Wno-deprecated-gpu-targets -O1 -x cu -c test.cpp
/usr/include/x86_64-linux-gnu/bits/string_fortified.h(104): error: identifier "__builtin___stpncpy_chk" is undefined
7 months ago, both variants worked fine.
I wanted to ask if there is something that can be done to fix this issue by amending the file string_fortified.h
.
答案1
得分: 0
根据这个错误报告评论中的提示(感谢Siddesh!),我提出了以下对string_fortified.h头文件的修改,解决了这个问题(每当您的软件包管理器更新此头文件时,您需要手动重新编辑):
# if (__GNUC_PREREQ (4, 7) && (!defined(CUDART_VERSION) || CUDART_VERSION>8000)) || __glibc_clang_prereq (2, 6)
__fortify_function char *
__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
{
return __builtin___stpncpy_chk (__dest, __src, __n,
__glibc_objsize (__dest));
}
# else
extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
size_t __destlen) __THROW
__fortified_attr_access (__write_only__, 1, 3)
__attr_access ((__read_only__, 2));
extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
size_t __n), stpncpy);
# endif
英文:
Based on the hint in this bug report comment (thanks Siddesh!), I came up with the following modification of the string_fortified.h header that solves the problem (you need to re-edit by hand every time this header is updated by your package manager):
# if (__GNUC_PREREQ (4, 7) && (!defined(CUDART_VERSION) || CUDART_VERSION>8000)) || __glibc_clang_prereq (2, 6)
__fortify_function char *
__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
{
return __builtin___stpncpy_chk (__dest, __src, __n,
__glibc_objsize (__dest));
}
# else
extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
size_t __destlen) __THROW
__fortified_attr_access (__write_only__, 1, 3)
__attr_access ((__read_only__, 2));
extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
size_t __n), stpncpy);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论