From patchwork Thu Feb 2 17:33:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 93119 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp207534qgi; Thu, 2 Feb 2017 09:33:34 -0800 (PST) X-Received: by 10.98.33.66 with SMTP id h63mr12135418pfh.142.1486056814851; Thu, 02 Feb 2017 09:33:34 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g29si22919542plj.102.2017.02.02.09.33.34; Thu, 02 Feb 2017 09:33:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752145AbdBBRde (ORCPT + 2 others); Thu, 2 Feb 2017 12:33:34 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:35318 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751465AbdBBRdd (ORCPT ); Thu, 2 Feb 2017 12:33:33 -0500 Received: by mail-wm0-f45.google.com with SMTP id b65so100894465wmf.0 for ; Thu, 02 Feb 2017 09:33:33 -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; bh=1iCZg9lRc8sjQ8cGHBnszVroCukRdYp+BqrDVv4Lr0c=; b=Jc2UmPjV6XVlb3Lq4+m8xSj2s3hMqB6QxY/ZXGDeeKMqmRNBanmMK704zH/g9acq4E wPmJd4iPBAh5ozMMrjbUP8xlr8RHFfplV7R7mEQ8dsi/McMNIJQaRfyT4w/Hvqpbie3r YrYV6ExqpLyCsf00JgtRRdxsH10AbvjNlDQtc= 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; bh=1iCZg9lRc8sjQ8cGHBnszVroCukRdYp+BqrDVv4Lr0c=; b=mvE73Ix9Cwwh+8Y8P6zZN/qZ0h6XVI7+6T9HTgp9r3JcdCQH66iyxFkWV3vxvX34jO Rhn/QGKXadxQqjiCIo9rfPP+ozsHVCZAGdrBkpYyVpUMciFJAZ5RDGV+8s73dlwgBV5T tJM94JJhylGlsCPzvFsx7yEfZDSuGff28YbqD1fmq0iVVL7ozSHzm4GCpOZNQ73Jpnjf usQAlZn0suDmrYekZScEiZmsRqLJy/PEJ4+6hlq1UHyWUmRqPAYGooKT0xtlpKI7wuBU d3BYP6ZIwLtSbPP9nRDZM0NHdprJoRYA5DEbyyh7+Oo0VrZy3JW+pJtOBo4ZAh7D6p0K V2Ew== X-Gm-Message-State: AIkVDXK3Q4gVjsv49EmTYEbJZ7N6r6116mBWeBtfjGfzWxN3FK2bvjTuLTllQHpYf4rARN87 X-Received: by 10.28.180.132 with SMTP id d126mr29721444wmf.123.1486056812051; Thu, 02 Feb 2017 09:33:32 -0800 (PST) Received: from localhost.localdomain ([105.130.17.13]) by smtp.gmail.com with ESMTPSA id y30sm41002531wrc.23.2017.02.02.09.33.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Feb 2017 09:33:30 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, will.deacon@arm.com, mark.rutland@arm.com Cc: leif.lindholm@linaro.org, Ard Biesheuvel Subject: [PATCH v4] efi: arm64: Add vmlinux debug link to the Image binary Date: Thu, 2 Feb 2017 17:33:19 +0000 Message-Id: <1486056799-4825-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org When building with debugging symbols, take the absolute path to the vmlinux binary and add it to the special PE/COFF debug table entry. This allows a debug EFI build to find the vmlinux binary, which is very helpful in debugging, given that the offset where the Image is first loaded by EFI is highly unpredictable. On implementations of UEFI that choose to implement it, this information is exposed via the EFI debug support table, which is a UEFI configuration table that is accessible both by the firmware at boot time and by the OS at runtime, and lists all PE/COFF images loaded by the system. The format of the NB10 Codeview entry is based on the definition used by EDK2, which is our primary reference when it comes to the use of PE/COFF in the context of UEFI firmware. Signed-off-by: Ard Biesheuvel --- v4: add a separate DEBUG_EFI debug option so that this feature is disabled by default dropped 1/2 which has been queued already in the EFI tree use ASCII rather than an opaque constant for "NB10" signature arch/arm64/Kconfig.debug | 8 ++++ arch/arm64/kernel/Makefile | 4 ++ arch/arm64/kernel/head.S | 47 +++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index d1ebd46872fd..f7f38b1aab14 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -95,6 +95,14 @@ config DEBUG_ALIGN_RODATA If in doubt, say N. +config DEBUG_EFI + depends on EFI && DEBUG_INFO + bool "UEFI debugging" + help + Enable this option to include EFI specific debugging features into + the kernel that are only useful when using a debug build of the + UEFI firmware + source "drivers/hwtracing/coresight/Kconfig" endmenu diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 7d66bbaafc0c..2600c60337ac 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -55,3 +55,7 @@ obj-y += $(arm64-obj-y) vdso/ probes/ obj-m += $(arm64-obj-m) head-y := head.o extra-y += $(head-y) vmlinux.lds + +ifeq ($(CONFIG_DEBUG_EFI),y) +AFLAGS_head.o += -DVMLINUX_PATH="\"$(shell readlink -f $(objtree)/vmlinux)\"" +endif diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 4b1abac3485a..d9faf09f6401 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -149,7 +149,7 @@ extra_header_fields: .quad 0 // SizeOfHeapReserve .quad 0 // SizeOfHeapCommit .long 0 // LoaderFlags - .long 0x6 // NumberOfRvaAndSizes + .long (section_table - .) / 8 // NumberOfRvaAndSizes .quad 0 // ExportTable .quad 0 // ImportTable @@ -158,6 +158,11 @@ extra_header_fields: .quad 0 // CertificationTable .quad 0 // BaseRelocationTable +#ifdef CONFIG_DEBUG_EFI + .long efi_debug_table - _head // DebugTable + .long efi_debug_table_size +#endif + // Section table section_table: @@ -195,6 +200,46 @@ section_table: .short 0 // NumberOfLineNumbers (0 for executables) .long 0xe0500020 // Characteristics (section flags) +#ifdef CONFIG_DEBUG_EFI + /* + * 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 .init.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. + */ + __INITRODATA + + .align 2 +efi_debug_table: + // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY + .long 0 // Characteristics + .long 0 // TimeDateStamp + .short 0 // MajorVersion + .short 0 // MinorVersion + .long 2 // Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW + .long efi_debug_entry_size // SizeOfData + .long 0 // RVA + .long efi_debug_entry - _head // 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 + /* * EFI will load .text onwards at the 4k section alignment * described in the PE/COFF header. To ensure that instruction