Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

kernel-cflags-finder: Set CONFIG_CC_IS_CLANG=y #227

Merged
merged 1 commit into from
Aug 9, 2020
Merged

Conversation

geofft
Copy link
Collaborator

@geofft geofft commented Aug 9, 2020

Some of the things in the kernel's Makefile check whether
${CC} --version is clang, which is affected by setting CC. Some look at
CONFIG_CC_IS_CLANG, which was set at configuration time when our kernel
was built. We need to override the latter to get clang-compatible flags.

This causes the kernel to no longer set -W / -Wno flags that aren't
valid for clang, so we can get rid of -Wno-unknown-warning-option.

One problem with the previous approach is that the kernel's Makefile
does feature detection to see what options are accepted by the current
compiler, and it doesn't accept custom CFLAGS early enough for them to
take effect during feature detection. Because the kernel sets
-Werror=unknown-warning-option for clang (by checking the version of
${CC}, unfortunately), all attempts at feature detection would fail
with an unrelated error. This causes Makefile to wrongly conclude that
the compiler doesn't support -mfentry and use mcount instead even if
the compiled kernel expects fentry - i.e., this commit fixes #174.

We might eventually need to set CONFIG_CLANG_VERSION and perhaps unset
CONFIG_CC_IS_GCC, but this seems to work well enough for now.

Some of the things in the kernel's Makefile check whether
`${CC} --version` is clang, which is affected by setting CC. Some look at
CONFIG_CC_IS_CLANG, which was set at configuration time when our kernel
was built. We need to override the latter to get clang-compatible flags.

This causes the kernel to no longer set -W / -Wno flags that aren't
valid for clang, so we can get rid of `-Wno-unknown-warning-option`.

One problem with the previous approach is that the kernel's Makefile
does feature detection to see what options are accepted by the current
compiler, and it doesn't accept custom CFLAGS early enough for them to
take effect during feature detection. Because the kernel sets
`-Werror=unknown-warning-option` for clang (by checking the version of
`${CC}`, unfortunately), all attempts at feature detection would fail
with an unrelated error. This causes Makefile to wrongly conclude that
the compiler doesn't support `-mfentry` and use mcount instead even if
the compiled kernel expects fentry - i.e., this commit fixes #174.

We might eventually need to set CONFIG_CLANG_VERSION and perhaps unset
CONFIG_CC_IS_GCC, but this seems to work well enough for now.
@geofft geofft requested a review from alex August 9, 2020 06:04
geofft added a commit that referenced this pull request Aug 9, 2020
This is #185 minus #188, but with the CONFIG_CC_IS_CLANG fix from #227.

Co-authored-by: Geoffrey Thomas <geofft@ldpreload.com>
@alex alex merged commit 490173c into master Aug 9, 2020
@alex alex deleted the config-cc-is-clang branch August 9, 2020 13:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build fails with: ERROR: "mcount" [/home/kees/src/rust-linux/hello-world/helloworld.ko] undefined!
2 participants