From patchwork Mon Nov 5 19:43:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10669083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C07F015A6 for ; Mon, 5 Nov 2018 20:19:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A455429E67 for ; Mon, 5 Nov 2018 20:19:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9869429E6A; Mon, 5 Nov 2018 20:19:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2D53B29E67 for ; Mon, 5 Nov 2018 20:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=d4/mh/2U5FJSCGP93qTzqLGhujh1wvDseH/PdVyDHK0=; b=ikFN6aL7w0S9cc skv59YhEAUL+THkZTHemA1TCzNvh5Gwp/JFaXqQpOwwdilz1pcPdRCoqeEc7xRYbbbIJ9W+1Crqrf 3QwMo625y2q+rioPJiFCJjaT5EH6nfaxJ7OlzWmqmdyJjcDNo8NRe8B20z93Jn2l9t6eCwX99l/bz g3fG7gNcQgQzo/sthQr7Ib/ymfbZfGsse5vK7CruN2ueffa6agX1zBdK6oz3LWwaofqPASc8I/9/S +GgHjVApg0357DsMnMsqnFiQXvHALiEpLTJ0fSUCIUnS762dDdKWE6fcJnkIrnyBtZLNKwRlVzYKC HZ5H38/4/NMLMBJWolLg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJlLn-0004EH-VX; Mon, 05 Nov 2018 20:19:56 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJkmi-0008OI-M8 for linux-arm-kernel@lists.infradead.org; Mon, 05 Nov 2018 19:44:24 +0000 Received: by mail-wm1-x344.google.com with SMTP id v24-v6so9592522wmh.3 for ; Mon, 05 Nov 2018 11:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mOmpu3P7v3gpXrLZh9WU+3bPVnKAcjO0G6US5FBumbY=; b=Oyq7RJ/r2j+Zr2IbRwgYxLO9A/+BAxvL4WijrTfi1hbNlfZRPGfORztp19IaSV1DdK 8hDA3yfc8XJ/jY31vo15Htl+cIPwIwtobd5EHNMtFiC++7diAt8Ggdd5EWk9zRCA/M3F DhwYJxmfviHkQHfrLDvWCKJx8dI16HVOmtXCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mOmpu3P7v3gpXrLZh9WU+3bPVnKAcjO0G6US5FBumbY=; b=HIn0daHTKH5p0tVqUaU703RhVz7oSMLyIMROkxiMxepTJO2xN6WYBSvRAL0RvnoGRY d2pukziX/7KTHuh3OIwVcAr5eMJWnaXQ4031BEH7dK9pvdrIg6zNory0l1ewdJqgzvpb RqXU6V3tu0zA8rkugGSMT/4OqGZ6WXTz9CIXc6EEh/pohRWRTHvMBXK1XT+bNN3Zb5UN BulSWlIhA6nGCNcVYNKu5rW4PYmUZDkO8kdCNdQMHxLmhPjbRz58j5/hL3Bd2qxmlnWe B8qydL2VzE73XJqcaFNlYdZDh6e7vJGrGeVe3HzfQFgZtGaRNR6SHDQwufOCR01yjcYo 2gsQ== X-Gm-Message-State: AGRZ1gIt8rNiy8TQjuZY0xpdSlGenz4kocmXcxNwcz5E0cIKJX0I+And CUaOnU1zb3k6ViuDwtG1/4O2V/aF53I= X-Google-Smtp-Source: AJdET5d1vmQxZh2MIwVsM0GVnirW1RfFQ9cgrYE+qg3Gxkk5N1ogPJ80lJuQ/XgZtL22VQV01KPRIA== X-Received: by 2002:a1c:7e8f:: with SMTP id z137-v6mr7026249wmc.140.1541447007761; Mon, 05 Nov 2018 11:43:27 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:3117:2b29:5ef7:a9e5]) by smtp.gmail.com with ESMTPSA id x197-v6sm45518322wme.15.2018.11.05.11.43.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 11:43:26 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 2/2] ARM: efi: add PE/COFF debug table to EFI header Date: Mon, 5 Nov 2018 20:43:21 +0100 Message-Id: <20181105194321.26657-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181105194321.26657-1-ard.biesheuvel@linaro.org> References: <20181105194321.26657-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181105_114359_682643_1AABC29F X-CRM114-Status: GOOD ( 13.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nicolas.pitre@linaro.org, linux@armlinux.org.uk, Ard Biesheuvel Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This updates the PE/COFF header to emit the absolute path to the decompressor vmlinux ELF file into a so-called NB10 Codeview entry. On DEBUG builds of EDK2 for ARM, this will result in output to be printed as follows add-symbol-file /home/ard/linux-build-arm/arch/arm/boot/compressed/vmlinux 0x43889000 which can be consumed by GDB directly, and load the decompressor ELF symbols at the correct offset in the UEFI address space. With both the decompressor and the firmware's ELF symbols loaded, we can do single step debugging of calls made from the EFI stub into the firmware and back, which is *really* helpful when debugging the handover from UEFI to the decompressor. Signed-off-by: Ard Biesheuvel --- arch/arm/boot/compressed/Makefile | 4 ++ arch/arm/boot/compressed/efi-header.S | 47 ++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index 01bf2585a0fa..727584a7a602 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -202,3 +202,7 @@ AFLAGS_hyp-stub.o := -Wa,-march=armv7-a $(obj)/hyp-stub.S: $(srctree)/arch/$(SRCARCH)/kernel/hyp-stub.S $(call cmd,shipped) + +ifeq ($(CONFIG_EFI)$(CONFIG_DEBUG_INFO),yy) +AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(obj)/vmlinux)\"" +endif diff --git a/arch/arm/boot/compressed/efi-header.S b/arch/arm/boot/compressed/efi-header.S index c94a88ae834d..5c29b31e7080 100644 --- a/arch/arm/boot/compressed/efi-header.S +++ b/arch/arm/boot/compressed/efi-header.S @@ -98,6 +98,11 @@ extra_header_fields: .quad 0 @ CertificationTable .quad 0 @ BaseRelocationTable +#ifdef CONFIG_DEBUG_INFO + .long efi_debug_table - start @ DebugTable + .long efi_debug_table_size +#endif + section_table: .ascii ".text\0\0\0" .long __pecoff_code_size @ VirtualSize @@ -127,6 +132,48 @@ section_table: .set section_count, (. - section_table) / 40 +#ifdef CONFIG_DEBUG_INFO + /* + * The debug table is referenced via its Relative Virtual + * Address (RVA), which is only defined for those parts of + * the image that are covered by a section declaration. Since + * this header is not covered by any section, the debug table + * must be emitted elsewhere. So stick it in the .rodata + * section instead. + * + * Note that the EFI debug entry itself may legally have a + * zero RVA, which means we can simply put it right after the + * section headers. + */ + .section ".rodata", #alloc + + .align 2 +efi_debug_table: + // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY + .long 0 @ Characteristics + .long 0 @ TimeDateStamp + .short 0 @ MajorVersion + .short 0 @ MinorVersion + .long IMAGE_DEBUG_TYPE_CODEVIEW @ Type + .long efi_debug_entry_size @ SizeOfData + .long 0 @ RVA + .long efi_debug_entry - start @ FileOffset + + .set efi_debug_table_size, . - efi_debug_table + .previous + +efi_debug_entry: + // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY + .ascii "NB10" @ Signature + .long 0 @ Unknown + .long 0 @ Unknown2 + .long 0 @ Unknown3 + + .asciz VMLINUX_PATH + + .set efi_debug_entry_size, . - efi_debug_entry +#endif + .align 12 __efi_start: #endif