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

Clang inspired fixes, add clang CI permutation #172

Closed
wants to merge 8 commits into from

Conversation

evelikov
Copy link
Collaborator

@evelikov evelikov commented Oct 3, 2024

This series fixes all the issues spotted by clang (+ be that clang itself, scan-build or cland-tidy) and adds it to CI.

At a glance - from the 5 distros we have 4 major clang versions and as indicated in the patches, there's some value in having them.

Understandably, the CI matrix is becoming a bit of a zoo... Although half of it will be gone with the drop of autotools, soon (tm) 😅

Plus since they're all parallel jobs, I think we can bare with it.

@evelikov
Copy link
Collaborator Author

evelikov commented Oct 3, 2024

Whelp seems like sanitizers and clang don't play well together... I'm assuming gcc uses static sanitizer libs while clang shared ones, or vice versa.

Flipping to draft, feel free to review and comment though.

@evelikov evelikov marked this pull request as draft October 3, 2024 16:37
tools/insmod.c Outdated Show resolved Hide resolved
libkmod/libkmod-index.c Outdated Show resolved Hide resolved
libkmod/libkmod.c Outdated Show resolved Hide resolved
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
Required for puts(), reported by clang-tidy.

Fixes: b644b8d ("tools: add kmod_version() helper")
Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
Required for size_t, reported by clang-tidy.

Fixes: 38943b2 ("shared: use size_t for strbuf")
Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
Initialize the variable, otherwise we'll get (random) stack value if the
user hasn't provided --syslog. Reported by scan-build.

Fixes: ca8f04e ("tools/insmod: add syslog and verbose options")
Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
Initialize the variable, otherwise we'll get (random) stack value if the
user hasn't provided --syslog. Reported by scan-build.

Fixes: 24fe68d ("tools/rmmod: make opt variables non-global")
Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
Initialize the variable, otherwise we'll get (random) stack value if the
user hasn't provided --syslog. Reported by scan-build.

Fixes: 6313d40 ("tools/lsmod: add basic opts like rmmod")
Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
Older versions of clang (14.0.0 as seen in Ubuntu 22.04) will flag a
warning that we're using unsigned int, with a unsigned char modifier.

Newer versions like 16.0.6 (Debian unstable), 17.0.6 (Alpine), etc do
not flag this as an issue.

In practise the number fits in the latter range, so just add a cast to
silence the warning.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
Clang will detect that the enum cannot be zero, thus triggering a
warning. Since this is an external (public API) function, the end-user
can provide any input so we want to keep the check.

Note: include the pragmas in a if defined(__clang__) guard, otherwise
we'll trigger -Wunknown_pragma which will become an error in CI and
developer builds.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
There was some recent snafu which meant the container wasn't available.
With that resolved, we can drop our hack and use the correct container
directly.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 9, 2024
I'm about to add some more and the current (almost sorted) state breaks
my brain :-x

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
@lucasdemarchi
Copy link
Contributor

Applied most of the patches, leaving some comments in others. Thanks

@evelikov evelikov force-pushed the clang-inspired-fixes branch from 7617ce7 to e8d1628 Compare October 9, 2024 17:03
@evelikov
Copy link
Collaborator Author

evelikov commented Oct 9, 2024

Updated the PR dropping the already merged changes. In addition we have:

  • use single variable for insmod control flow
  • tweak the rmmod code flow
  • rerun the tests in verbose, if they fail
  • properly resolve the GCC/ASAN ordering issue - @stoeckmann please check it over
  • fix the UB issues reported by clang's sanitizer
    • alternative suggestions for "adding zero to a NULL pointer" are more then welcome

CI now passes all permutations apart from Fedora 40 and Ubuntu 22.04:

  • F40, package compiler-rt should include the files although they're nowhere to be found - either find or clang -print-file-name (see the Set the environment section)
  • U22.04, the files are there according to find and clang ... with all their dependencies resolved, yet it fails with "No such file or directory"

As you can see I didn't succeed in excluding them - web linter complains matrix.exclude is unknown key... Then again it also complains for matrix.container -> Matrix must only contain primitive types 🤯

Any tips would be appreciated. In the meanwhile feel free to grab whatever makes sense.

libkmod/libkmod-index.c Outdated Show resolved Hide resolved
@lucasdemarchi
Copy link
Contributor

Is this still a draft?

@evelikov
Copy link
Collaborator Author

Is this still a draft?

Since it's getting really hairy, I've split out the prep patches into separate PRs.

As those land, I will respin the final patches and undraft.

@evelikov evelikov force-pushed the clang-inspired-fixes branch 2 times, most recently from 31ad907 to 497a04a Compare October 17, 2024 21:30
@evelikov
Copy link
Collaborator Author

The newly enabled clang build already flagged another few issues (alongside the ELFDBG) 🎉

In addition we have:

  • temporary disabled Fedora + clang - the sanitizer shared lib is missing
  • move sanitizer enablement to build-dev.ini
  • convert the test wrapper to "sanitizer-env.sh" setup script
  • updated make references in testsuite code and README

Last two are from #172 ... With the final outstanding piece (add test toggle --disable-sanitizer) which doesn't seem doable ATM.

@evelikov evelikov marked this pull request as ready for review October 17, 2024 21:36
The recently added "always build ELFDBG" patch is already paying
dividends... Clang is flagging a "fmt" is not literal warning.

That's clearly wrong, although without _printf_format_ clang was
struggling to figure things out. With the attribute, it helpfully
flagged that handful of the modifiers are wrong.

Signed-off-by: Emil Velikov <[email protected]>
Convert the existing wrapper script, into one that we source to set the
environment aka LD_PRELOAD.

Thus a developer can, use/test/debug the tests without using meson.
Namely:
 - source scripts/sanitizer-env.sh
 - build/testsuite/test-depmod

Signed-off-by: Emil Velikov <[email protected]>
With the sanitizers supported in both gcc + clang and all the issues
resolved, let's enable them via build-dev.ini.

This means, developers will see any issues OOTB without having to run
through the CI.

As a nice bonus, let's re-enable them for ubuntu:22.04 - it should be
working fine now.

Signed-off-by: Emil Velikov <[email protected]>
@evelikov evelikov force-pushed the clang-inspired-fixes branch from 497a04a to c89d457 Compare October 17, 2024 21:49
@evelikov
Copy link
Collaborator Author

Masking Fedora + clang, nuked clang all together 🤯 Converted to keep Fedora gcc/clang yet disable the sanitizers.

Plus some last second commit reshuffle, for extra fun 😂

By default clang uses static sanitizer libraries, which causes build and
test-time failures. Swap for the shared libasan which resolves both.

Note: meson tries to be helpful here, throwing a warning that we should
use -D b_lundef=false which is incorrect in our case.

Signed-off-by: Emil Velikov <[email protected]>
With the clang issues resolved, let's add it to the CI matrix so fewer
issues get it.

Note: Fedora 40 doesn't ship the shared sanitizer library, while older
Fedora versions did. Fedora 41 will be coming with LLVM 19, which will
have the binary (seemingly with different name 🤦).

Let's leave the Fedora/clang infra in and just mask it out sanitizers
for the next month or so, until the new version comes out. Then we can
re-evaluate.

Signed-off-by: Emil Velikov <[email protected]>
Mention that running outside of `meson test", one needs to set the env.
aka "source scripts/sanitizer-env.sh".

Also gently discourage using sanitizers alongside gdb and strace. While
thing might work it's not the setup we want to support, I think.

Signed-off-by: Emil Velikov <[email protected]>
@evelikov evelikov force-pushed the clang-inspired-fixes branch from c89d457 to 86f2f91 Compare October 18, 2024 17:22
We have added meson recently, with the goal to remove the make/autotools
one in a release or two. Update the reference to the meson equivalent.

Signed-off-by: Emil Velikov <[email protected]>
@evelikov evelikov force-pushed the clang-inspired-fixes branch from 86f2f91 to 154fe19 Compare October 18, 2024 17:27
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
The recently added "always build ELFDBG" patch is already paying
dividends... Clang is flagging a "fmt" is not literal warning.

That's clearly wrong, although without _printf_format_ clang was
struggling to figure things out. With the attribute, it helpfully
flagged that handful of the modifiers are wrong.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
Convert the existing wrapper script, into one that we source to set the
environment aka LD_PRELOAD.

Thus a developer can, use/test/debug the tests without using meson.
Namely:
 - source scripts/sanitizer-env.sh
 - build/testsuite/test-depmod

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
With the sanitizers supported in both gcc + clang and all the issues
resolved, let's enable them via build-dev.ini.

This means, developers will see any issues OOTB without having to run
through the CI.

As a nice bonus, let's re-enable them for ubuntu:22.04 - it should be
working fine now.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
By default clang uses static sanitizer libraries, which causes build and
test-time failures. Swap for the shared libasan which resolves both.

Note: meson tries to be helpful here, throwing a warning that we should
use -D b_lundef=false which is incorrect in our case.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
With the clang issues resolved, let's add it to the CI matrix so fewer
issues get it.

Note: Fedora 40 doesn't ship the shared sanitizer library, while older
Fedora versions did. Fedora 41 will be coming with LLVM 19, which will
have the binary (seemingly with different name 🤦).

Let's leave the Fedora/clang infra in and just mask it out sanitizers
for the next month or so, until the new version comes out. Then we can
re-evaluate.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
Mention that running outside of `meson test", one needs to set the env.
aka "source scripts/sanitizer-env.sh".

Also gently discourage using sanitizers alongside gdb and strace. While
thing might work it's not the setup we want to support, I think.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Oct 18, 2024
We have added meson recently, with the goal to remove the make/autotools
one in a release or two. Update the reference to the meson equivalent.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
@lucasdemarchi
Copy link
Contributor

I did a small fixup in testsuite/README and applied. Thanks!

@evelikov evelikov deleted the clang-inspired-fixes branch October 18, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants