clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
592 stars 97 forks source link

'-mabi' issues #605

Closed ZZH-Finalize closed 3 months ago

ZZH-Finalize commented 3 months ago

clangd raise an error "Unsupported option '-mabi=' for target 'x86_64-unknown-linux-gnu'" after I rebuild my project, but it works well before.

I have already specified the '-mabi=lp64d', and this flag is generated to compile_commands.json by meson build system. image image

System information Clangd version (from the log, or clangd --version): image clangd extension version: image Operating system: image

HighCommander4 commented 3 months ago

The flag can be removed using https://clangd.llvm.org/config.html#remove if clang does not recognize it.

ZZH-Finalize commented 3 months ago

The flag can be removed using https://clangd.llvm.org/config.html#remove if clang does not recognize it.

I add this configuration to my .clangd file, the error is gone but I still can't get any tip or code completion at all.

But I noticed that if I use bear to generate the compile_commands.json, the clangd will work as expected, the compile flags are the same. The only difference between these two "compile_commands.json" is the format, "meson" put flags into command section but "bear" put flags into arguments section like this:

image image

HighCommander4 commented 3 months ago

Can you share a complete clangd log for the non-working (meson) case?

ZZH-Finalize commented 3 months ago

Yes, I setup a new demo project that doesn't contain any confidential information, this project has the same problem. I uploaded the"compile_commands.json" file and clangd log. compile_commands.json clangd.json clangd-log-from-vscode-output.txt dot_clangd.txt

HighCommander4 commented 3 months ago

The relevant error from the log seems to be:

E[15:41:12.622] Could not build a preamble for file /workspace/proj/riscv-demo/src/main.c version 1: CreateTargetInfo() return null E[15:41:12.622] error: unknown target CPU 'rv64imafdc_zicsr_zifencei_zba_zbb'

Suggesting the flag -march=rv64imafdc_zicsr_zifencei_zba_zbb is the problem. Try removing that one too?

(I don't have a log for the working (bear) version to compare, but maybe that one doesn't have this flag?)

ZZH-Finalize commented 3 months ago

(I don't have a log for the working (bear) version to compare, but maybe that one doesn't have this flag?)

I can provide that also, and I can upload another version clangd log which without -march flag (by add configuration to .clangd file, instead of remove flags from the build system).

Both of them will work as expected. But bear version have -march -mabi flags, meson version doesn't have those flags.

bear version: compile_commands.json clangd.json clangd-log-from-vscode-output-bear.txt

meson version without -march: compile_commands.json clangd.json clangd-log-from-vscode-output-without-march.txt

HighCommander4 commented 3 months ago

A potentially relevant difference is that with bear, the command contains --target=riscv64-unknown-elf, so clang doesn't need to look at the -march to try to determine the target.

Anyways, it sounds like you've got it working.

ZZH-Finalize commented 3 months ago

Yes, thanks for the help.

ZZH-Finalize commented 3 months ago

I have to say I made a mistake that I forgot the compiler is different between the meson case and the bear case.

And I noticed that all of these three configurations will work, so here is the question, does clangd parse the name of compiler to get target information? When I set the compiler to riscv64-unknow-elf-gcc, It could work with the -mabi -march flags, but when I set it to riscv-none-elf-gcc it will not work because of clangd couldn't get the correct target information from compiler name, then it tries to parse the -march -mabi flags and met another error. Is that correct?

image image image

HighCommander4 commented 3 months ago

Yes, clangd tries to infer the target by parsing the compiler executable name (that happens here in the code).