<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/100403>100403</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Linker missing `_FortranACopyInAssign`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tukss
</td>
</tr>
</table>
<pre>
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.
```fortran
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?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V0tv4zgS_jX0pUCBph62Dz6kk9UgQALsTmbnGlBkyeKEIgWSSpz99QtKfqQz7sam4QUCxSLr8bGqWPpKhKB3FnFLym-kvFuIMXbOb-P4EsKicep9e-v6QRttdxA7HSDofjAIHgfv1CjRg3QKgfB17NKyMIB7MclIYQwqIBW7--0fj4-kYoRv4KAXQFgYrcJWW1TgsUWPViJElz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