All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images
@ 2018-09-26  6:03 Bin Meng
  2018-09-26  6:03 ` [U-Boot] [PATCH 2/5] x86: efi: payload: Generate Microsoft PE format complaint image Bin Meng
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Bin Meng @ 2018-09-26  6:03 UTC (permalink / raw)
  To: u-boot

Per Microsoft PE Format documentation [1], PointerToSymbolTable and
NumberOfSymbols should be zero for an image in the COFF file header.
Currently U-Boot is generating *.efi images (eg: helloworld.efi) in
which these two members are not zero.

This updates the build rules to tell linker to remove the symbol
table completely so that we can generate compliant *.efi images.

[1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format

Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 scripts/Makefile.lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index f8c3fff..91f0b20 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -381,7 +381,7 @@ $(obj)/%.efi: $(obj)/%_efi.so
 
 quiet_cmd_efi_ld = LD      $@
 cmd_efi_ld = $(LD) -nostdlib -znocombreloc -T $(EFI_LDS_PATH) -shared \
-		-Bsymbolic $^ -o $@
+		-Bsymbolic -s $^ -o $@
 
 EFI_LDS_PATH = $(srctree)/arch/$(ARCH)/lib/$(EFI_LDS)
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 2/5] x86: efi: payload: Generate Microsoft PE format complaint image
  2018-09-26  6:03 [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images Bin Meng
@ 2018-09-26  6:03 ` Bin Meng
  2018-09-26  6:03 ` [U-Boot] [PATCH 3/5] x86: efi: app: " Bin Meng
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Bin Meng @ 2018-09-26  6:03 UTC (permalink / raw)
  To: u-boot

Per Microsoft PE Format documentation [1], PointerToSymbolTable and
NumberOfSymbols should be zero for an image in the COFF file header.
Currently U-Boot is generating u-boot-payload.efi image in which
these two members are not zero.

This updates the build rules to tell linker to remove the symbol
table completely so that we can generate compliant *.efi images.

[1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format

Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 arch/x86/config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/config.mk b/arch/x86/config.mk
index 5b04feb..483ff95 100644
--- a/arch/x86/config.mk
+++ b/arch/x86/config.mk
@@ -34,7 +34,7 @@ PLATFORM_LDFLAGS += -m $(if $(IS_32BIT),elf_i386,elf_x86_64)
 
 # This is used in the top-level Makefile which does not include
 # PLATFORM_LDFLAGS
-LDFLAGS_EFI_PAYLOAD := -Bsymbolic -Bsymbolic-functions -shared --no-undefined
+LDFLAGS_EFI_PAYLOAD := -Bsymbolic -Bsymbolic-functions -shared --no-undefined -s
 
 OBJCOPYFLAGS_EFI := -j .text -j .sdata -j .data -j .dynamic -j .dynsym \
 	-j .rel -j .rela -j .reloc
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 3/5] x86: efi: app: Generate Microsoft PE format complaint image
  2018-09-26  6:03 [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images Bin Meng
  2018-09-26  6:03 ` [U-Boot] [PATCH 2/5] x86: efi: payload: Generate Microsoft PE format complaint image Bin Meng
@ 2018-09-26  6:03 ` Bin Meng
  2018-09-26  6:03 ` [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images Bin Meng
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Bin Meng @ 2018-09-26  6:03 UTC (permalink / raw)
  To: u-boot

Per Microsoft PE Format documentation [1], PointerToSymbolTable and
NumberOfSymbols should be zero for an image in the COFF file header.
Currently U-Boot is generating u-boot-app.efi in which these two
members are not zero.

This updates the build rules to tell linker to remove the symbol
table completely so that we can generate compliant *.efi images.

[1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 arch/x86/config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/config.mk b/arch/x86/config.mk
index 483ff95..0e50e18 100644
--- a/arch/x86/config.mk
+++ b/arch/x86/config.mk
@@ -65,7 +65,7 @@ CPPFLAGS_crt0-efi-$(EFIARCH).o += $(CFLAGS_EFI)
 ifeq ($(CONFIG_EFI_APP),y)
 
 PLATFORM_CPPFLAGS += $(CFLAGS_EFI)
-LDFLAGS_FINAL += -znocombreloc -shared
+LDFLAGS_FINAL += -znocombreloc -shared -s
 LDSCRIPT := $(LDSCRIPT_EFI)
 
 else
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images
  2018-09-26  6:03 [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images Bin Meng
  2018-09-26  6:03 ` [U-Boot] [PATCH 2/5] x86: efi: payload: Generate Microsoft PE format complaint image Bin Meng
  2018-09-26  6:03 ` [U-Boot] [PATCH 3/5] x86: efi: app: " Bin Meng
@ 2018-09-26  6:03 ` Bin Meng
  2018-09-26 17:51   ` Heinrich Schuchardt
  2018-09-26  6:03 ` [U-Boot] [PATCH 5/5] riscv: " Bin Meng
  2018-09-26 18:40 ` [U-Boot] [PATCH 1/5] efi_loader: " Heinrich Schuchardt
  4 siblings, 1 reply; 11+ messages in thread
From: Bin Meng @ 2018-09-26  6:03 UTC (permalink / raw)
  To: u-boot

Per Microsoft PE Format documentation [1], PointerToSymbolTable and
NumberOfSymbols should be zero for an image in the COFF file header.
Currently the COFF file header is hardcoded on ARM and these two
members are not zero.

This updates the hardcoded structure to clear these two members, as
well as setting the flag IMAGE_FILE_LOCAL_SYMS_STRIPPED so that we
can generate compliant *.efi images.

[1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 arch/arm/lib/crt0_aarch64_efi.S | 7 ++++---
 arch/arm/lib/crt0_arm_efi.S     | 6 +++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
index 0db4360..a489d05 100644
--- a/arch/arm/lib/crt0_aarch64_efi.S
+++ b/arch/arm/lib/crt0_aarch64_efi.S
@@ -28,13 +28,14 @@ coff_header:
 	.short	2				/* nr_sections */
 	.long	0				/* TimeDateStamp */
 	.long	0				/* PointerToSymbolTable */
-	.long	1				/* NumberOfSymbols */
+	.long	0				/* NumberOfSymbols */
 	.short	section_table - optional_header	/* SizeOfOptionalHeader */
 	/*
 	 * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
-	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
+	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED |
+	 * IMAGE_FILE_LOCAL_SYMS_STRIPPED
 	 */
-	.short	0x206
+	.short	0x20e
 optional_header:
 	.short	0x20b				/* PE32+ format */
 	.byte	0x02				/* MajorLinkerVersion */
diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
index 23db49f..5330578 100644
--- a/arch/arm/lib/crt0_arm_efi.S
+++ b/arch/arm/lib/crt0_arm_efi.S
@@ -27,14 +27,14 @@ coff_header:
 	.short	2				/* nr_sections */
 	.long	0				/* TimeDateStamp */
 	.long	0				/* PointerToSymbolTable */
-	.long	1				/* NumberOfSymbols */
+	.long	0				/* NumberOfSymbols */
 	.short	section_table - optional_header	/* SizeOfOptionalHeader */
 	/*
 	 * Characteristics: IMAGE_FILE_32BIT_MACHINE |
 	 * IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
-	 * IMAGE_FILE_LINE_NUMS_STRIPPED
+	 * IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_LOCAL_SYMS_STRIPPED
 	 */
-	.short	0x306
+	.short	0x30e
 optional_header:
 	.short	0x10b				/* PE32+ format */
 	.byte	0x02				/* MajorLinkerVersion */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 5/5] riscv: efi: Generate Microsoft PE format complaint images
  2018-09-26  6:03 [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images Bin Meng
                   ` (2 preceding siblings ...)
  2018-09-26  6:03 ` [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images Bin Meng
@ 2018-09-26  6:03 ` Bin Meng
  2018-09-26 17:49   ` Heinrich Schuchardt
  2018-09-26 18:40 ` [U-Boot] [PATCH 1/5] efi_loader: " Heinrich Schuchardt
  4 siblings, 1 reply; 11+ messages in thread
From: Bin Meng @ 2018-09-26  6:03 UTC (permalink / raw)
  To: u-boot

Per Microsoft PE Format documentation [1], PointerToSymbolTable and
NumberOfSymbols should be zero for an image in the COFF file header.
Currently the COFF file header is hardcoded on RISC-V and these two
members are not zero.

This updates the hardcoded structure to clear these two members, as
well as setting the flag IMAGE_FILE_LOCAL_SYMS_STRIPPED so that we
can generate compliant *.efi images.

[1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 arch/riscv/lib/crt0_riscv_efi.S | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
index 18f61f5..6d61b3a 100644
--- a/arch/riscv/lib/crt0_riscv_efi.S
+++ b/arch/riscv/lib/crt0_riscv_efi.S
@@ -41,13 +41,14 @@ coff_header:
 	.short	2				/* nr_sections */
 	.long	0				/* TimeDateStamp */
 	.long	0				/* PointerToSymbolTable */
-	.long	1				/* NumberOfSymbols */
+	.long	0				/* NumberOfSymbols */
 	.short	section_table - optional_header	/* SizeOfOptionalHeader */
 	/*
 	 * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
-	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
+	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED |
+	 * IMAGE_FILE_LOCAL_SYMS_STRIPPED
 	 */
-	.short	0x206
+	.short	0x20e
 optional_header:
 	.short	0x20b				/* PE32+ format */
 	.byte	0x02				/* MajorLinkerVersion */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 5/5] riscv: efi: Generate Microsoft PE format complaint images
  2018-09-26  6:03 ` [U-Boot] [PATCH 5/5] riscv: " Bin Meng
@ 2018-09-26 17:49   ` Heinrich Schuchardt
  0 siblings, 0 replies; 11+ messages in thread
From: Heinrich Schuchardt @ 2018-09-26 17:49 UTC (permalink / raw)
  To: u-boot

On 09/26/2018 08:03 AM, Bin Meng wrote:
> Per Microsoft PE Format documentation [1], PointerToSymbolTable and
> NumberOfSymbols should be zero for an image in the COFF file header.
> Currently the COFF file header is hardcoded on RISC-V and these two
> members are not zero.
> 
> This updates the hardcoded structure to clear these two members, as
> well as setting the flag IMAGE_FILE_LOCAL_SYMS_STRIPPED so that we
> can generate compliant *.efi images.
> 
> [1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format
> 
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
> 
>  arch/riscv/lib/crt0_riscv_efi.S | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> index 18f61f5..6d61b3a 100644
> --- a/arch/riscv/lib/crt0_riscv_efi.S
> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> @@ -41,13 +41,14 @@ coff_header:
>  	.short	2				/* nr_sections */
>  	.long	0				/* TimeDateStamp */
>  	.long	0				/* PointerToSymbolTable */
> -	.long	1				/* NumberOfSymbols */
> +	.long	0				/* NumberOfSymbols */
>  	.short	section_table - optional_header	/* SizeOfOptionalHeader */
>  	/*
>  	 * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
> -	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
> +	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED |
> +	 * IMAGE_FILE_LOCAL_SYMS_STRIPPED
>  	 */

Thanks for your patch.

I think your code misses to set IMAGE_FILE_32BIT_MACHINE in dependence
of the bitness of the system.

I would prefer if these constants were defined in asm-generic/pe.h:

#define IMAGE_FILE_RELOCS_STRIPPED		0x0001
#define IMAGE_FILE_EXECUTABLE_IMAGE		0x0002
#define IMAGE_FILE_LINE_NUMS_STRIPPED		0x0004
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED		0x0008
#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 		0x0010
#define IMAGE_FILE_LARGE_ADDRESS_AWARE		0x0020
/* Reserved					0x0040 */
#define IMAGE_FILE_BYTES_REVERSED_LO		0x0080
#define IMAGE_FILE_32BIT_MACHINE		0x0100
#define IMAGE_FILE_DEBUG_STRIPPED		0x0200
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP	0x0400
#define IMAGE_FILE_NET_RUN_FROM_SWAP		0x0800
#define IMAGE_FILE_SYSTEM			0x1000
#define IMAGE_FILE_DLL				0x2000
#define IMAGE_FILE_UP_SYSTEM_ONLY		0x4000
#define IMAGE_FILE_BYTES_REVERSED_HI		0x8000

These values of "characteristics" I found in the wild:

Windows: memtest.efi: Characteristics 0x22
Windows: bootmgfw.efi: Characteristics 0x2022
GRUB: bootx64.efi: Characteristics 0x20e
EDK2:
Characteristics 0x10e
Characteristics 0x2022
Characteristics 0x2102
Characteristics 0x2e

Best regards

Heinrich

> -	.short	0x206
> +	.short	0x20e
>  optional_header:
>  	.short	0x20b				/* PE32+ format */
>  	.byte	0x02				/* MajorLinkerVersion */
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images
  2018-09-26  6:03 ` [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images Bin Meng
@ 2018-09-26 17:51   ` Heinrich Schuchardt
  2018-10-02 14:16     ` Bin Meng
  0 siblings, 1 reply; 11+ messages in thread
From: Heinrich Schuchardt @ 2018-09-26 17:51 UTC (permalink / raw)
  To: u-boot

On 09/26/2018 08:03 AM, Bin Meng wrote:
> Per Microsoft PE Format documentation [1], PointerToSymbolTable and
> NumberOfSymbols should be zero for an image in the COFF file header.
> Currently the COFF file header is hardcoded on ARM and these two
> members are not zero.
> 
> This updates the hardcoded structure to clear these two members, as
> well as setting the flag IMAGE_FILE_LOCAL_SYMS_STRIPPED so that we
> can generate compliant *.efi images.
> 
> [1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format
> 
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
> 
>  arch/arm/lib/crt0_aarch64_efi.S | 7 ++++---
>  arch/arm/lib/crt0_arm_efi.S     | 6 +++---
>  2 files changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
> index 0db4360..a489d05 100644
> --- a/arch/arm/lib/crt0_aarch64_efi.S
> +++ b/arch/arm/lib/crt0_aarch64_efi.S
> @@ -28,13 +28,14 @@ coff_header:
>  	.short	2				/* nr_sections */
>  	.long	0				/* TimeDateStamp */
>  	.long	0				/* PointerToSymbolTable */
> -	.long	1				/* NumberOfSymbols */
> +	.long	0				/* NumberOfSymbols */
>  	.short	section_table - optional_header	/* SizeOfOptionalHeader */
>  	/*
>  	 * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
> -	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
> +	 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED |
> +	 * IMAGE_FILE_LOCAL_SYMS_STRIPPED
>  	 */
> -	.short	0x206
> +	.short	0x20e

I think your code misses to set IMAGE_FILE_32BIT_MACHINE in dependence
of the bitness of the system.

I would prefer if these constants were defined in asm-generic/pe.h:

#define IMAGE_FILE_RELOCS_STRIPPED		0x0001
#define IMAGE_FILE_EXECUTABLE_IMAGE		0x0002
#define IMAGE_FILE_LINE_NUMS_STRIPPED		0x0004
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED		0x0008
#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 		0x0010
#define IMAGE_FILE_LARGE_ADDRESS_AWARE		0x0020
/* Reserved					0x0040 */
#define IMAGE_FILE_BYTES_REVERSED_LO		0x0080
#define IMAGE_FILE_32BIT_MACHINE		0x0100
#define IMAGE_FILE_DEBUG_STRIPPED		0x0200
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP	0x0400
#define IMAGE_FILE_NET_RUN_FROM_SWAP		0x0800
#define IMAGE_FILE_SYSTEM			0x1000
#define IMAGE_FILE_DLL				0x2000
#define IMAGE_FILE_UP_SYSTEM_ONLY		0x4000
#define IMAGE_FILE_BYTES_REVERSED_HI		0x8000

Best regards

Heinrich

>  optional_header:
>  	.short	0x20b				/* PE32+ format */
>  	.byte	0x02				/* MajorLinkerVersion */
> diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
> index 23db49f..5330578 100644
> --- a/arch/arm/lib/crt0_arm_efi.S
> +++ b/arch/arm/lib/crt0_arm_efi.S
> @@ -27,14 +27,14 @@ coff_header:
>  	.short	2				/* nr_sections */
>  	.long	0				/* TimeDateStamp */
>  	.long	0				/* PointerToSymbolTable */
> -	.long	1				/* NumberOfSymbols */
> +	.long	0				/* NumberOfSymbols */
>  	.short	section_table - optional_header	/* SizeOfOptionalHeader */
>  	/*
>  	 * Characteristics: IMAGE_FILE_32BIT_MACHINE |
>  	 * IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
> -	 * IMAGE_FILE_LINE_NUMS_STRIPPED
> +	 * IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_LOCAL_SYMS_STRIPPED
>  	 */
> -	.short	0x306
> +	.short	0x30e
>  optional_header:
>  	.short	0x10b				/* PE32+ format */
>  	.byte	0x02				/* MajorLinkerVersion */
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images
  2018-09-26  6:03 [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images Bin Meng
                   ` (3 preceding siblings ...)
  2018-09-26  6:03 ` [U-Boot] [PATCH 5/5] riscv: " Bin Meng
@ 2018-09-26 18:40 ` Heinrich Schuchardt
  2018-10-02 14:31   ` Bin Meng
  4 siblings, 1 reply; 11+ messages in thread
From: Heinrich Schuchardt @ 2018-09-26 18:40 UTC (permalink / raw)
  To: u-boot

On 09/26/2018 08:03 AM, Bin Meng wrote:
> Per Microsoft PE Format documentation [1], PointerToSymbolTable and
> NumberOfSymbols should be zero for an image in the COFF file header.
> Currently U-Boot is generating *.efi images (eg: helloworld.efi) in
> which these two members are not zero.
> 
> This updates the build rules to tell linker to remove the symbol
> table completely so that we can generate compliant *.efi images.
> 
> [1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format
> 
> Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---


With the -s switch
- PointerToSymbolTable is 0,
- NumberOfSymbols is 0.

$ objdump -T  lib/efi_loader/helloworld.efi

lib/efi_loader/helloworld.efi:     file format pei-i386

objdump: lib/efi_loader/helloworld.efi: not a dynamic object
DYNAMIC SYMBOL TABLE:
no symbols

So the binaries are now conforming the PE standard.

qemu-x86_defconfig lib/efi_loader/helloworld.efi still contains these
sections:

Section[3] .dynamic
Section[5] .dynsym

Is this what you expect when you have 0 symbols? Should these sections
be removed with strip -R? But anyway these empty tables do no harm.

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

> 
>  scripts/Makefile.lib | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index f8c3fff..91f0b20 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -381,7 +381,7 @@ $(obj)/%.efi: $(obj)/%_efi.so
>  
>  quiet_cmd_efi_ld = LD      $@
>  cmd_efi_ld = $(LD) -nostdlib -znocombreloc -T $(EFI_LDS_PATH) -shared \
> -		-Bsymbolic $^ -o $@
> +		-Bsymbolic -s $^ -o $@
>  
>  EFI_LDS_PATH = $(srctree)/arch/$(ARCH)/lib/$(EFI_LDS)
>  
>               

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images
  2018-09-26 17:51   ` Heinrich Schuchardt
@ 2018-10-02 14:16     ` Bin Meng
  2018-10-02 18:13       ` Heinrich Schuchardt
  0 siblings, 1 reply; 11+ messages in thread
From: Bin Meng @ 2018-10-02 14:16 UTC (permalink / raw)
  To: u-boot

Hi Heinrich,

On Thu, Sep 27, 2018 at 1:51 AM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 09/26/2018 08:03 AM, Bin Meng wrote:
> > Per Microsoft PE Format documentation [1], PointerToSymbolTable and
> > NumberOfSymbols should be zero for an image in the COFF file header.
> > Currently the COFF file header is hardcoded on ARM and these two
> > members are not zero.
> >
> > This updates the hardcoded structure to clear these two members, as
> > well as setting the flag IMAGE_FILE_LOCAL_SYMS_STRIPPED so that we
> > can generate compliant *.efi images.
> >
> > [1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format
> >
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
> >
> >  arch/arm/lib/crt0_aarch64_efi.S | 7 ++++---
> >  arch/arm/lib/crt0_arm_efi.S     | 6 +++---
> >  2 files changed, 7 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
> > index 0db4360..a489d05 100644
> > --- a/arch/arm/lib/crt0_aarch64_efi.S
> > +++ b/arch/arm/lib/crt0_aarch64_efi.S
> > @@ -28,13 +28,14 @@ coff_header:
> >       .short  2                               /* nr_sections */
> >       .long   0                               /* TimeDateStamp */
> >       .long   0                               /* PointerToSymbolTable */
> > -     .long   1                               /* NumberOfSymbols */
> > +     .long   0                               /* NumberOfSymbols */
> >       .short  section_table - optional_header /* SizeOfOptionalHeader */
> >       /*
> >        * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
> > -      * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
> > +      * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED |
> > +      * IMAGE_FILE_LOCAL_SYMS_STRIPPED
> >        */
> > -     .short  0x206
> > +     .short  0x20e
>
> I think your code misses to set IMAGE_FILE_32BIT_MACHINE in dependence
> of the bitness of the system.
>

Do you mean currently for aarch64 targets, U-Boot only supports
loading 32-bit EFI images?

> I would prefer if these constants were defined in asm-generic/pe.h:
>
> #define IMAGE_FILE_RELOCS_STRIPPED              0x0001
> #define IMAGE_FILE_EXECUTABLE_IMAGE             0x0002
> #define IMAGE_FILE_LINE_NUMS_STRIPPED           0x0004
> #define IMAGE_FILE_LOCAL_SYMS_STRIPPED          0x0008
> #define IMAGE_FILE_AGGRESSIVE_WS_TRIM           0x0010
> #define IMAGE_FILE_LARGE_ADDRESS_AWARE          0x0020
> /* Reserved                                     0x0040 */
> #define IMAGE_FILE_BYTES_REVERSED_LO            0x0080
> #define IMAGE_FILE_32BIT_MACHINE                0x0100
> #define IMAGE_FILE_DEBUG_STRIPPED               0x0200
> #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP      0x0400
> #define IMAGE_FILE_NET_RUN_FROM_SWAP            0x0800
> #define IMAGE_FILE_SYSTEM                       0x1000
> #define IMAGE_FILE_DLL                          0x2000
> #define IMAGE_FILE_UP_SYSTEM_ONLY               0x4000
> #define IMAGE_FILE_BYTES_REVERSED_HI            0x8000
>

Will add these macros in v2.

Regards,
Bin

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images
  2018-09-26 18:40 ` [U-Boot] [PATCH 1/5] efi_loader: " Heinrich Schuchardt
@ 2018-10-02 14:31   ` Bin Meng
  0 siblings, 0 replies; 11+ messages in thread
From: Bin Meng @ 2018-10-02 14:31 UTC (permalink / raw)
  To: u-boot

Hi Heinrich,

On Thu, Sep 27, 2018 at 2:40 AM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 09/26/2018 08:03 AM, Bin Meng wrote:
> > Per Microsoft PE Format documentation [1], PointerToSymbolTable and
> > NumberOfSymbols should be zero for an image in the COFF file header.
> > Currently U-Boot is generating *.efi images (eg: helloworld.efi) in
> > which these two members are not zero.
> >
> > This updates the build rules to tell linker to remove the symbol
> > table completely so that we can generate compliant *.efi images.
> >
> > [1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format
> >
> > Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
>
>
> With the -s switch
> - PointerToSymbolTable is 0,
> - NumberOfSymbols is 0.
>
> $ objdump -T  lib/efi_loader/helloworld.efi
>
> lib/efi_loader/helloworld.efi:     file format pei-i386
>
> objdump: lib/efi_loader/helloworld.efi: not a dynamic object
> DYNAMIC SYMBOL TABLE:
> no symbols
>
> So the binaries are now conforming the PE standard.
>
> qemu-x86_defconfig lib/efi_loader/helloworld.efi still contains these
> sections:
>
> Section[3] .dynamic
> Section[5] .dynsym
>
> Is this what you expect when you have 0 symbols? Should these sections
> be removed with strip -R? But anyway these empty tables do no harm.
>

As you said, they do no harm so let's leave them there. I indeed
investigated 'strip' before but I used the '-s' switch of the linker
in the end.

> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>

Regards,
Bin

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images
  2018-10-02 14:16     ` Bin Meng
@ 2018-10-02 18:13       ` Heinrich Schuchardt
  0 siblings, 0 replies; 11+ messages in thread
From: Heinrich Schuchardt @ 2018-10-02 18:13 UTC (permalink / raw)
  To: u-boot

On 10/02/2018 04:16 PM, Bin Meng wrote:
> Hi Heinrich,
> 
> On Thu, Sep 27, 2018 at 1:51 AM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>> On 09/26/2018 08:03 AM, Bin Meng wrote:
>>> Per Microsoft PE Format documentation [1], PointerToSymbolTable and
>>> NumberOfSymbols should be zero for an image in the COFF file header.
>>> Currently the COFF file header is hardcoded on ARM and these two
>>> members are not zero.
>>>
>>> This updates the hardcoded structure to clear these two members, as
>>> well as setting the flag IMAGE_FILE_LOCAL_SYMS_STRIPPED so that we
>>> can generate compliant *.efi images.
>>>
>>> [1] https://docs.microsoft.com/zh-cn/windows/desktop/Debug/pe-format
>>>
>>> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>>> ---
>>>
>>>  arch/arm/lib/crt0_aarch64_efi.S | 7 ++++---
>>>  arch/arm/lib/crt0_arm_efi.S     | 6 +++---
>>>  2 files changed, 7 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
>>> index 0db4360..a489d05 100644
>>> --- a/arch/arm/lib/crt0_aarch64_efi.S
>>> +++ b/arch/arm/lib/crt0_aarch64_efi.S
>>> @@ -28,13 +28,14 @@ coff_header:
>>>       .short  2                               /* nr_sections */
>>>       .long   0                               /* TimeDateStamp */
>>>       .long   0                               /* PointerToSymbolTable */
>>> -     .long   1                               /* NumberOfSymbols */
>>> +     .long   0                               /* NumberOfSymbols */
>>>       .short  section_table - optional_header /* SizeOfOptionalHeader */
>>>       /*
>>>        * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
>>> -      * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
>>> +      * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED |
>>> +      * IMAGE_FILE_LOCAL_SYMS_STRIPPED
>>>        */
>>> -     .short  0x206
>>> +     .short  0x20e
>>
>> I think your code misses to set IMAGE_FILE_32BIT_MACHINE in dependence
>> of the bitness of the system.
>>
> 
> Do you mean currently for aarch64 targets, U-Boot only supports
> loading 32-bit EFI images?

I misread your patch. Sorry for the noise.

> 
>> I would prefer if these constants were defined in asm-generic/pe.h:
>>
>> #define IMAGE_FILE_RELOCS_STRIPPED              0x0001
>> #define IMAGE_FILE_EXECUTABLE_IMAGE             0x0002
>> #define IMAGE_FILE_LINE_NUMS_STRIPPED           0x0004
>> #define IMAGE_FILE_LOCAL_SYMS_STRIPPED          0x0008
>> #define IMAGE_FILE_AGGRESSIVE_WS_TRIM           0x0010
>> #define IMAGE_FILE_LARGE_ADDRESS_AWARE          0x0020
>> /* Reserved                                     0x0040 */
>> #define IMAGE_FILE_BYTES_REVERSED_LO            0x0080
>> #define IMAGE_FILE_32BIT_MACHINE                0x0100
>> #define IMAGE_FILE_DEBUG_STRIPPED               0x0200
>> #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP      0x0400
>> #define IMAGE_FILE_NET_RUN_FROM_SWAP            0x0800
>> #define IMAGE_FILE_SYSTEM                       0x1000
>> #define IMAGE_FILE_DLL                          0x2000
>> #define IMAGE_FILE_UP_SYSTEM_ONLY               0x4000
>> #define IMAGE_FILE_BYTES_REVERSED_HI            0x8000
>>
> 
> Will add these macros in v2.
> 
> Regards,
> Bin
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-10-02 18:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-26  6:03 [U-Boot] [PATCH 1/5] efi_loader: Generate Microsoft PE format complaint images Bin Meng
2018-09-26  6:03 ` [U-Boot] [PATCH 2/5] x86: efi: payload: Generate Microsoft PE format complaint image Bin Meng
2018-09-26  6:03 ` [U-Boot] [PATCH 3/5] x86: efi: app: " Bin Meng
2018-09-26  6:03 ` [U-Boot] [PATCH 4/5] arm: efi: Generate Microsoft PE format complaint images Bin Meng
2018-09-26 17:51   ` Heinrich Schuchardt
2018-10-02 14:16     ` Bin Meng
2018-10-02 18:13       ` Heinrich Schuchardt
2018-09-26  6:03 ` [U-Boot] [PATCH 5/5] riscv: " Bin Meng
2018-09-26 17:49   ` Heinrich Schuchardt
2018-09-26 18:40 ` [U-Boot] [PATCH 1/5] efi_loader: " Heinrich Schuchardt
2018-10-02 14:31   ` Bin Meng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.