* If users want to debug EFI applications via qemu + GDB, they need to know the relocated address of the application to align their symbols to in GDB via add-symbol-file. * This exposes where EFI applications are relocated to enable debugging EFI applications via qemu + gdb * Usage is generally determining the address, then add-symbol-file (efi loader) (address) * The address can change, but is generally consistent with the same qemu version and u-boot binary. (allowing you to boot once, find the address, then reboot with qemu -s -S --- include/efi_loader.h | 3 +++ lib/efi_loader/efi_boottime.c | 1 + lib/efi_loader/efi_image_loader.c | 3 +++ 3 files changed, 7 insertions(+)
diff --git a/include/efi_loader.h b/include/efi_loader.h index f4860e87fc..2ca2bf3adb 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -403,6 +403,7 @@ enum efi_image_auth_status { * @exit_data_size: exit data size passed to Exit() * @exit_data: exit data passed to Exit() * @exit_jmp: long jump buffer for returning from started image + * @reloc_addr: relocated address of the image * @entry: entry address of the relocated image * @image_type: indicates if the image is an applicition or a driver * @auth_status: indicates if the image is authenticated @@ -413,6 +414,8 @@ struct efi_loaded_image_obj { efi_uintn_t *exit_data_size; u16 **exit_data; struct jmp_buf_data *exit_jmp; + + u64 reloc_addr; EFIAPI efi_status_t (*entry)(efi_handle_t image_handle, struct efi_system_table *st); u16 image_type; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 20b69699fe..6fac8c576e 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3057,6 +3057,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, current_image = image_handle; image_obj->header.type = EFI_OBJECT_TYPE_STARTED_IMAGE; + log_info("EFI image relocated to 0x%llx\n", image_obj->reloc_addr); EFI_PRINT("Jumping into 0x%p\n", image_obj->entry); ret = EFI_CALL(image_obj->entry(image_handle, &systab)); diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index 773bd0677c..65e5b7e40b 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -906,6 +906,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, ret = EFI_OUT_OF_RESOURCES; goto err; } + handle->reloc_addr = (u64)efi_reloc; handle->entry = efi_reloc + opt->AddressOfEntryPoint; rel_size = opt->DataDirectory[rel_idx].Size; rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress; @@ -922,6 +923,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, ret = EFI_OUT_OF_RESOURCES; goto err; } + + handle->reloc_addr = (u64)efi_reloc; handle->entry = efi_reloc + opt->AddressOfEntryPoint; rel_size = opt->DataDirectory[rel_idx].Size; rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress; -- 2.35.1