Internal procedures cannot be called directly from outside the host procedure, so there is no point giving them external linkage. The only reason flang did is because it is the default in MLIR. Giving external linkage to them: - prevents deleting them when not used/inlined by LLVM - causes bugs with shared libraries (at least on linux x86-64) because the call to the internal function could lead to a dynamic loader call that would overwrite r10 register (the static chain pointer) due to system calls and did not restore (it seems it does not expect r10 to be used for PLT calls). This patch gives internal linkage to internal procedures: Note: the llvm.linkage attribute name cannot be obtained via a getLinkageAttrName since it is not the same name as the one used in the LLVM dialect. It is just a placeholder defined in mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp until the func dialect gets a real linkage model. So simply avoid hard coding it too many times in lowering.
40 lines
1.1 KiB
Fortran
40 lines
1.1 KiB
Fortran
! Test that module data access are lowered correctly in the different
|
|
! procedure contexts.
|
|
! RUN: bbc -emit-fir %s -o - | FileCheck %s
|
|
|
|
module parent
|
|
integer :: i
|
|
contains
|
|
! Test simple access to the module data
|
|
! CHECK-LABEL: func @_QMparentPtest1
|
|
subroutine test1()
|
|
! CHECK: fir.address_of(@_QMparentEi) : !fir.ref<i32>
|
|
print *, i
|
|
end subroutine
|
|
|
|
! Test access to the module data inside an internal procedure where the
|
|
! host is defined inside the module.
|
|
subroutine test2()
|
|
call test2internal()
|
|
contains
|
|
! CHECK-LABEL: func private @_QMparentFtest2Ptest2internal()
|
|
subroutine test2internal()
|
|
! CHECK: fir.address_of(@_QMparentEi) : !fir.ref<i32>
|
|
print *, i
|
|
end subroutine
|
|
end subroutine
|
|
end module
|
|
|
|
! Test access to the module data inside an internal procedure where the
|
|
! host is using the module.
|
|
subroutine test3()
|
|
use parent
|
|
call test3internal()
|
|
contains
|
|
! CHECK-LABEL: func private @_QFtest3Ptest3internal()
|
|
subroutine test3internal()
|
|
! CHECK: fir.address_of(@_QMparentEi) : !fir.ref<i32>
|
|
print *, i
|
|
end subroutine
|
|
end subroutine
|