Skip to content

lkl: discard .export_symbol section to fix fuzzer build - #648

Open
clingfei wants to merge 1 commit into
lkl:masterfrom
clingfei:master
Open

clingfei wants to merge 1 commit into
lkl:masterfrom
clingfei:master

Conversation

@clingfei

@clingfei clingfei commented Oct 9, 2026 •

Copy link
Copy Markdown

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 ddb5cdb ("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: #595
Closes: #613

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 ddb5cdb ("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: lkl#595
Signed-off-by: Cheng Lingfei <chenglingfei@foxmail.com>
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Test Results

106 files  ±0  106 suites  ±0   10m 27s ⏱️ -3s
206 tests ±0  195 ✅ ±0  11 💤 ±0  0 ❌ ±0 
790 runs  ±0  734 ✅ ±0  56 💤 ±0  0 ❌ ±0 

Results for commit c30cb45. ± Comparison against base commit d0f76a7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LKL fuzzer compilation is failed Failure to build hid-fuzzer

1 participant