Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm: use proper syntax for --config option #61778

Merged
merged 1 commit into from
Aug 23, 2023

Conversation

kartben
Copy link
Collaborator

@kartben kartben commented Aug 23, 2023

Use proper --config= syntax instead of --config as the latter can cause issues in some situations.

Use proper --config= syntax instead of --config as the latter can cause
issues in some situations.

Signed-off-by: Benjamin Cabé <[email protected]>
@fabiobaltieri fabiobaltieri merged commit 577d47f into zephyrproject-rtos:main Aug 23, 2023
@marc-hb
Copy link
Collaborator

marc-hb commented Aug 30, 2023

For some unknown reason this just broke the SOF fuzzer build:

Any idea?

clang: error: unsupported option '--config=/home/runner/work/sof/sof/workspace/zephyr/cmake/toolchain/llvm/clang_libgcc.cfg'

Ubuntu clang version 14.0.0-1ubuntu1.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/[12](https://github.com/thesofproject/sof/actions/runs/6024171187/job/16342326426?pr=8126#step:7:13)
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64

@marc-hb
Copy link
Collaborator

marc-hb commented Aug 30, 2023

Same failure reproduced with more recent clang 15.0.7

@kartben which clang version did you test this with and how?

Also, what specific problem(s) did this commit help with?

clang --verbose

clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/13.2.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

clang --help | grep config

  --config <value>        Specifies configuration file

@kartben
Copy link
Collaborator Author

kartben commented Aug 30, 2023

Same failure reproduced with more recent clang 15.0.7

@kartben which clang version did you test this with and how?

clang 16.0.0.0

Also, what specific problem(s) did this commit help with?

When using the newly introduced CodeChecker stuff with ZEPHYR_TOOLCHAIN_VARIANT=llvm and clang 16.0.0, I get the following error: clang-16: error: configuration file '-Wall' cannot be found

CodeChecker uses the compile_commands.json file generated by CMake (I think?), which contains entries such as:

  {
    "directory": "/home/kartben/zephyrproject/zephyr/build",
    "command": "/home/kartben/Downloads/clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -DKERNEL -D_POSIX_C_SOURCE=200809 -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED -D__ZEPHYR__=1 -I/home/kartben/zephyrproject/zephyr/include -I/home/kartben/zephyrproject/zephyr/build/zephyr/include/generated -I/home/kartben/zephyrproject/zephyr/soc/posix/inf_clock -I/home/kartben/zephyrproject/zephyr/boards/posix/native_posix -I/home/kartben/zephyrproject/zephyr/arch/posix/core/nsi_compat -I/home/kartben/zephyrproject/modules/lib/acpica/../../zephyr/include -I/home/kartben/zephyrproject/modules/lib/acpica/.. -I/home/kartben/zephyrproject/modules/lib/acpica/source/include -I/home/kartben/zephyrproject/modules/lib/acpica/source/include/platform -I/home/kartben/zephyrproject/modules/lib/acpica/source/compiler -I/home/kartben/zephyrproject/modules/lib/acpica/generate/zephyr -I/home/kartben/zephyrproject/modules/lib/acpica/source/tools/acpiexec -I/home/kartben/zephyrproject/modules/lib/acpica/source/tools/acpidump -fno-strict-aliasing -Os -imacros /home/kartben/zephyrproject/zephyr/build/zephyr/include/generated/autoconf.h -fno-common -g -gdwarf-4 -fcolor-diagnostics --config /home/kartben/zephyrproject/zephyr/cmake/toolchain/llvm/clang_libgcc.cfg -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-unused-but-set-variable -Wno-typedef-redefinition -Wno-deprecated-non-prototype -Wno-pointer-sign -Wpointer-arith -Wno-sometimes-uninitialized -Wno-shift-overflow -Wno-missing-braces -Wno-self-assign -Wno-address-of-packed-member -Wno-unused-function -Wno-initializer-overrides -Wno-section -Wno-unknown-warning-option -Wno-unused-variable -Wno-format-invalid-specifier -Wno-gnu -Wno-tautological-compare -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -Wno-vla -fmacro-prefix-map=/home/kartben/zephyrproject/zephyr/samples/hello_world=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/kartben/zephyrproject/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/kartben/zephyrproject=WEST_TOPDIR -ffunction-sections -fdata-sections -m32 -msse2 -mfpmath=sse -include /home/kartben/zephyrproject/zephyr/arch/posix/include/posix_cheats.h -std=c11 -o CMakeFiles/app.dir/src/main.c.obj -c /home/kartben/zephyrproject/zephyr/samples/hello_world/src/main.c",
    "file": "/home/kartben/zephyrproject/zephyr/samples/hello_world/src/main.c"
  },

and for some reason it gets the --config argument wrong? Just adding double quotes around --config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang_${runtime_lib}.cfg seems break even a simple build, so I eventually figured that both double quotes AND = were making everything work ... with 16.0 :-/
Do we need to treat <16 and 16+ differently or..?

Also, for what it's worth:

❯ clang -v
clang version 16.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/kartben/Downloads/clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
❯ clang --help | grep config
  --config=<file>         Specify configuration file
  --no-default-config     Disable loading default configuration files

@marc-hb
Copy link
Collaborator

marc-hb commented Aug 30, 2023

clang 16.0.0.0

Thanks, that helps.

Do we need to treat <16 and 16+ differently or..?

I found a clang 16.0.6 version somewhere and I tested it and for me it works BOTH with and without the equal sign =. As LLVM 16 is less than 6 months old it seems premature to break backwards compatibility with clang < 16.

and for some reason it gets the --config argument wrong?

I tried to reproduce your issue but I could not. I don't understand why clang 16.0.0.0 seems to drop the config file argument in your case. This feels like a bug in the parser change that they just made, can you try to upgrade your clang?

@marc-hb
Copy link
Collaborator

marc-hb commented Aug 30, 2023

This feels like a bug in the parser change that they just made, can you try to upgrade your clang?

Some clang gitarcheology...

I didn't find any obvious bug fix after that. On the other hand, I found some significant changes after 16.0.0, for instance:

So I think it's definitely worth trying something newer than 16.0.0.0

@marc-hb
Copy link
Collaborator

marc-hb commented Aug 30, 2023

CodeChecker uses the compile_commands.json file generated by CMake (I think?),

Also, can you try to re-run your clang command directly on the command line? The easiest to find the real, full command is to temporarily insert garbage in one C file; then CMake prints it and you can copy/paste it and run it directly. This is how I performed all my testing of clang 15 and clang 16.

carlescufi pushed a commit that referenced this pull request Aug 31, 2023
This reverts commit 577d47f.

The --config= syntax with the equal sign does not work with clang 15
which is less than one year old (https://releases.llvm.org/). It does
not work with clang 14 either.

```
clang --verbose
clang version 15.0.7

clang --help | grep config

  -cl-std=<value>         OpenCL language standard to compile for.
  --config   <value>      Specifies configuration file
  --cuda-feature=<value>  Manually specify the CUDA feature to use

clang: error: unsupported option '--config=/home/runner/work/...
```

The reverted commit mentioned "issues in some situations" without
providing any example or other information.
This revert fixes the SOF fuzzer build, see more details in #61778.

Signed-off-by: Marc Herbert <[email protected]>
@kartben
Copy link
Collaborator Author

kartben commented Aug 31, 2023

CodeChecker uses the compile_commands.json file generated by CMake (I think?),

Also, can you try to re-run your clang command directly on the command line? The easiest to find the real, full command is to temporarily insert garbage in one C file; then CMake prints it and you can copy/paste it and run it directly. This is how I performed all my testing of clang 15 and clang 16.

So the command as found in the compile_commands.json file definitely works, with both syntaxes, and I can make it fail by pointing to a config file that doesn't exist.

I am calling for a bug in CodeChecker as it seems to actually be dropping the config file altogether when calling clang-tidy

The following from the compile_commands:

[...] -fno-common -g -gdwarf-4 -fcolor-diagnostics --config /home/kartben/zephyrproject/zephyr/cmake/toolchain/llvm/clang_libgcc.cfg -Wall -Wformat -Wformat-security -Wno-format-zero-length [...]

becomes:

[...] -fno-common -g -gdwarf-4 -fcolor-diagnostics --config -Wall -Wformat -Wformat-security -Wno-format-zero-length  [...]

piotrnarajowski pushed a commit to piotrnarajowski/zephyr that referenced this pull request Aug 31, 2023
This reverts commit 577d47f.

The --config= syntax with the equal sign does not work with clang 15
which is less than one year old (https://releases.llvm.org/). It does
not work with clang 14 either.

```
clang --verbose
clang version 15.0.7

clang --help | grep config

  -cl-std=<value>         OpenCL language standard to compile for.
  --config   <value>      Specifies configuration file
  --cuda-feature=<value>  Manually specify the CUDA feature to use

clang: error: unsupported option '--config=/home/runner/work/...
```

The reverted commit mentioned "issues in some situations" without
providing any example or other information.
This revert fixes the SOF fuzzer build, see more details in zephyrproject-rtos#61778.

Signed-off-by: Marc Herbert <[email protected]>
@kartben kartben deleted the fix_llvm_toolchain branch September 15, 2023 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants