While trying to build an Android kernel from source, I ran into the following error:
Strangely, using different
defconfigs or other kernel sources all led me to this weird
modpost section mismatch error. I researched the issue and found some Stack Overflow posts, none of which were very helpful. Here are some of the posts I read:
- How to fix section mismatch errors during cross compile of android
- Linux kernel CONFIG_DEBUG_SECTION_MISMATCH make errors
- What is kernel section mismatch?
But this was a well-established kernel source straight from LineageOS. I thought code being broken straight from LineageOS’s repositories was unlikely, so I looked around some more for another solution.
Turns out, it wasn’t a code problem, but rather a toolchain problem. @mochi_wwww from the Linux kernel chat on Telegram figured out that I was using the incorrect toolchain - I had been using a completely outdated toolchain from several years ago. So embarrassing.
Now, to my defense, the reference Android kernel building guide links to that toolchain. I just didn’t know that it was outdated. Using the proper toolchain magically solved the problem.
So now you know - if you ever run into these weird errors above, try using the correct toolchain for your kernel. It is usually shown in
AndroidKernel.mk if you are using kernel sources from LineageOS. Don’t be an idiot like me and spend hours debugging a code problem that isn’t really a code problem!