Commit 3d44f1b
George Guo
kpatch/LoongArch: fix kernel panic with -fPIC for same-compilation-unit symbol references
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 kpatch 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.
Example failure case:
- SYSCALL_DEFINE1(newuname) references the same-compilation-unit symbol 'uts_sem'
- When kpatch extracts this function into a module, the reference to
'uts_sem' must be properly relocated
- Without -fPIC, the absolute address reference causes invalid memory
access and kernel panic
Solution:
Force -fPIC compilation for all LoongArch64 kpatch builds. This ensures
that references to same-compilation-unit symbols use position-independent
addressing, allowing proper relocation by the kernel module loader and
preventing kernel panics in livepatch scenarios.
Co-developed-by: Kexin Liu <liukexin@kylinos.cn>
Singed-off-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>1 parent 57d1458 commit 3d44f1b
1 file changed
+4
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1288 | 1288 | | |
1289 | 1289 | | |
1290 | 1290 | | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
1291 | 1295 | | |
1292 | 1296 | | |
1293 | 1297 | | |
| |||
0 commit comments