]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Fix debug experience
authorJan Janssen <medhefgo@web.de>
Tue, 28 Feb 2023 16:44:05 +0000 (17:44 +0100)
committerJan Janssen <medhefgo@web.de>
Fri, 10 Mar 2023 10:41:08 +0000 (11:41 +0100)
src/boot/efi/meson.build
src/boot/efi/util.c
tools/debug-sd-boot.sh
tools/elf2efi.lds

index 297eb0f5eefa5b68864b5dd506b3bc610a9a145b..6b04cfb4951b6792382a23b236dd3d8412d4f760 100644 (file)
@@ -92,6 +92,13 @@ efi_c_args += cc.get_supported_arguments(
         '-maccumulate-outgoing-args',
 )
 
+# Debug information has little value in release builds as no normal human being knows
+# how to attach a debugger to EFI binaries running on real hardware. Anyone who does
+# certainly has the means to do their own dev build.
+if get_option('mode') == 'developer' and get_option('debug')
+        efi_c_args += '-DEFI_DEBUG'
+endif
+
 efi_c_ld_args = [
         # We only support bfd. gold is going away, lld has issues with LTO on x86
         # and mold does not support linker scripts.
index 588d60dd0613d69b05e5a9cfd1f14b4503890a20..c8bbe7527795f730abf0ffd1bae89a8cc45d4b4a 100644 (file)
@@ -508,9 +508,9 @@ uint64_t get_os_indications_supported(void) {
 }
 
 #ifdef EFI_DEBUG
-extern uint8_t _text, _data;
+extern uint8_t __ImageBase;
 __attribute__((noinline)) void notify_debugger(const char *identity, volatile bool wait) {
-        printf("%s@%p,%p\n", identity, &_text, &_data);
+        printf("%s@%p\n", identity, &__ImageBase);
         if (wait)
                 printf("Waiting for debugger to attach...\n");
 
index b087c1d4d5ede3a73722a670b9d8ded00a6ffe17..0420dbdab7010f4cb24f68d05bef0cc48260cb88 100755 (executable)
@@ -51,19 +51,17 @@ case "${BASH_REMATCH[1]}" in
         exit 1
 esac
 
-# system-boot will print out a line like this to inform us where gdb is supposed to
-# look for .text and .data section:
-#        systemd-boot@0x0,0x0
+# system-boot/stub will print out a line like this to inform us where it was loaded:
+#        systemd-boot@0xC0DE
 while read -r line; do
-    if [[ "${line}" =~ ${target}@(0x[[:xdigit:]]+),(0x[[:xdigit:]]+) ]]; then
-        text="${BASH_REMATCH[1]}"
-        data="${BASH_REMATCH[2]}"
+    if [[ "${line}" =~ ${target}@(0x[[:xdigit:]]+) ]]; then
+        loaded_base="${BASH_REMATCH[1]}"
         break
     fi
 done <"${2}"
 
-if [[ -z "${text}" || -z "${data}" ]]; then
-    echo "Could not determine text and data location."
+if [[ -z "${loaded_base}" ]]; then
+    echo "Could not determine loaded image base."
     exit 1
 fi
 
@@ -76,8 +74,8 @@ fi
 
 cat >"${gdb_script}" <<EOF
 file ${binary}
-add-symbol-file ${symbols} ${text} -s .data ${data}
-set architecture ${arch}"
+symbol-file ${symbols} -o ${loaded_base}
+set architecture ${arch}
 EOF
 
 if [[ -z "${3}" ]]; then
index eed9e279e98ceb2bd2f05ec074f1505281e49458..805efc156d14886b4cf0313aee124960efe30d85 100644 (file)
@@ -1,4 +1,6 @@
 SECTIONS {
+        __ImageBase = .;
+
         /* We skip the first page because the space will be occupied by the PE headers after conversion. */
         . = CONSTANT(MAXPAGESIZE);
         .text ALIGN(CONSTANT(MAXPAGESIZE)) : {