Reducing an LTO Linux kernel bug with cvise

My co-maintainer Nick Desaulniers wrote a great post about taking a several thousand line C file that exposed a compiler bug down to 12 lines with creduce. I thought I would do the same thing with a bug that only happens with link time optimization (LTO) in the Linux kernel, which is a bit of a different beast. Hopefully this post can help others reduce their own bugs and think about the best way to triage a bug. ...

November 29, 2021 · 19 min · Nathan Chancellor

October 2021 ClangBuiltLinux Work

This was a bit of a shorter month for me, as I took some vacation at the beginning of the month to recouperate and meet half of my girlfriend’s extended family and friends for the first time. Thankfully, the rest of the ClangBuiltLinux team was able to keep everything churning along in my absence and I was able to be super productive the rest of the month once I returned. ...

October 29, 2021 · 7 min · Nathan Chancellor

September 2021 ClangBuiltLinux Work

Linux kernel patches tools: compiler-gcc.h: Guard error attribute use with __has_attribute (v1): The minimum version of GCC was raised to 5.1, which helped simplify a lot of code but caused issues for older versions of clang. This helps resolve it. Harden clang against unknown flag options (v2): A follow up. ptp: ocp: Avoid operator precedence warning in ptp_ocp_summary_show() (v1, v2): An interesting warning around operator precedence, which will not be an issue in practice but now that Linus has decreed that warnings are unacceptable, it is important to clean them up! ...

September 30, 2021 · 6 min · Nathan Chancellor

August 2021 ClangBuiltLinux Work

Linux kernel patches [PATCH] dmaengine: idxd: Remove unused status variable in irq_process_work_list(): Not a clang specific warning but it impacts builds where I use -Werror, as kernel builds should be as warning clean as possible. [PATCH] ASoC: Intel: boards: Fix CONFIG_SND_SOC_SDW_MOCKUP select: Not a clang specific warning but Kconfig warnings such as this can potentially be build errors later due to incorrect dependency selection so it is important to fix them when they pop up. ...

August 31, 2021 · 10 min · Nathan Chancellor

July 2021 ClangBuiltLinux Work

Linux kernel patches [PATCH] Hexagon: Export raw I/O routines for modules: Hexagon is a digital signal processor architecture by Qualcomm, which is a little special in terms of the Linux kernel because it is the only architecture that does not have a GCC backend so LLVM has to be used to build it, meaning that it is important to keep it building. This patch fixes an issue with allmodconfig, which enables us to build a wide variety of code and verify the compiler is able to handle all of it. ...

August 1, 2021 · 6 min · Nathan Chancellor

June 2021 ClangBuiltLinux Work

Linux kernel patches ANDROID: sched: Gate sched_stat tracepoint exports on CONFIG_SCHEDSTATS: One of those instances where a tangential change in the Android trees broke our continuous integration. Our CI tests some 32-bit ARM configurations because certain Android OEMs care about them but these configs are not tested by the actual Android team, meaning we find breakage that they do not. [PATCH net-next] net: ks8851: Make ks8851_read_selftest() return void: clang implemented GCC’s -Wunused-but-set-variable and this instance was found by Intel’s kernel test robot. Rather simple fix but it is important to fix warnings as they crop up so that the build stays as clean as possible so that the real issues are easily visible. ...

July 1, 2021 · 8 min · Nathan Chancellor

May 2021 ClangBuiltLinux Work

This month felt longer than others but I feel like that was because I was a lot more spread out in the work that I was doing. Let’s dive in, shall we? Linux kernel patches / backports [PATCH] fbmem: Correct position of '__maybe_unused' in proc_fb_seq_ops: A common mistake people make is splitting “struct ” with an attribute, in this case “__maybe_unused”, which clang warns about while GCC does not. This causes a warning in all of our builds. Unfortunately, this patch did not actually make it into mainline because Linus fixed it himself. ...

June 1, 2021 · 6 min · Nathan Chancellor

April 2021 ClangBuiltLinux Work

Another month down! Feels like I just wrote the March 2021 post… but I suppose that is what happens when your project moves super quickly :) Linux kernel patches [PATCH] ACPI / CPPC: Replace cppc_attr with kobj_attribute: I discovered this issue as part of my testing of Sami Tolvanen’s Control Flow Integrity series (more on that below). There are probably many more of these lurking because this pattern is hard to spot without runtime testing. As I have time amongst all of the other issues and such, I will be testing the x86 variant of CFI on several different servers, trying to flush out all of the different issues there. ...

April 30, 2021 · 7 min · Nathan Chancellor

March 2021 ClangBuiltLinux Work

Another month, another post about the work that I have done as a kernel/compiler developer! One of the highlights this month is that I got LLVM commit access so I can merge my own patches into LLVM, which I did twice so far. Linux kernel patches powerpc/fadump: Mark fadump_calculate_reserve_size as __init: LLVM 13 switched over to the New Pass Manager (NPM), which has impacted some inlining decisions, which in turn exposed some bugs in section annotations. The kernel places certain functions and variables into specific sections that are discarded and freed after init. If a non-init function calls an init function, that is technically a use-after-free so the kernel warns when this happens. In this particular case, identical_pvr_fixup() was not marked as __init and it was not getting inlined so the calls to identify_cpu() and of_get_flat_dt_prop() resulting in the modpost warnings. In practice, this is not an issue because identical_pvr_fixup() is only called from __init context but it is important to get these things right so that real warnings can easily be caught. ...

April 1, 2021 · 6 min · Nathan Chancellor

February 2021 ClangBuiltLinux Work

As some of you may or may not know by now, I am now employed by the Linux Foundation to help improve Linux security. The primary way that I am doing that is through the work I do for ClangBuiltLinux, of which I am an official maintainer. Linux kernel patches First and foremost, I am a Linux kernel developer, meaning that I love sending kernel patches. Getting familiar with git send-email and the standard Linux kernel workflow can be difficult but now that I am used to it, I find other things cumbersome. ...

February 28, 2021 · 8 min · Nathan Chancellor