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

--- Comment #6 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
(In reply to Iain Sandoe from comment #4)
> Whether this is a back-end fault or perhaps a constraint of darwin not
> present for binutils-ld I cannot tell immediately and would welcome input
> from the Fortran maintainers as to the decoration intended for the indirect
> reference produced for c_funloc (defined_function).

Iain, I am willing to help there but do not understand exactly what you are
asking for. Below is a short explanation of what the Fortran front-end is
trying to do.

Let's take this code, which compiles fine on darwin:

module foo
contains
  subroutine bar
    use, intrinsic :: iso_c_binding
    call gee(c_funloc(gee))
  end subroutine
  subroutine gee(f)
    use, intrinsic :: iso_c_binding
    type(c_funptr), value :: f
  end subroutine 
end module foo

Here GEE takes as single argument a function pointer, and has no return type.
The code in BAR is equivalent to calling gee, with its own address as argument.


Now, the second case passes the GEE argument by reference:

module foo
contains
  subroutine bar
    use, intrinsic :: iso_c_binding
    call gee(c_funloc(gee))
  end subroutine
  subroutine gee(f)
    use, intrinsic :: iso_c_binding
    type(c_funptr) :: f
  end subroutine 
end module foo

This generates the linker error:

ld: illegal text-relocation to '___foo_MOD_gee' in a.o from 'anon' in a.o for
architecture x86_64

If you look at the tree dump (-fdump-tree-original), you can see that instead
of being just:

bar () { gee(gee); }

in the previous case, it now uses a temporary variable to pass by reference:

bar ()
{
  static void (*<T618>) (void (*<T68>) (void) & restrict) C.2324 = gee;
  gee (&C.2324);
}



Let me know what else I can do to help solve this.

Reply via email to