nvcc(cuda8,gcc 5.3)在Ubuntu 22.04上不再支持使用 -O1 编译。

huangapple go评论73阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月22日 19:35:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76531467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定