Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When building LKL fuzzers with
LKL_FUZZING=1, linking targets such ashid-fuzzerfails 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
In Linux 6.5+ via commit ddb5cdb ("kbuild: generate KSYMTAB entries by modpost"), EXPORT_SYMBOL() was changed to emit
.quad symreferences into a temporary.export_symbolsection. These entries serve as markers for modpost to generate.vmlinux.export.cand are intended to be dropped from the final vmlinux via/DISCARD/.Upstream places
*(.export_symbol)inCOMMON_DISCARDS. However, in LKL'sarch/lkl/kernel/vmlinux.lds.S,DISCARDSis bypassed whenCONFIG_LKL_FUZZINGis enabled to prevent sanitizer-related sections (.init_array,.eh_frame) from being stripped. As a result,.export_symbolremains inlkl.oandliblkl.a.When linking fuzzers with
-fsanitize=fuzzer, the linker defaults to PIE mode, whereld.lldstrictly rejects absoluteR_X86_64_64relocations in read-only sections.Fix this by explicitly discarding
*(.export_symbol)inarch/lkl/kernel/vmlinux.lds.S.Closes: #595
Closes: #613