On Thu, 2026-06-04 at 14:53 +0800, George Guo wrote: > From: George Guo <[email protected]> > > Add architecture-specific -fPIC compiler flag for LoongArch64 to prevent > kernel panics when applying livepatches containing references to symbols > defined in the same compilation unit. > > Root cause: > In the KLP workflow, when a function is livepatched, it's extracted > from the original object file and compiled into a separate kernel > module. When the patched function references symbols defined in the > same compilation unit (like 'uts_sem' in kernel/sys.c), these > references break if not compiled as position-independent code. > > On LoongArch64, without -fPIC, references to same-compilation-unit symbols > use absolute addressing that assumes fixed memory locations. When the > function is relocated into the livepatch module, these absolute addresses > become invalid, causing kernel panics.
This is incorrect. With GCC and Clang, -fPIC does not mean generating position independent code. It means generating position independent code *suitable for SVR4- style shared objects*. The kernel has nothing to do with SVR4-style shared objects. The kernel modules are not SVR4 shared objects but relocatable ELF object files. If you only need position independent code (without the shared object stuff) you should use -fPIE instead. The kernel is already built with - fPIE if CONFIG_RELOCATABLE=y. Thus if you only need position independent code you should make live patching depend on CONFIG_RELOCATABLE. On the contrary if you really need to use/abuse something mechanism designed for SVR4 shared object you 'd at least need to fix the description above. -- Xi Ruoyao <[email protected]>

