From 34dd1ba21994c19c19052f0ab2a9c84771ecd7b0 Mon Sep 17 00:00:00 2001 From: dor Date: Thu, 28 May 2026 17:32:21 +0300 Subject: [PATCH] use relocated ko copy to resolve module symbols --- scripts/04-deploy-and-prep-gdb.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/04-deploy-and-prep-gdb.sh b/scripts/04-deploy-and-prep-gdb.sh index 976f0b0..c969337 100755 --- a/scripts/04-deploy-and-prep-gdb.sh +++ b/scripts/04-deploy-and-prep-gdb.sh @@ -6,8 +6,8 @@ # 1. Best-effort kill of any local gdb holding the debug-endpoint TCP # port (KGDB serial bridge and QEMU gdbstub each serve one client). # 2. Upload module/.ko, verify size matches. -# 3. Insmod in the background; poll /sys/module//sections/ for the -# runtime load addresses and emit an `add-symbol-file ...` line. +# 3. Insmod; poll /sys/module//sections/ for runtime addresses, +# stage a section-relocated copy of the .ko, and add-symbol-file it. # 4. Emit .gdb/-.gdb (+ -attached variant) and the # current-* symlinks the IDE launch configs point at. # @@ -171,12 +171,23 @@ load_and_discover_symbols() { local text_addr text_addr="$(awk '$1 == ".text" { print $2 }' "$tmp")" if [[ -n "$text_addr" ]]; then - local cmd="add-symbol-file $artifact $text_addr" + # Pre-relocate the .ko: write each section's runtime + # address into its sh_addr so BFD bakes correct addresses into DWARF. + local relocated="$gdb_dir/$target-$debug_method-$module_name-relocated.ko" + local objcopy_args=() + local existing + existing="$(objdump -h "$artifact" | awk '$1 ~ /^[0-9]+$/ {print $2}')" while read -r sec addr; do - [[ "$sec" != ".text" && -n "$addr" ]] && cmd+=" -s $sec $addr" + [[ -z "$addr" || -z "$sec" ]] && continue + grep -qxF "$sec" <<< "$existing" || continue + objcopy_args+=("--change-section-address" "$sec=$addr") done < "$tmp" + rm -f "$relocated" + objcopy --no-change-warnings "${objcopy_args[@]}" \ + "$artifact" "$relocated" \ + || die "objcopy failed to produce $relocated" { - echo "$cmd" + printf 'add-symbol-file %s %s\n' "$relocated" "$text_addr" printf 'echo loaded %s module symbols for %s\\n\n' "$module_name" "$target" } > "$symbols_file" rm -f "$tmp"