Fixing compile_commands.json for VS Code and Linux kernel sources

I have my Linux kernel sources setup like this:

-------------------
Fri Jun 14 00:35:24 [bash:5.2.15 jobs:0 error:0 time:2449]
jj5@virtuoso:/home/jj5/repo/git/git.kernel.org/torvalds-linux
$ git remote show origin
* remote origin
  Fetch URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  Push  URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)
-------------------

The scripts/clang-tools/gen_compile_commands.py runs just fine:

-------------------
Fri Jun 14 00:35:28 [bash:5.2.15 jobs:0 error:0 time:2453]
jj5@virtuoso:/home/jj5/repo/git/git.kernel.org/torvalds-linux
$ scripts/clang-tools/gen_compile_commands.py 
-------------------

But there is a problem with some unknown clang options, as you can see here:

Problems with clang commands in VS Code

So I wrote this collection of sed scripts to delete the problematic options:

-------------------
Fri Jun 14 00:11:28 [bash:5.2.15 jobs:0 error:0 time:1013]
jj5@virtuoso:/home/jj5/repo/git/git.kernel.org/torvalds-linux
$ cat jj5/fix-commands.sh 
#!/bin/bash

main() {

  set -euo pipefail;

  cd "$( dirname "$0" )";

  cd ..;

  local file="compile_commands.json";

  sed -i 's/-mpreferred-stack-boundary=3//g' "$file"
  sed -i 's/-mfunction-return=thunk-extern//g' "$file"
  sed -i 's/-mindirect-branch=thunk-extern//g' "$file"
  sed -i 's/-mindirect-branch-register//g' "$file"
  sed -i 's/-fno-allow-store-data-races//g' "$file"
  sed -i 's/-fconserve-stack//g' "$file"
  sed -i 's/-mrecord-mcount//g' "$file"

}

main "$@";
-------------------

Bug fixed! Thanks to my mates on IRC for helping me fix this one. This clangd extension for VS Code seems to work really well.

p.s. another possible solution is here.

New books

Ordered on Amazon today:

I’m not sure what to make of the fact that these books are nearly 20 years old… totally out of date, but all that is available? What’s up with that?

Netfilter and iptables

This evening I read the iptables man page and Linux iptables Pocket Reference from cover-to-cover; my notes are here: Netfilter.

I think at this point I am ready to use iptables in anger for the first time in a long time, and the first time ever on a router.

However, before I take that on, I’m going to have a quick diversion into the following books, and then sleep, and I will do my iptables programming when I wake up tomorrow.