From c30cb45be6d51ca25eabbab8cd25cbf8881eb479 Mon Sep 17 00:00:00 2001 From: Cheng Lingfei Date: Fri, 9 Oct 2026 09:59:21 +0000 Subject: [PATCH] lkl: discard .export_symbol section to fix fuzzer build When building LKL fuzzers with `LKL_FUZZING=1`, linking targets such as `hid-fuzzer` fails with the following linker error under lld: ld.lld: error: relocation R_X86_64_64 cannot be used against symbol 'system_state'; recompile with -fPIC >>> defined in tools/lkl/liblkl.a(lkl.o) >>> referenced by main.c:128 (init/main.c:128) >>> lkl.o:(.export_symbol+0x8) in archive tools/lkl/liblkl.a In Linux 6.5+ via commit ddb5cdbafaaa ("kbuild: generate KSYMTAB entries by modpost"), EXPORT_SYMBOL() was changed to emit `.quad sym` references into a temporary `.export_symbol` section. These entries serve as markers for modpost to generate `.vmlinux.export.c` and are intended to be dropped from the final vmlinux via `/DISCARD/`. Upstream places `*(.export_symbol)` in `COMMON_DISCARDS`. However, in LKL's `arch/lkl/kernel/vmlinux.lds.S`, `DISCARDS` is bypassed when `CONFIG_LKL_FUZZING` is enabled to prevent sanitizer-related sections (`.init_array`, `.eh_frame`) from being stripped. As a result, `.export_symbol` remains in `lkl.o` and `liblkl.a`. When linking fuzzers with `-fsanitize=fuzzer`, the linker defaults to PIE mode, where `ld.lld` strictly rejects absolute `R_X86_64_64` relocations in read-only sections. Fix this by explicitly discarding `*(.export_symbol)` in `arch/lkl/kernel/vmlinux.lds.S`. Closes: https://github.com/lkl/linux/issues/595 Signed-off-by: Cheng Lingfei --- arch/lkl/kernel/vmlinux.lds.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/lkl/kernel/vmlinux.lds.S b/arch/lkl/kernel/vmlinux.lds.S index dd273c92fac9d9..0dec86f212f3a5 100644 --- a/arch/lkl/kernel/vmlinux.lds.S +++ b/arch/lkl/kernel/vmlinux.lds.S @@ -71,6 +71,10 @@ SECTIONS STABS_DEBUG DWARF_DEBUG + /DISCARD/ : { + *(.export_symbol) + } + // Don't include DISCARDS section to build the target with code coverage. #if !defined(CONFIG_LKL_FUZZING) DISCARDS