Linux 용 Windows 하위 시스템의 GNU Fortran 컴파일러-내부 함수를 다른 프로 시저로 전달하는 데 따른 분할 오류 [중복]

Nov 29 2020

다음은 유효한 Fortran 2008 프로그램이며 Intel 및 GNU Fortran 컴파일러가 모두있는 정품 macOS, Linux 및 Windows 운영 체제에서 제대로 작동한다고 생각합니다.

module InternalFuncCaller_mod
    implicit none
    abstract interface 
        function getInternalFunc_proc(input) result(output)
            implicit none
            real, intent(in)    :: input
            real                :: output
        end function getInternalFunc_proc
    end interface
contains
    subroutine callInternalFunc(getInternalFunc, x)
        implicit none
        procedure(getInternalFunc_proc) :: getInternalFunc
        real, intent(in)                :: x
        write(*,*) getInternalFunc(x)
    end subroutine callInternalFunc
end module InternalFuncCaller_mod

module InternalFunc_mod
    implicit none
contains
    subroutine passInternalFunc()
        use InternalFuncCaller_mod, only: callInternalFunc
        implicit none
        call callInternalFunc(getThisInternalFunc, x = 4.)
    contains
        function getThisInternalFunc(x) result(sqrtx)
            implicit none
            real, intent(in)    :: x
            real                :: sqrtx
            sqrtx = sqrt(x)
        end function getThisInternalFunc
    end subroutine passInternalFunc
end module InternalFunc_mod

program testInternalFuncCall
    use InternalFunc_mod
    implicit none
    call passInternalFunc()
    write(*,*) "Done."
end program testInternalFuncCall

그러나 Linux 용 Windows 하위 시스템 (WSL) (Ubuntu)에서 GFortran으로 컴파일하고 실행하면 다음과 같은 SegFault 오류 메시지가 표시됩니다.

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0  0x7ffb84580d3a
#1  0x7ffb8457fed5
#2  0x7ffb843a620f
#3  0x7fffde946cb0
Segmentation fault (core dumped)

외부 프로 시저에 의한 내부 함수 호출에 대한 문제를 추적했습니다. 그러나 동일한 코드가 다른 Fortran 컴파일러를 사용하는 다른 모든 운영 체제에서 잘 작동합니다. 따라서 이것은 GNU GFortran의 버그가 아닌 것으로 보이지만 특히 WSL OS에서 다른 프로 시저의 내부 프로 시저에 대한 외부 호출을 포함하는 코드의 정적 컴파일 및 실행 문제 일 가능성이 높습니다.

더 많은 정보를 제공하기 위해 라이브러리가 공유 라이브러리로 빌드 될 때 (내부 함수 호출에도 불구하고) 제대로 작동한다는 것을 알았습니다. 그러나 정적 라이브러리를 컴파일 할 때 동일한 오류 메시지와 함께 실패합니다.

따라서 일부 GFortran 플래그의 조합이 어떻게 든 오류 ( -fPIC -shared)를 해결할 수있는 것 같습니다 . 이 문제를 해결하는 방법에 대한 도움을 주시면 감사하겠습니다.

답변

3 Rob Nov 30 2020 at 09:25

내부 함수를 인수로 전달할 때 분할 오류에 문제가있는 사람이 WSL 버전 2로 이동하면 문제가 해결되는 것으로 나타났습니다.