Skip to content

Commit 757b435

Browse files
Ard Biesheuvelwildea01
authored andcommitted
efi: arm64: Add vmlinux debug link to the Image binary
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 <ard.biesheuvel@linaro.org> [will: use realpath instead of shell invocation, as discussed on list] Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 965861d commit 757b435

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

arch/arm64/Kconfig.debug

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ config DEBUG_ALIGN_RODATA
9595

9696
If in doubt, say N.
9797

98+
config DEBUG_EFI
99+
depends on EFI && DEBUG_INFO
100+
bool "UEFI debugging"
101+
help
102+
Enable this option to include EFI specific debugging features into
103+
the kernel that are only useful when using a debug build of the
104+
UEFI firmware
105+
98106
source "drivers/hwtracing/coresight/Kconfig"
99107

100108
endmenu

arch/arm64/kernel/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ obj-y += $(arm64-obj-y) vdso/ probes/
5555
obj-m += $(arm64-obj-m)
5656
head-y := head.o
5757
extra-y += $(head-y) vmlinux.lds
58+
59+
ifeq ($(CONFIG_DEBUG_EFI),y)
60+
AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\""
61+
endif

arch/arm64/kernel/head.S

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ extra_header_fields:
149149
.quad 0 // SizeOfHeapReserve
150150
.quad 0 // SizeOfHeapCommit
151151
.long 0 // LoaderFlags
152-
.long 0x6 // NumberOfRvaAndSizes
152+
.long (section_table - .) / 8 // NumberOfRvaAndSizes
153153

154154
.quad 0 // ExportTable
155155
.quad 0 // ImportTable
@@ -158,6 +158,11 @@ extra_header_fields:
158158
.quad 0 // CertificationTable
159159
.quad 0 // BaseRelocationTable
160160

161+
#ifdef CONFIG_DEBUG_EFI
162+
.long efi_debug_table - _head // DebugTable
163+
.long efi_debug_table_size
164+
#endif
165+
161166
// Section table
162167
section_table:
163168

@@ -195,6 +200,46 @@ section_table:
195200
.short 0 // NumberOfLineNumbers (0 for executables)
196201
.long 0xe0500020 // Characteristics (section flags)
197202

203+
#ifdef CONFIG_DEBUG_EFI
204+
/*
205+
* The debug table is referenced via its Relative Virtual Address (RVA),
206+
* which is only defined for those parts of the image that are covered
207+
* by a section declaration. Since this header is not covered by any
208+
* section, the debug table must be emitted elsewhere. So stick it in
209+
* the .init.rodata section instead.
210+
*
211+
* Note that the EFI debug entry itself may legally have a zero RVA,
212+
* which means we can simply put it right after the section headers.
213+
*/
214+
__INITRODATA
215+
216+
.align 2
217+
efi_debug_table:
218+
// EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
219+
.long 0 // Characteristics
220+
.long 0 // TimeDateStamp
221+
.short 0 // MajorVersion
222+
.short 0 // MinorVersion
223+
.long 2 // Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW
224+
.long efi_debug_entry_size // SizeOfData
225+
.long 0 // RVA
226+
.long efi_debug_entry - _head // FileOffset
227+
228+
.set efi_debug_table_size, . - efi_debug_table
229+
.previous
230+
231+
efi_debug_entry:
232+
// EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
233+
.ascii "NB10" // Signature
234+
.long 0 // Unknown
235+
.long 0 // Unknown2
236+
.long 0 // Unknown3
237+
238+
.asciz VMLINUX_PATH
239+
240+
.set efi_debug_entry_size, . - efi_debug_entry
241+
#endif
242+
198243
/*
199244
* EFI will load .text onwards at the 4k section alignment
200245
* described in the PE/COFF header. To ensure that instruction

0 commit comments

Comments
 (0)