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
.
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);