https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112858

--- Comment #5 from Thomas Schwinge <tschwinge at gcc dot gnu.org> ---
(I did see that the '__cxa_thread_atexit_impl' issue has been resolved
differently, but there is a genuine GCC/nvptx issue here.)

(In reply to myself from comment #1)
> Indeed in 'build-gcc/nvptx-none/libstdc++-v3/libsupc++/atexit_thread.o' I
> see:
> 
>     // BEGIN GLOBAL FUNCTION DECL: __cxa_thread_atexit_impl
>     .extern .func (.param .u32 %value_out) __cxa_thread_atexit_impl (.param
> .u64 %in_ar0, .param .u64 %in_ar1, .param .u64 %in_ar2);
> 
> That is, '.extern' instead of '.weak' linking directive, huh.

That one indeed is a GCC/nvptx back end issue.  A fix might look similar to the
following:

    --- gcc/config/nvptx/nvptx.cc
    +++ gcc/config/nvptx/nvptx.cc
    @@ -1001,10 +1001,11 @@ write_fn_proto_1 (std::stringstream &s, bool
is_defn,
                      const char *name, const_tree decl, bool force_public)
     {
    -  if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) == NULL)
    +  if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) == NULL
    +      && !DECL_WEAK (decl))
         write_fn_marker (s, is_defn, TREE_PUBLIC (decl) || force_public,
name);

       /* PTX declaration.  */
       if (DECL_EXTERNAL (decl))
    -    s << ".extern ";
    +    s << (DECL_WEAK (decl) ? ".weak " : ".extern ");
       else if (TREE_PUBLIC (decl) || force_public)
         s << (DECL_WEAK (decl) ? ".weak " : ".visible ");

> ..., but still doing the NULL check: [...]

..., and that check ('if (__cxa_thread_atexit_impl)') then fails to assemble,
and thus the build (!) fails:

    ptxas fatal   : Cannot take address of function '__cxa_thread_atexit_impl' 

Thus, more smarts are needed to make "weak, undefined" work.  (May be able to
fix this up in the linker, assuming seeing the whole program; similar to
PR105018 "[nvptx] Need better alias support" ideas?)  (For reference, "weak,
defined" does not run into this problem.)

Reply via email to