动态库中的 OpenMP 卸载无法编译

OpenMP offloading in a dynamic library fails to compile

我想用 OpenMP 卸载编译 C 代码并创建一个动态库 libtest.so。 当我使用以下命令时:

gcc -fPIC -shared -fopenmp -foffload=nvptx-none="-fPIC" test.c -o libtest.so

我收到这个错误:

/usr/bin/ld: /tmp/ccWnqb5o.target.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status

GCC 版本为 10.2.0。 我不确定我在这里做错了什么,因为 -fPIC 包含在命令中。我想知道是否可以做我想做的事?

我的 test.c 来源只是检查卸载是否有效:

#include <omp.h>
#include <stdio.h>

void test()
{
  #pragma omp target teams
  {
    if (omp_is_initial_device())
      printf("on host\n");
    else
      printf("on target device\n");
  }
}

我与 GCC 开发人员交谈过,这似乎是一个错误。他们似乎已经为 GCC 11 解决了这个问题,但是这个修复没有向后移植。有关详细信息,请参阅 https://gcc.gnu.org/g:a8b522311beef5e02de15427e924752ea02def2a