https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119806
Bug ID: 119806 Summary: OpenACC, OpenMP 'target' offloading vs. C++ 'typeinfo' parts Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: openacc, openmp, wrong-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tschwinge at gcc dot gnu.org CC: burnus at gcc dot gnu.org, jakub at gcc dot gnu.org Target Milestone: --- Target: GCN, nvptx We've got cases of C++ OpenACC, OpenMP 'target' offloading code (XFAILed test case soon to appear), where nvptx offloading linking fails due to: ptxas ./exceptions-throw-2.xnvptx-none.mkoffload.o, line 23; fatal : Initial value type mismatch ptxas fatal : Ptx assembly aborted due to errors nvptx-as: ptxas returned 255 exit status nvptx mkoffload: fatal error: [...]/powerpc64le-unknown-linux-gnu-accel-nvptx-none-gcc returned 1 exit status It's complaining about: // BEGIN GLOBAL VAR DEF: _ZTI11MyException .weak .global .align 8 .u64 _ZTI11MyException[2] = { generic(_ZTVN10__cxxabiv117__class_type_infoE) + 16, generic(_ZTS11MyException) }; The players here are: $ c++filt _ZTI11MyException _ZTVN10__cxxabiv117__class_type_infoE _ZTS11MyException typeinfo for MyException vtable for __cxxabiv1::__class_type_info typeinfo name for MyException ..., but '_ZTVN10__cxxabiv117__class_type_infoE' and '_ZTS11MyException' aren't getting declared in this file. This issue bears some relation to PR119734 "nvptx/C++ vs. '_ZTISt8bad_cast' ('typeinfo for std::bad_cast')", as again, '_ZTI11MyException' is only being "referenced" within: /* BEGIN '.gcc_except_table' [...] .symbol_ref _ZTI11MyException END '.gcc_except_table' */ It would be good if there was a way to not emit that '.extern' '_ZTI11MyException' definition if only (fake-)referenced like this. Here, '_ZTVN10__cxxabiv117__class_type_infoE' comes from libstdc++ (via definition in libsupc++'s 'class_type_info.o'), and '_ZTS11MyException' would come from the user source code -- but isn't getting defined in this file. In contrast, the respective non-offloading, nvptx target test case (to appear soon), gets this right, includes the 'vtable for __cxxabiv1::__class_type_info' declaration: // BEGIN GLOBAL VAR DECL: _ZTVN10__cxxabiv117__class_type_infoE .extern .global .align 8 .u64 _ZTVN10__cxxabiv117__class_type_infoE[]; ..., and includes the 'typeinfo name for MyException' definition: // BEGIN GLOBAL VAR DEF: _ZTS11MyException .weak .global .align 1 .u8 _ZTS11MyException[14] = { 49, 49, 77, 121, 69, 120, 99, 101, 112, 116, 105, 111, 110, 0 }; ..., and assembles, links, executes as expected. I suspect that we simply fail to mark up these C++ 'typeinfo' parts to be emitted for offloading compilation? (Via 'omp declare target' attribute, set 'offloadable' on 'symtab_node', push into 'offload_vars'?) Quite similarly, GCN offloading linking fails due to: ld: error: undefined symbol: typeinfo name for MyException >>> referenced by ./exceptions-throw-2.xamdgcn-amdhsa.mkoffload.hsaco-exceptions-throw-2.xamdgcn-amdhsa.mkoffload.2.o:(typeinfo for MyException) >>> did you mean: typeinfo for MyException >>> defined in: ./exceptions-throw-2.xamdgcn-amdhsa.mkoffload.hsaco-exceptions-throw-2.xamdgcn-amdhsa.mkoffload.2.o collect2: error: ld returned 1 exit status gcn mkoffload: fatal error: [...]/x86_64-pc-linux-gnu-accel-amdgcn-amdhsa-gcc returned 1 exit status As above, that's: .weak _ZTI11MyException .section .data.rel.ro._ZTI11MyException,"awG",@progbits,_ZTI11MyException,comdat .align 8 .type _ZTI11MyException, @object .size _ZTI11MyException, 16 _ZTI11MyException: .8byte _ZTVN10__cxxabiv117__class_type_infoE+16 .8byte _ZTS11MyException ..., which also here is only referenced from '.fake_gcc_except_table': .section .fake_gcc_except_table,"e",@progbits [...] .8byte _ZTI11MyException As above, the players here are: $ c++filt _ZTI11MyException _ZTVN10__cxxabiv117__class_type_infoE _ZTS11MyException typeinfo for MyException vtable for __cxxabiv1::__class_type_info typeinfo name for MyException As above, '_ZTVN10__cxxabiv117__class_type_infoE' comes from libstdc++ (via definition in libsupc++'s 'class_type_info.o'), and '_ZTS11MyException' would come from the user source code, but isn't getting defined in this file. As above, in contrast, the respective non-offloading, GCN target test case (to appear soon), gets this right, (doesn't need a 'vtable for __cxxabiv1::__class_type_info' declaration, but) includes the 'typeinfo name for MyException' definition: .weak _ZTS11MyException .section .rodata._ZTS11MyException,"aG",@progbits,_ZTS11MyException,comdat .align 16 .type _ZTS11MyException, @object .size _ZTS11MyException, 14 _ZTS11MyException: .string "11MyException" ..., and assembles, links, executes as expected. So I suspect it's the very same underlying issue.