https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106487
Bug ID: 106487 Summary: Calls to ___builtin_nested_func_ptr_created that cannot be resolved on M1 (Apple silicon) Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: apersaud at lbl dot gov Target Milestone: --- I'm trying to compile a program (not public available) on an M1 and am running in an issue where the linker is complaining about unknown functions U ___builtin_nested_func_ptr_created U ___builtin_nested_func_ptr_deleted I'm using: > gfortran-12 --version GNU Fortran (Homebrew GCC 12.1.0_1) 12.1.0 [...] Since I cannot share the source code. I tried to reduce it to a small program: """ MODULE focus IMPLICIT NONE PRIVATE PUBLIC myinit ABSTRACT INTERFACE REAL(kind=8) FUNCTION dummyf(x) REAL(kind=8), INTENT(IN) :: x END FUNCTION dummyf end INTERFACE CONTAINS SUBROUTINE myfun(fun, x, res) ! return res = fun(x) IMPLICIT NONE PROCEDURE(dummyf) :: fun REAL(kind=8), INTENT(INOUT) :: x INTEGER, INTENT(OUT) :: res res = fun(x) end SUBROUTINE myfun SUBROUTINE myinit() IMPLICIT NONE INTEGER :: its, nfcalls REAL(kind=8) :: ftv CALL myfun(internal_func, ftv, its) CONTAINS FUNCTION internal_func(fv) IMPLICIT NONE REAL(kind=8), INTENT(IN) :: fv REAL(kind=8) :: internal_func !internal_func = nfcalls ! create links to ___builtin_nested_func_ptr_created internal_func = 111 ! this works END FUNCTION internal_func END SUBROUTINE myinit END MODULE focus """ The problem seems to be the function definition in the contains block of a subroutine. However, if this is not working on the M1, I would have expected some kind of warning or error message, but the file compiles OK and only fails in a later linker stage when the two mentioned functions cannot be found. The command I used to compile was "gfortran-12 -m64 -O2 -c input.f95" When I comment out the "internal_func = nfcalls" line and uncomment the following line, the compiler does not link to these two functions (this only works with the -O2 flag enabled though, so it probably just inlines the function calls and therefore there is no CONTAINS block anymore?) I'm not that familiar with fortran/gfortran...Not sure if this can/should be fixed, but I thought I report it.