<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102667>102667</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Flang fails to build when a non-host LLVM_DEFAULT_TARGET_TRIPLE is provided
</td>
</tr>
<tr>
<th>Labels</th>
<td>
build-problem,
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jonathonpenix
</td>
</tr>
</table>
<pre>
After https://github.com/llvm/llvm-project/commit/2f8b64d327a27a73b57a54eb5d1f28c41e650aee builds including flang seem to fail if a non-host LLVM_DEFAULT_TARGET_TRIPLE triple is provided.
For example, building llvm at cb5ec3796ab08b34d9b0c42f654ca3ca026e50d3 using the following cmake invocation fails with errors for me:
```
$ cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lld;mlir;flang;openmp" -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabi -DCMAKE_INSTALL_PREFIX=$PWD/../install -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=0n ../llvm-project/llvm
```
The errors I see are as follows:
```
[7829/7904] Generating ../../../../include/flang/iso_fortran_env_impl.mod, iso_fortran_env_impl.o
FAILED: cd /path/to/build/tools/flang/tools/f18 && /path/to/cmake/3.23.1/bin/cmake -E make_directory /path/to/build/include/flang && /path/to/build/bin/flang-new -cpp -c -o /path/to/build/tools/flang/tools/f18/iso_fortran_env_impl.o -module-dir /path/to/build/include/flang /path/to/llvm-project/flang/module/iso_fortran_env_impl.f90
error: /path/to/llvm-project/flang/lib/Optimizer/CodeGen/Target.cpp:1114: not yet implemented: target not implemented
LLVM ERROR: aborting
```
The specific error is presumably due to 32bit arm not being a supported target in Flang, but it seems like the larger issue is inconsistent targets being used--even supported targets (expectedly, I think) have problems. Ex: on an arm64 MacOS machine with the default target triple set to riscv64, libFortranRuntime.a fails to link with the below error:
```
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: tools/flang/tools/f18/iso_fortran_env_impl.o is not an object file (not allowed in a library)
```
`file` shows `tools/flang/tools/f18/iso_fortran_env_impl.o` is a ELF 64bit RISC-V object file versus the rest which are Mach-O arm64 objects.
Presumably a consistent `--target` (or equivalent) should be enforced when building `iso_fortran_env_impl.o` (and the runtime more generally) but I'm not sure if this is an expected/supported use case at the moment or how best to handle this offhand given that the current runtime build setup seems to be intended as a temporary measure.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVlFv4jwW_TXm5SooOBDIAw-0kBG7zLSifLO7T8ixb4hnHDtrO7TdX7-yA22n20qzIyHAiX3vudfnHJs5J08acUlmN2S2HrHeN8YufxjNfGN0h1o-jSojnper2qOFxvvOkWxFaEloeZK-6asxNy2hpVLn60_SWfMDuSe05KZtZfhD60WVT0VG54zO2TyrZnM2m2I1E5OaLvh0gvksZYhQ9VIJB1Jz1QupT1Arpk_gEFvwBmomFYCsgYE2OmmM87Dbff96XG_K1V-7w_Gw2n_ZHI6H_fZ-twFvZacQpIPOmrMUKMYkXZN0NXyXxgI-sbZTSOjtkDvkDFUA88CrGfJsXuSsShdVNhVFlfIprfPZlLOMs5TmOEtFBr0Ly3yDUBulzGMY8Zb9RJD6bDjz0uiI3cGj9A2gtcY6qI2FFkNDB1B5evkMQzq9BEm-wDepfzBI1rHYzbfVzW5zvN_f_W1ze3gg2ZpQykOjSHajlCDZTaukJdlNfXloOtRtRyi9hviwXyRbM9smSur-KTnpHlklIVnffl39fXPcfns4rHa74_1-U27_GXNO7_-xJrQcjwktpXaeKfUy_eav7W59PPzrPkTdo0Lm8B3-1cPDZn_Y3n0LFaQaYpx3DIq8-qg7hwavbdwGegCzCMxdNsB92tTZzXxBC0LLeZFOyWwNX1CjZT5sWQTw7mtgIhJaDr2kpXTmWBvrLdNH1OejbDs1bo0IFPrwnbmwbbXdbdYkWwEXQGjZMd8QWnpDaBmpFwdGuTe5XsaTBRCaE5q_XxkZQmiZjWk2noRQUl8fQ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