llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Linker missing `_FortranACopyInAssign`

Open tukss opened this issue 2 years ago • 4 comments

Compiling this simple reproducer code (the real example called DGEMM) produces an undefined reference to _FortranACopyInAssign. I'm using flang-new from the current main branch.

program atest
  implicit none

  real(8) :: a(2)

  call ar(a)

contains

  subroutine br(x)
    implicit none
    real(8) :: x(*)
  end subroutine br
  
  subroutine ar(d)
    implicit none
    real(8) :: d(:)
    call br(d)
    
  end subroutine ar
end program atest

This is the error message:

% flang-new atest.f08 -o atest -v                                                                                                                        (1)
flang-new version 20.0.0git (https://github.com/llvm/llvm-project.git 37123e9915407d266074aaf81c5de9399b672e53)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/14
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/14
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version 12.5
 "/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/flang-new" -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -resource-dir /home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/lib/clang/20 -mframe-pointer=all -o /tmp/atest-ba7628.o -x f95-cpp-input atest.f08
 "/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/ld" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o atest /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o -L/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/../lib/x86_64-unknown-linux-gnu -L/usr/lib/gcc/x86_64-redhat-linux/14 -L/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/atest-ba7628.o -L/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/lib -lFortranRuntime -lFortranDecimal -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crtn.o
/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/ld: /tmp/atest-ba7628.o: in function `_QFPar':
FIRModule:(.text+0x115): undefined reference to `_FortranACopyInAssign'
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)

I think the reason is that the -L/usr/lib option is passed to ld before -L/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/lib so the linker is picking up the libFortranRuntime from my system (having LLMV 18.1.6 installed) instead of the one installed by LLVM from git in my home directory. Should the order of the -L options be changed here?

tukss avatar Jul 24 '24 15:07 tukss

how do you slove this problem? i find this problem too...

Leilongjie2000 avatar Feb 11 '25 09:02 Leilongjie2000

Actually the problem went away for me by updating to a newer operating system that ships clang 19. I guess the underlying bug is still there it just doesn't manifest itself.

You can probably work around it by calling the linker command manually the right -L at the right position.

tukss avatar Feb 12 '25 17:02 tukss

This is fixed by 1264d7a53a4de3094672be2a248db57b213f33ac.

ceseo avatar Jun 04 '25 13:06 ceseo

@llvm/issue-subscribers-flang-driver

Author: Philipp Edelmann (tukss)

Compiling this simple reproducer code (the real example called `DGEMM`) produces an undefined reference to `_FortranACopyInAssign`. I'm using `flang-new` from the current `main` branch.
program atest
  implicit none

  real(8) :: a(2)

  call ar(a)

contains

  subroutine br(x)
    implicit none
    real(8) :: x(*)
  end subroutine br
  
  subroutine ar(d)
    implicit none
    real(8) :: d(:)
    call br(d)
    
  end subroutine ar
end program atest

This is the error message:

% flang-new atest.f08 -o atest -v                                                                                                                        (1)
flang-new version 20.0.0git (https://github.com/llvm/llvm-project.git 37123e9915407d266074aaf81c5de9399b672e53)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/14
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/14
Candidate multilib: .;@<!-- -->m64
Candidate multilib: 32;@<!-- -->m32
Selected multilib: .;@<!-- -->m64
Found CUDA installation: /usr/local/cuda, version 12.5
 "/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/flang-new" -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -resource-dir /home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/lib/clang/20 -mframe-pointer=all -o /tmp/atest-ba7628.o -x f95-cpp-input atest.f08
 "/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/ld" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o atest /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o -L/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/../lib/x86_64-unknown-linux-gnu -L/usr/lib/gcc/x86_64-redhat-linux/14 -L/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/atest-ba7628.o -L/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/lib -lFortranRuntime -lFortranDecimal -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crtn.o
/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/bin/ld: /tmp/atest-ba7628.o: in function `_QFPar':
FIRModule:(.text+0x115): undefined reference to `_FortranACopyInAssign'
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)

I think the reason is that the -L/usr/lib option is passed to ld before -L/home/user/local/._llvm/l5duc52wf5stt5l5n6whwfzlfnd2ggl2/lib so the linker is picking up the libFortranRuntime from my system (having LLMV 18.1.6 installed) instead of the one installed by LLVM from git in my home directory. Should the order of the -L options be changed here?

llvmbot avatar Jun 04 '25 13:06 llvmbot