https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119854
Bug ID: 119854 Summary: nvptx offloading: omptests' 'xt-declare-target-ctors': 'unresolved symbol __dso_handle' Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: openacc, openmp Severity: normal Priority: P3 Component: target 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, vries at gcc dot gnu.org Target Milestone: --- Target: nvptx For omptests' 'xt-declare-target-ctors' (<https://github.com/doru1004/omptests/blob/main/xt-declare-target-ctors/test.cpp>), nvptx offloading compilation currently fails due to: unresolved symbol __dso_handle collect2: error: ld returned 1 exit status nvptx mkoffload: fatal error: [...]/x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status GCN offloading compiles fine. I first thought GCN, via being 'OBJECT_FORMAT_ELF', would get a '__dso_handle' definition via 'libgcc/crtstuff.c': #ifdef OBJECT_FORMAT_ELF #if DEFAULT_USE_CXA_ATEXIT /* Declare the __dso_handle variable. It should have a unique value in every shared-object; in a main program its value is zero. The object should in any case be protected. This means the instance in one DSO or the main program is not used in another object. The dynamic linker takes care of this. If __cxa_atexit is not being used, __dso_handle will not be used and doesn't need to be defined. */ #ifdef TARGET_LIBGCC_SDATA_SECTION extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION))); #endif #ifdef HAVE_GAS_HIDDEN extern void *__dso_handle __attribute__ ((__visibility__ ("hidden"))); #endif #ifdef CRTSTUFFS_O void *__dso_handle = &__dso_handle; #else void *__dso_handle = 0; #endif #endif /* DEFAULT_USE_CXA_ATEXIT */ ..., but actually it doesn't, due to being '!DEFAULT_USE_CXA_ATEXIT'. (See PR119853 "GCN, nvptx: Review 'DEFAULT_USE_CXA_ATEXIT'".) Instead, it's via linker magic; running GCN offloading 'ld' with '--trace-symbol=__dso_handle': ./a.xamdgcn-amdhsa.mkoffload.hsaco-a.xamdgcn-amdhsa.mkoffload.2.o: reference to __dso_handle <internal>: definition of __dso_handle (The '__dso_handle'-using code is per 'DEFAULT_USE_CXA_ATEXIT' powerpc64le and x86_64 GNU/Linux host.)