From patchwork Mon Nov 5 18:44:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10668923 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 E63EF17D4 for ; Mon, 5 Nov 2018 18:45:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5E6E295E2 for ; Mon, 5 Nov 2018 18:45:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9EF729976; Mon, 5 Nov 2018 18:45:55 +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 626CE295E2 for ; Mon, 5 Nov 2018 18:45:55 +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=Uy0GrpgpU2ZYzFNASiITsfWBWLv7nZb41me14O7jVFs=; b=DFqxmWsdPNjSpa ulQ5EzM/HJeWsgaH2UzD9BdcnCnyC5O60bKre/z8nsC7F1E1euSNufh8Uqs4pXmbxPRqLzLWMpKgv tzgHVtbRbMN3FlCJkp7gaCdmNiYBVutBSG3SvTHNMXf8MjV5Ura9s7LwbZli/wbDCq5ZMu71yY1FR CHHgdQqb3iGaX2KE/rXbvbqCOcyAowf/x+DxInyBwUrHwJxPqr6TRCoy+lQMqn4HUCv5txsSRt9gg s0qMZC2jhxfM5f5U0mJSL7H06YR+kpOvMLgxT2GPzGSu16XEJG6fgv5vLn1l9lRe/pIBGjN1jSUql zT0vd2U3N3hdlJRgk3og==; 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 1gJjsn-000485-LZ; Mon, 05 Nov 2018 18:45:53 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJjs4-0001ur-Hp for linux-arm-kernel@lists.infradead.org; Mon, 05 Nov 2018 18:45:12 +0000 Received: by mail-wr1-x444.google.com with SMTP id o15-v6so7048059wrv.4 for ; Mon, 05 Nov 2018 10:45:01 -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=7syzrrpvzhMrE0+EM0swCFRh5FwJREr5Lqqb/OiR/qU=; b=Gc4Amew/4OUrzbZb0R+JnA260MYVHu0pktxPzZMJsrcUxKnZn4oTBiHG8DUjDQLGp1 YrUma0+lYKxDVcZnE4iT8oo9Tamt7Rs4Qr/4RQVkTpqC9v8pHL7Y4qOa1h5u5UxNoYyO XPDeMZk7YXkQWqCe7p5XQH56j/yGV6bI3/L5E= 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=7syzrrpvzhMrE0+EM0swCFRh5FwJREr5Lqqb/OiR/qU=; b=RZdB6Ve7Gg8+zIBymyWH/jVdMa0AIrfeQfgaPZstIL3wXcoFffJv+yMCav3cJtbEZC 6zIfyj/k+ZWu+Pbm1nOGaVtqy47wQdh0nyYNOng6xnzXkrD2+g7wo/9AyamHhsZOZj+P 4IuOjmKWX3MB3imPi1Vz1Sbu/d4/K6TplOYijPsvA0nb/GaVb0oTVVTjGyjRJGv98Pq+ KpnuKCRlV+Pni1GiSOIA022V5N3nPuxZuoZYE4L+zsOYVAUFWao2Nd/H+p8sSPovdh0d 1f4bzT/QO6v13HfE8hfv3CMk4mTTHNMaZpp1zv+gB+szUt/K++aP9FpY5ig6nPMe5ug2 mvKQ== X-Gm-Message-State: AGRZ1gJIXkSknTYvnvJhOQwyt0qzHTIbDw/Rv1tqqCLP92DLjwT/17Tl uimkTL5A1DYCdRDTw5/gs/PvaO1u7lk= X-Google-Smtp-Source: AJdET5c9kJdHwGp5NtdsCk87gkULKBFDqJmLgkIVh2+8OLhUYg7hUNfiLGwHNjnZHO+Ska6vfEN2gA== X-Received: by 2002:adf:bd0f:: with SMTP id j15-v6mr19563031wrh.267.1541443500251; Mon, 05 Nov 2018 10:45:00 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:3117:2b29:5ef7:a9e5]) by smtp.gmail.com with ESMTPSA id y21-v6sm19329761wma.36.2018.11.05.10.44.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 10:44:59 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 6/6] ARM: efi: add PE/COFF debug table to EFI header Date: Mon, 5 Nov 2018 19:44:38 +0100 Message-Id: <20181105184438.19494-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181105184438.19494-1-ard.biesheuvel@linaro.org> References: <20181105184438.19494-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_104508_695752_60D5E8BB X-CRM114-Status: GOOD ( 13.59 ) 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 d1862621556f..b3c7aff96b92 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -194,3 +194,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