<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123073>123073</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clangd] LLVM-style Baremetal toolchain driver was selected for TUs built with `arm-none-eabi-gcc` GNU toolchain
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RigoLigoRLC
</td>
</tr>
</table>
<pre>
Note: this issue is opened based on suggestion of clangd maintainer under clangd/clangd#2289. Specifics of the issue can also be found in the referred issue under clangd.
I've been building an ARM microcontroller toolchain with `arm-none-eabi` GNU toolchain provided by ARM, and clangd was used for code completion. Clangd will consume `compile_commands.json` generated by CMake Ninja generator and provide completion and live error checks in Visual Studio Code.
The issue is that, clangd will choose `clang::driver::toolchains::BareMetal` as the toolchain driver for translation units built by my GNU toolchain (for example `arm-none-eabi-gcc.exe`). Further inspection found that any toolchain that had neither an OS target nor an designated architecture will all cause `BareMetal` selected as the driver, which will lead to clangd looking for system headers in LLVM-style include paths rather than the correct GNU style. (See `clang/lib/Driver/Driver.cpp, Driver::getToolChain`.)
Using `--query-driver` is said to be *the most robust way* of fixing these issues of cross-compilation toolchains but to me this seems like a bug (not handling GNU toolchain correctly). Also, having to add `--query-driver` option on every computer that has a different GCC installation path is not so practical either. RISC-V also has a special check for existence of GNU toolchain, and when a GNU toolchain is present then a GNU-style toolchain driver will be created. Clearly this is only fixing it for RISC-V, and ARM was not getting some love. I thin maybe the detection of GNU toolchain should be improved overall so that other architectures like Xtensa (used extensively in ESP32S3, for example) will also benefit, and maintainer on clangd side suggested that this topic may be more appropriately discussed on LLVM issue tracker.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVs1y2zwSfBrqMiUWRVlSdNBBkVepVNnZLTtJ7W1rCIxIxCDAxYCy-fZfDUjGys_JNImf7p6eHiGzqR3RIdt8zDb3C-xj48Ph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