* [RFC PATCH 0/2] efi/arm64: add vmlinux link to PE/COFF debug table @ 2016-10-19 11:40 Ard Biesheuvel 2016-10-19 11:40 ` [RFC PATCH 1/2] efi: libstub: preserve .debug sections after absolute relocation check Ard Biesheuvel 2016-10-19 11:40 ` [RFC PATCH 2/2] efi: arm64: add vmlinux debug link to the Image binary Ard Biesheuvel 0 siblings, 2 replies; 4+ messages in thread From: Ard Biesheuvel @ 2016-10-19 11:40 UTC (permalink / raw) To: linux-efi, linux-arm-kernel Cc: mark.rutland, matt, Ard Biesheuvel, leif.lindholm, eugene Much like GNU debug links, PE/COFF binaries can carry the patch to the binary containing the debugging symbols. Since the kernel binary is loaded by UEFI at an a priori unknown offset in the 1:1 mapping of physical memory, having this information is useful for the debugger automation to find the file and the offset, and load the symbols automatically. So if we have debugging symbols to begin with (CONFIG_DEBUG_INFO=y), add the absolute path to vmlinux to the PE/COFF debug table. Ard Biesheuvel (2): efi: libstub: preserve .debug sections after absolute relocation check efi: arm64: add vmlinux debug link to the Image binary arch/arm64/kernel/Makefile | 4 +++ arch/arm64/kernel/head.S | 34 +++++++++++++++++++- arch/arm64/kernel/image.h | 3 ++ drivers/firmware/efi/libstub/Makefile | 19 ++++++++--- 4 files changed, 54 insertions(+), 6 deletions(-) -- 2.7.4 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [RFC PATCH 1/2] efi: libstub: preserve .debug sections after absolute relocation check 2016-10-19 11:40 [RFC PATCH 0/2] efi/arm64: add vmlinux link to PE/COFF debug table Ard Biesheuvel @ 2016-10-19 11:40 ` Ard Biesheuvel 2016-10-19 12:55 ` Cohen, Eugene 2016-10-19 11:40 ` [RFC PATCH 2/2] efi: arm64: add vmlinux debug link to the Image binary Ard Biesheuvel 1 sibling, 1 reply; 4+ messages in thread From: Ard Biesheuvel @ 2016-10-19 11:40 UTC (permalink / raw) To: linux-efi, linux-arm-kernel Cc: mark.rutland, matt, Ard Biesheuvel, leif.lindholm, eugene The build commands for the ARM and arm64 EFI stubs strips the .debug sections and other sections that my legally contain absolute relocations, in order to inspect the remaining sections for the presence of such relocations. This leaves us without debugging symbols in the stub for no good reason, given that these sections are omitted from the kernel binary, and that these relocations are thus only interpreted by the debugger. So if the relocation check succeeds, invoke objcopy again, but this time, leave the .debug sections in place. Note that these sections may refer to ksymtab/kcrctab contents, so leave those in place as well. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> --- drivers/firmware/efi/libstub/Makefile | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index c06945160a41..66584f173123 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -60,7 +60,7 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) extra-$(CONFIG_EFI_ARMSTUB) := $(lib-y) lib-$(CONFIG_EFI_ARMSTUB) := $(patsubst %.o,%.stub.o,$(lib-y)) -STUBCOPY_FLAGS-y := -R .debug* -R *ksymtab* -R *kcrctab* +STUBCOPY_RM := -R .debug* -R *ksymtab* -R *kcrctab* STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \ --prefix-symbols=__efistub_ STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS @@ -68,11 +68,20 @@ STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS $(obj)/%.stub.o: $(obj)/%.o FORCE $(call if_changed,stubcopy) +# +# This calls objcopy twice: the first time it includes STUBCOPY_RM, and inspects +# the result to ensure that the actual code itself does not contain any absolute +# references. If this succeeds, the objcopy is performed a second time, but this +# time the .debug and other sections are retained, given that we know that the +# absolute relocations they may contain are harmless. +# quiet_cmd_stubcopy = STUBCPY $@ - cmd_stubcopy = if $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@; then \ - $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y) \ - && (echo >&2 "$@: absolute symbol references not allowed in the EFI stub"; \ - rm -f $@; /bin/false); else /bin/false; fi + cmd_stubcopy = if $(OBJCOPY) $(STUBCOPY_FLAGS-y) $(STUBCOPY_RM) $< $@; \ + then if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); \ + then (echo >&2 "$@: absolute symbol references not allowed in the EFI stub"; \ + rm -f $@; /bin/false); \ + else $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@; fi \ + else /bin/false; fi # # ARM discards the .data section because it disallows r/w data in the -- 2.7.4 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [RFC PATCH 1/2] efi: libstub: preserve .debug sections after absolute relocation check 2016-10-19 11:40 ` [RFC PATCH 1/2] efi: libstub: preserve .debug sections after absolute relocation check Ard Biesheuvel @ 2016-10-19 12:55 ` Cohen, Eugene 0 siblings, 0 replies; 4+ messages in thread From: Cohen, Eugene @ 2016-10-19 12:55 UTC (permalink / raw) To: Ard Biesheuvel, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: mark.rutland@arm.com, matt@codeblueprint.co.uk, leif.lindholm@linaro.org I was literally just looking at this. I originally commented out the removal of debug (which I though was really annoying) but ran into the absolute relocations warning for symbols that it need not apply to. Your two-pass solution is a nice one. > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Wednesday, October 19, 2016 5:41 AM > To: linux-efi@vger.kernel.org; linux-arm-kernel@lists.infradead.org > Cc: mark.rutland@arm.com; leif.lindholm@linaro.org; Cohen, Eugene > <eugene@hp.com>; matt@codeblueprint.co.uk; Ard Biesheuvel > <ard.biesheuvel@linaro.org> > Subject: [RFC PATCH 1/2] efi: libstub: preserve .debug sections after absolute > relocation check > > The build commands for the ARM and arm64 EFI stubs strips the .debug > sections and other sections that my legally contain absolute relocations, > in order to inspect the remaining sections for the presence of such > relocations. > > This leaves us without debugging symbols in the stub for no good reason, > given that these sections are omitted from the kernel binary, and that > these relocations are thus only interpreted by the debugger. > > So if the relocation check succeeds, invoke objcopy again, but this time, > leave the .debug sections in place. Note that these sections may refer > to ksymtab/kcrctab contents, so leave those in place as well. > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Eugene Cohen <eugene@hp.com> > --- > drivers/firmware/efi/libstub/Makefile | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/drivers/firmware/efi/libstub/Makefile > b/drivers/firmware/efi/libstub/Makefile > index c06945160a41..66584f173123 100644 > --- a/drivers/firmware/efi/libstub/Makefile > +++ b/drivers/firmware/efi/libstub/Makefile > @@ -60,7 +60,7 @@ CFLAGS_arm64-stub.o := - > DTEXT_OFFSET=$(TEXT_OFFSET) > extra-$(CONFIG_EFI_ARMSTUB) := $(lib-y) > lib-$(CONFIG_EFI_ARMSTUB) := $(patsubst %.o,%.stub.o,$(lib-y)) > > -STUBCOPY_FLAGS-y := -R .debug* -R *ksymtab* -R *kcrctab* > +STUBCOPY_RM := -R .debug* -R *ksymtab* -R *kcrctab* > STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \ > --prefix-symbols=__efistub_ > STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS > @@ -68,11 +68,20 @@ STUBCOPY_RELOC-$(CONFIG_ARM64) := > R_AARCH64_ABS > $(obj)/%.stub.o: $(obj)/%.o FORCE > $(call if_changed,stubcopy) > > +# > +# This calls objcopy twice: the first time it includes STUBCOPY_RM, and inspects > +# the result to ensure that the actual code itself does not contain any absolute > +# references. If this succeeds, the objcopy is performed a second time, but this > +# time the .debug and other sections are retained, given that we know that the > +# absolute relocations they may contain are harmless. > +# > quiet_cmd_stubcopy = STUBCPY $@ > - cmd_stubcopy = if $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@; then \ > - $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y) \ > - && (echo >&2 "$@: absolute symbol references not allowed in > the EFI stub"; \ > - rm -f $@; /bin/false); else /bin/false; fi > + cmd_stubcopy = if $(OBJCOPY) $(STUBCOPY_FLAGS-y) $(STUBCOPY_RM) $< > $@; \ > + then if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); \ > + then (echo >&2 "$@: absolute symbol references not allowed > in the EFI stub"; \ > + rm -f $@; /bin/false); \ > + else $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@; fi \ > + else /bin/false; fi > > # > # ARM discards the .data section because it disallows r/w data in the > -- > 2.7.4 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [RFC PATCH 2/2] efi: arm64: add vmlinux debug link to the Image binary 2016-10-19 11:40 [RFC PATCH 0/2] efi/arm64: add vmlinux link to PE/COFF debug table Ard Biesheuvel 2016-10-19 11:40 ` [RFC PATCH 1/2] efi: libstub: preserve .debug sections after absolute relocation check Ard Biesheuvel @ 2016-10-19 11:40 ` Ard Biesheuvel 1 sibling, 0 replies; 4+ messages in thread From: Ard Biesheuvel @ 2016-10-19 11:40 UTC (permalink / raw) To: linux-efi, linux-arm-kernel Cc: mark.rutland, matt, Ard Biesheuvel, leif.lindholm, eugene 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. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> --- arch/arm64/kernel/Makefile | 4 +++ arch/arm64/kernel/head.S | 34 +++++++++++++++++++- arch/arm64/kernel/image.h | 3 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 7d66bbaafc0c..1def85599fdb 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 + +ifneq ($(CONFIG_DEBUG_INFO),) +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 427f6d3f084c..2f3fbd966de7 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_INFO + .long efi_debug_table - _head // DebugTable + .long efi_debug_table_size +#endif + // Section table section_table: @@ -206,6 +211,33 @@ section_table: efi_header_end: #endif +#ifdef CONFIG_DEBUG_INFO + __INITDATA + +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 efi_debug_entry_offset // RVA + .long efi_debug_entry_offset // FileOffset + +ENTRY(efi_debug_entry) + // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY + .long 0x3031424E // Signature + .long 0 // Unknown + .long 0 // Unknown2 + .long 0 // Unknown3 + + .asciz VMLINUX_PATH + + .set efi_debug_entry_size, . - efi_debug_entry + .set efi_debug_table_size, . - efi_debug_table +#endif + __INIT /* diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h index c7fcb232fe47..ad5406f011c2 100644 --- a/arch/arm64/kernel/image.h +++ b/arch/arm64/kernel/image.h @@ -116,6 +116,9 @@ __efistub__end = KALLSYMS_HIDE(_end); __efistub__edata = KALLSYMS_HIDE(_edata); __efistub_screen_info = KALLSYMS_HIDE(screen_info); +#ifdef CONFIG_DEBUG_INFO +efi_debug_entry_offset = efi_debug_entry - _text; +#endif #endif #endif /* __ASM_IMAGE_H */ -- 2.7.4 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-10-19 12:55 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-10-19 11:40 [RFC PATCH 0/2] efi/arm64: add vmlinux link to PE/COFF debug table Ard Biesheuvel 2016-10-19 11:40 ` [RFC PATCH 1/2] efi: libstub: preserve .debug sections after absolute relocation check Ard Biesheuvel 2016-10-19 12:55 ` Cohen, Eugene 2016-10-19 11:40 ` [RFC PATCH 2/2] efi: arm64: add vmlinux debug link to the Image binary Ard Biesheuvel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).