From ae94e383a3a26d466339e817644a79605a936000 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Thu, 24 Oct 2024 11:15:19 +0100 Subject: [PATCH 1/5] Make our dummy .reloc sections not depend on section order. Currently on x64 we manually build a dummy .reloc table entry by using a symbol in .text and subtracting its address from another symbol that's inside the .reloc section. On ia32 we just use its location. In either case, if the linker puts either section in a location we're not expecting, the .reloc table winds up having invalid values, and the PE loader will fail to load the binary. This changes it to be two symbols that are both in .text, making the result unrelated to the section order or location. It's not clear to me that these .reloc entries are actually necessary at all, but I'm going to leave them in place for now, in case they are. Ref: rhboot/gnu-efi@9fb55dee2bc6bcbafc3223b61c82ea53f361eabe Co-authored-by: Peter Jones Signed-off-by: Callum Farmer --- gnuefi/crt0-efi-aarch64-local.S | 8 ++++---- gnuefi/crt0-efi-aarch64.S | 8 ++++---- gnuefi/crt0-efi-arm.S | 7 ++++--- gnuefi/crt0-efi-ia32-local.S | 7 ++++--- gnuefi/crt0-efi-ia32.S | 5 +++-- gnuefi/crt0-efi-ia64.S | 2 +- gnuefi/crt0-efi-loongarch64.S | 7 ++++--- gnuefi/crt0-efi-riscv64-local.S | 7 ++++--- gnuefi/crt0-efi-riscv64.S | 7 ++++--- gnuefi/crt0-efi-x86_64.S | 7 ++++--- 10 files changed, 36 insertions(+), 29 deletions(-) diff --git a/gnuefi/crt0-efi-aarch64-local.S b/gnuefi/crt0-efi-aarch64-local.S index 8ce3d28..b157ea7 100644 --- a/gnuefi/crt0-efi-aarch64-local.S +++ b/gnuefi/crt0-efi-aarch64-local.S @@ -172,12 +172,12 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc, "a" -label1: - .4byte dummy-label1 // Page RVA + .section .reloc, "a", %progbits + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-aarch64.S b/gnuefi/crt0-efi-aarch64.S index 6decdbc..df2584f 100644 --- a/gnuefi/crt0-efi-aarch64.S +++ b/gnuefi/crt0-efi-aarch64.S @@ -43,12 +43,12 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc, "a" -label1: - .4byte dummy-label1 // Page RVA + .section .reloc, "a", %progbits + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-arm.S b/gnuefi/crt0-efi-arm.S index ad02ca1..495beed 100644 --- a/gnuefi/crt0-efi-arm.S +++ b/gnuefi/crt0-efi-arm.S @@ -177,11 +177,12 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .areloc - .4byte dummy // Page RVA + .section .areloc, "a", %progbits + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-ia32-local.S b/gnuefi/crt0-efi-ia32-local.S index a13be2d..f07cb71 100644 --- a/gnuefi/crt0-efi-ia32-local.S +++ b/gnuefi/crt0-efi-ia32-local.S @@ -163,11 +163,12 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc - .4byte dummy // Page RVA + .section .reloc, "a", %progbits + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-ia32.S b/gnuefi/crt0-efi-ia32.S index e7023ab..35b0385 100644 --- a/gnuefi/crt0-efi-ia32.S +++ b/gnuefi/crt0-efi-ia32.S @@ -68,11 +68,12 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc - .4byte dummy // Page RVA + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-ia64.S b/gnuefi/crt0-efi-ia64.S index 30714d3..fc8a467 100644 --- a/gnuefi/crt0-efi-ia64.S +++ b/gnuefi/crt0-efi-ia64.S @@ -80,7 +80,7 @@ _start_plabel: #define IMAGE_REL_BASED_DIR64 10 - .section .reloc, "a" + .section .reloc, "a", %progbits data4 _start_plabel // Page RVA data4 12 // Block Size (2*4+2*2), must be aligned by 32 Bits data2 (IMAGE_REL_BASED_DIR64<<12) + 0 // reloc for plabel's entry point diff --git a/gnuefi/crt0-efi-loongarch64.S b/gnuefi/crt0-efi-loongarch64.S index af939ff..f094bf9 100644 --- a/gnuefi/crt0-efi-loongarch64.S +++ b/gnuefi/crt0-efi-loongarch64.S @@ -45,12 +45,13 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc, "a" + .section .reloc, "a", %progbits label1: - .4byte dummy-label1 // Page RVA + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-riscv64-local.S b/gnuefi/crt0-efi-riscv64-local.S index 4b34101..b96df9e 100644 --- a/gnuefi/crt0-efi-riscv64-local.S +++ b/gnuefi/crt0-efi-riscv64-local.S @@ -170,12 +170,13 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc, "a" + .section .reloc, "a", %progbits label1: - .4byte dummy-label1 // Page RVA + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-riscv64.S b/gnuefi/crt0-efi-riscv64.S index bc86a62..648ea40 100644 --- a/gnuefi/crt0-efi-riscv64.S +++ b/gnuefi/crt0-efi-riscv64.S @@ -38,12 +38,13 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc, "a" + .section .reloc, "a", %progbits label1: - .4byte dummy-label1 // Page RVA + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-x86_64.S b/gnuefi/crt0-efi-x86_64.S index b1f599f..f3d0712 100644 --- a/gnuefi/crt0-efi-x86_64.S +++ b/gnuefi/crt0-efi-x86_64.S @@ -66,12 +66,13 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .4byte 0 +dummy0: .4byte 0 +dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc, "a" + .section .reloc, "a", %progbits label1: - .4byte dummy-label1 // Page RVA + .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy From 40b020311670cfcf8f661d0af10ecc4d51aa03c2 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Thu, 24 Oct 2024 11:39:28 +0100 Subject: [PATCH 2/5] ia32 local: Rename reloc to areloc * Similar to ARM32, this triggers a GNU AS section parameters warning if called reloc * This breaks IA32 objcopy due to .reloc lookup Signed-off-by: Callum Farmer --- gnuefi/crt0-efi-ia32-local.S | 2 +- gnuefi/elf_ia32_efi_local.lds | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gnuefi/crt0-efi-ia32-local.S b/gnuefi/crt0-efi-ia32-local.S index f07cb71..0df7854 100644 --- a/gnuefi/crt0-efi-ia32-local.S +++ b/gnuefi/crt0-efi-ia32-local.S @@ -167,7 +167,7 @@ dummy0: .4byte 0 dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 - .section .reloc, "a", %progbits + .section .areloc, "a", %progbits .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/elf_ia32_efi_local.lds b/gnuefi/elf_ia32_efi_local.lds index 4e0b5f1..fec3895 100644 --- a/gnuefi/elf_ia32_efi_local.lds +++ b/gnuefi/elf_ia32_efi_local.lds @@ -20,8 +20,8 @@ SECTIONS _text_size = _etext - _text; . = ALIGN(4096); _reloc = .; - .reloc : { - *(.reloc) + .areloc : { + *(.areloc) _evreloc = .; . = ALIGN(4096); _ereloc = .; From 882df4e7327871aac39acdf2d0a0f65ca35a53e6 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Thu, 24 Oct 2024 12:13:57 +0100 Subject: [PATCH 3/5] ia32 local: Remove accidental rela REL not RELA Signed-off-by: Callum Farmer --- gnuefi/elf_ia32_efi_local.lds | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gnuefi/elf_ia32_efi_local.lds b/gnuefi/elf_ia32_efi_local.lds index fec3895..f59135f 100644 --- a/gnuefi/elf_ia32_efi_local.lds +++ b/gnuefi/elf_ia32_efi_local.lds @@ -90,21 +90,21 @@ SECTIONS . = ALIGN(4096); _rodata = .; - .rela : + .rel : { - *(.rela.text*) - *(.rela.data*) - *(.rela.got) - *(.rela.dyn) - *(.rela.stab) - *(.rela.init_array*) - *(.rela.fini_array*) - *(.rela.ctors*) - *(.rela.dtors*) + *(.rel.text*) + *(.rel.data*) + *(.rel.got) + *(.rel.dyn) + *(.rel.stab) + *(.rel.init_array*) + *(.rel.fini_array*) + *(.rel.ctors*) + *(.rel.dtors*) } . = ALIGN(4096); - .rela.plt : { *(.rela.plt) } + .rel.plt : { *(.rel.plt) } . = ALIGN(4096); .rodata : { *(.rodata*) From 03bfe2f5ced3cfda8cc693bbb2ff647b8087d5a8 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Thu, 24 Oct 2024 12:43:10 +0100 Subject: [PATCH 4/5] Push .reloc after .data Seems GNU ld is a bit stupid in this regard Apply to all archs incase this is repeated so far only seen on ARM64 Fixes ncroxon/gnu-efi#47 Signed-off-by: Callum Farmer --- gnuefi/crt0-efi-aarch64-local.S | 22 +++++++++++----------- gnuefi/crt0-efi-arm.S | 24 ++++++++++++------------ gnuefi/crt0-efi-ia32-local.S | 24 ++++++++++++------------ gnuefi/crt0-efi-riscv64-local.S | 22 +++++++++++----------- gnuefi/elf_aarch64_efi.lds | 17 ++++++++--------- gnuefi/elf_aarch64_efi_local.lds | 23 +++++++++++------------ gnuefi/elf_arm_efi.lds | 22 +++++++++++----------- gnuefi/elf_ia32_efi_local.lds | 22 +++++++++++----------- gnuefi/elf_loongarch64_efi.lds | 10 +++++----- gnuefi/elf_riscv64_efi.lds | 10 +++++----- gnuefi/elf_riscv64_efi_local.lds | 22 +++++++++++----------- gnuefi/elf_x86_64_efi.lds | 10 +++++----- gnuefi/elf_x86_64_fbsd_efi.lds | 10 +++++----- 13 files changed, 118 insertions(+), 120 deletions(-) diff --git a/gnuefi/crt0-efi-aarch64-local.S b/gnuefi/crt0-efi-aarch64-local.S index b157ea7..b33ef5e 100644 --- a/gnuefi/crt0-efi-aarch64-local.S +++ b/gnuefi/crt0-efi-aarch64-local.S @@ -108,6 +108,17 @@ section_table: .2byte 0 // NumberOfLineNumbers (0 for executables) .4byte 0x60000020 // Characteristics (section flags) + .ascii ".data\0\0\0" + .4byte _data_vsize - ImageBase // VirtualSize + .4byte _data - ImageBase // VirtualAddress + .4byte _data_size - ImageBase // SizeOfRawData + .4byte _data - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0xC0000040 // Characteristics (section flags) + /* * The EFI application loader requires a relocation section * because EFI applications must be relocatable. This is a @@ -124,17 +135,6 @@ section_table: .2byte 0 // NumberOfLineNumbers .4byte 0x42000040 // Characteristics (section flags) - .ascii ".data\0\0\0" - .4byte _data_vsize - ImageBase // VirtualSize - .4byte _data - ImageBase // VirtualAddress - .4byte _data_size - ImageBase // SizeOfRawData - .4byte _data - ImageBase // PointerToRawData - .4byte 0 // PointerToRelocations - .4byte 0 // PointerToLineNumbers - .2byte 0 // NumberOfRelocations - .2byte 0 // NumberOfLineNumbers - .4byte 0xC0000040 // Characteristics (section flags) - .ascii ".rodata\0" .4byte _rodata_vsize - ImageBase // VirtualSize .4byte _rodata - ImageBase // VirtualAddress diff --git a/gnuefi/crt0-efi-arm.S b/gnuefi/crt0-efi-arm.S index 495beed..c3836cd 100644 --- a/gnuefi/crt0-efi-arm.S +++ b/gnuefi/crt0-efi-arm.S @@ -50,7 +50,7 @@ optional_header: .4byte 0 // SizeOfUninitializedData .4byte _text - ImageBase // AddressOfEntryPoint .4byte _text - ImageBase // BaseOfCode - .4byte _reloc - ImageBase // BaseOfData + .4byte _data - ImageBase // BaseOfData extra_header_fields: .4byte 0 // ImageBase @@ -110,6 +110,17 @@ section_table: .2byte 0 // NumberOfLineNumbers (0 for executables) .4byte 0x60000020 // Characteristics (section flags) + .ascii ".data\0\0\0" + .4byte _data_vsize - ImageBase // VirtualSize + .4byte _data - ImageBase // VirtualAddress + .4byte _data_size - ImageBase // SizeOfRawData + .4byte _data - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0xC0000040 // Characteristics (section flags) + /* * The EFI application loader requires a relocation section * because EFI applications must be relocatable. This is a @@ -126,17 +137,6 @@ section_table: .2byte 0 // NumberOfLineNumbers .4byte 0x42000040 // Characteristics (section flags) - .ascii ".data\0\0\0" - .4byte _data_vsize - ImageBase // VirtualSize - .4byte _data - ImageBase // VirtualAddress - .4byte _data_size - ImageBase // SizeOfRawData - .4byte _data - ImageBase // PointerToRawData - .4byte 0 // PointerToRelocations - .4byte 0 // PointerToLineNumbers - .2byte 0 // NumberOfRelocations - .2byte 0 // NumberOfLineNumbers - .4byte 0xC0000040 // Characteristics (section flags) - .ascii ".rodata\0" .4byte _rodata_vsize - ImageBase // VirtualSize .4byte _rodata - ImageBase // VirtualAddress diff --git a/gnuefi/crt0-efi-ia32-local.S b/gnuefi/crt0-efi-ia32-local.S index 0df7854..5a2aeac 100644 --- a/gnuefi/crt0-efi-ia32-local.S +++ b/gnuefi/crt0-efi-ia32-local.S @@ -32,7 +32,7 @@ optional_header: .4byte 0 // SizeOfUninitializedData .4byte _start - ImageBase // AddressOfEntryPoint .4byte _start - ImageBase // BaseOfCode - .4byte _reloc - ImageBase // BaseOfData + .4byte _data - ImageBase // BaseOfData extra_header_fields: .4byte 0 // ImageBase @@ -92,6 +92,17 @@ section_table: .2byte 0 // NumberOfLineNumbers (0 for executables) .4byte 0x60000020 // Characteristics (section flags) + .ascii ".data\0\0\0" + .4byte _data_vsize - ImageBase // VirtualSize + .4byte _data - ImageBase // VirtualAddress + .4byte _data_size - ImageBase // SizeOfRawData + .4byte _data - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0xC0000040 // Characteristics (section flags) + /* * The EFI application loader requires a relocation section * because EFI applications must be relocatable. This is a @@ -108,17 +119,6 @@ section_table: .2byte 0 // NumberOfLineNumbers .4byte 0x42000040 // Characteristics (section flags) - .ascii ".data\0\0\0" - .4byte _data_vsize - ImageBase // VirtualSize - .4byte _data - ImageBase // VirtualAddress - .4byte _data_size - ImageBase // SizeOfRawData - .4byte _data - ImageBase // PointerToRawData - .4byte 0 // PointerToRelocations - .4byte 0 // PointerToLineNumbers - .2byte 0 // NumberOfRelocations - .2byte 0 // NumberOfLineNumbers - .4byte 0xC0000040 // Characteristics (section flags) - .ascii ".rodata\0" .4byte _rodata_vsize - ImageBase // VirtualSize .4byte _rodata - ImageBase // VirtualAddress diff --git a/gnuefi/crt0-efi-riscv64-local.S b/gnuefi/crt0-efi-riscv64-local.S index b96df9e..59b2388 100644 --- a/gnuefi/crt0-efi-riscv64-local.S +++ b/gnuefi/crt0-efi-riscv64-local.S @@ -110,6 +110,17 @@ section_table: .2byte 0 // NumberOfLineNumbers (0 for executables) .4byte 0x60000020 // Characteristics (section flags) + .ascii ".data\0\0\0" + .4byte _data_vsize - ImageBase // VirtualSize + .4byte _data - ImageBase // VirtualAddress + .4byte _data_size - ImageBase // SizeOfRawData + .4byte _data - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0xC0000040 // Characteristics (section flags) + /* * The EFI application loader requires a relocation section * because EFI applications must be relocatable. This is a @@ -126,17 +137,6 @@ section_table: .2byte 0 // NumberOfLineNumbers .4byte 0x42000040 // Characteristics (section flags) - .ascii ".data\0\0\0" - .4byte _data_vsize - ImageBase // VirtualSize - .4byte _data - ImageBase // VirtualAddress - .4byte _data_size - ImageBase // SizeOfRawData - .4byte _data - ImageBase // PointerToRawData - .4byte 0 // PointerToRelocations - .4byte 0 // PointerToLineNumbers - .2byte 0 // NumberOfRelocations - .2byte 0 // NumberOfLineNumbers - .4byte 0xC0000040 // Characteristics (section flags) - .ascii ".rodata\0" .4byte _rodata_vsize - ImageBase // VirtualSize .4byte _rodata - ImageBase // VirtualAddress diff --git a/gnuefi/elf_aarch64_efi.lds b/gnuefi/elf_aarch64_efi.lds index 3834b00..85f315f 100644 --- a/gnuefi/elf_aarch64_efi.lds +++ b/gnuefi/elf_aarch64_efi.lds @@ -24,14 +24,6 @@ SECTIONS _etext = .; _text_size = _etext - _text; . = ALIGN(65536); - .reloc : - { - KEEP (*(.reloc)) - } - . = ALIGN(4096); - _DYNAMIC = .; - .dynamic : { *(.dynamic) } - . = ALIGN(4096); .data : { _data = .; @@ -83,7 +75,14 @@ SECTIONS _bss_end = .; } - + . = ALIGN(4096); + .reloc : + { + KEEP (*(.reloc)) + } + . = ALIGN(4096); + _DYNAMIC = .; + .dynamic : { *(.dynamic) } . = ALIGN(4096); .rela : { diff --git a/gnuefi/elf_aarch64_efi_local.lds b/gnuefi/elf_aarch64_efi_local.lds index 1609544..16dbb30 100644 --- a/gnuefi/elf_aarch64_efi_local.lds +++ b/gnuefi/elf_aarch64_efi_local.lds @@ -19,16 +19,6 @@ SECTIONS _text_vsize = _evtext - _text; _text_size = _etext - _text; . = ALIGN(65536); - _reloc = .; - .reloc : { - *(.reloc) - _evreloc = .; - . = ALIGN(4096); - _ereloc = .; - } =0 - _reloc_vsize = _evreloc - _reloc; - _reloc_size = _ereloc - _reloc; - . = ALIGN(4096); _data = .; _DYNAMIC = .; .dynamic : { *(.dynamic) } @@ -87,7 +77,16 @@ SECTIONS } =0 _data_vsize = _evdata - _data; _data_size = _edata - _data; - + . = ALIGN(4096); + _reloc = .; + .reloc : { + *(.reloc) + _evreloc = .; + . = ALIGN(4096); + _ereloc = .; + } =0 + _reloc_vsize = _evreloc - _reloc; + _reloc_size = _ereloc - _reloc; . = ALIGN(4096); _rodata = .; .rela : @@ -115,7 +114,7 @@ SECTIONS _rodata_vsize = _evrodata - _rodata; _rodata_size = _erodata - _rodata; _image_end = .; - _alldata_size = _image_end - _reloc; + _alldata_size = _image_end - _data; . = ALIGN(4096); .dynsym : { *(.dynsym) } diff --git a/gnuefi/elf_arm_efi.lds b/gnuefi/elf_arm_efi.lds index b7e3fb1..7a8f361 100644 --- a/gnuefi/elf_arm_efi.lds +++ b/gnuefi/elf_arm_efi.lds @@ -19,16 +19,6 @@ SECTIONS _text_vsize = _evtext - _text; _text_size = _etext - _text; . = ALIGN(4096); - _reloc = .; - .areloc : { - *(.areloc) - _evreloc = .; - . = ALIGN(4096); - _ereloc = .; - } =0 - _reloc_vsize = _evreloc - _reloc; - _reloc_size = _ereloc - _reloc; - . = ALIGN(4096); _data = .; _DYNAMIC = .; .dynamic : { *(.dynamic) } @@ -87,6 +77,16 @@ SECTIONS } =0 _data_vsize = _evdata - _data; _data_size = _edata - _data; + . = ALIGN(4096); + _reloc = .; + .areloc : { + *(.areloc) + _evreloc = .; + . = ALIGN(4096); + _ereloc = .; + } =0 + _reloc_vsize = _evreloc - _reloc; + _reloc_size = _ereloc - _reloc; . = ALIGN(4096); _rodata = .; @@ -115,7 +115,7 @@ SECTIONS _rodata_vsize = _evrodata - _rodata; _rodata_size = _erodata - _rodata; _image_end = .; - _alldata_size = _image_end - _reloc; + _alldata_size = _image_end - _data; . = ALIGN(4096); .dynsym : { *(.dynsym) } diff --git a/gnuefi/elf_ia32_efi_local.lds b/gnuefi/elf_ia32_efi_local.lds index f59135f..2409cf3 100644 --- a/gnuefi/elf_ia32_efi_local.lds +++ b/gnuefi/elf_ia32_efi_local.lds @@ -19,16 +19,6 @@ SECTIONS _text_vsize = _evtext - _text; _text_size = _etext - _text; . = ALIGN(4096); - _reloc = .; - .areloc : { - *(.areloc) - _evreloc = .; - . = ALIGN(4096); - _ereloc = .; - } =0 - _reloc_vsize = _evreloc - _reloc; - _reloc_size = _ereloc - _reloc; - . = ALIGN(4096); _data = .; _DYNAMIC = .; .dynamic : { *(.dynamic) } @@ -87,6 +77,16 @@ SECTIONS } =0 _data_vsize = _evdata - _data; _data_size = _edata - _data; + . = ALIGN(4096); + _reloc = .; + .areloc : { + *(.areloc) + _evreloc = .; + . = ALIGN(4096); + _ereloc = .; + } =0 + _reloc_vsize = _evreloc - _reloc; + _reloc_size = _ereloc - _reloc; . = ALIGN(4096); _rodata = .; @@ -115,7 +115,7 @@ SECTIONS _rodata_vsize = _evrodata - _rodata; _rodata_size = _erodata - _rodata; _image_end = .; - _alldata_size = _image_end - _reloc; + _alldata_size = _image_end - _data; . = ALIGN(4096); .dynsym : { *(.dynsym) } diff --git a/gnuefi/elf_loongarch64_efi.lds b/gnuefi/elf_loongarch64_efi.lds index 998f680..b54612f 100644 --- a/gnuefi/elf_loongarch64_efi.lds +++ b/gnuefi/elf_loongarch64_efi.lds @@ -23,11 +23,6 @@ SECTIONS } _etext = .; _text_size = _etext - _text; - . = ALIGN(4096); - .reloc : - { - KEEP (*(.reloc)) - } . = ALIGN(65536); _DYNAMIC = .; .dynamic : { *(.dynamic) } @@ -83,6 +78,11 @@ SECTIONS _bss_end = .; } + . = ALIGN(4096); + .reloc : + { + KEEP (*(.reloc)) + } . = ALIGN(4096); .rela : diff --git a/gnuefi/elf_riscv64_efi.lds b/gnuefi/elf_riscv64_efi.lds index f61d3f6..d6663ee 100644 --- a/gnuefi/elf_riscv64_efi.lds +++ b/gnuefi/elf_riscv64_efi.lds @@ -26,11 +26,6 @@ SECTIONS _etext = .; _text_size = _etext - _text; . = ALIGN(65536); - .reloc : - { - KEEP (*(.reloc)) - } - . = ALIGN(4096); _DYNAMIC = .; .dynamic : { *(.dynamic) } . = ALIGN(4096); @@ -85,6 +80,11 @@ SECTIONS _bss_end = .; } + . = ALIGN(4096); + .reloc : + { + KEEP (*(.reloc)) + } . = ALIGN(4096); .rela : diff --git a/gnuefi/elf_riscv64_efi_local.lds b/gnuefi/elf_riscv64_efi_local.lds index 40465ee..6baaff3 100644 --- a/gnuefi/elf_riscv64_efi_local.lds +++ b/gnuefi/elf_riscv64_efi_local.lds @@ -21,16 +21,6 @@ SECTIONS _text_vsize = _evtext - _text; _text_size = _etext - _text; . = ALIGN(4096); - _reloc = .; - .reloc : { - *(.reloc) - _evreloc = .; - . = ALIGN(4096); - _ereloc = .; - } =0 - _reloc_vsize = _evreloc - _reloc; - _reloc_size = _ereloc - _reloc; - . = ALIGN(4096); _data = .; _DYNAMIC = .; .dynamic : { *(.dynamic) } @@ -89,6 +79,16 @@ SECTIONS } =0 _data_vsize = _evdata - _data; _data_size = _edata - _data; + . = ALIGN(4096); + _reloc = .; + .reloc : { + *(.reloc) + _evreloc = .; + . = ALIGN(4096); + _ereloc = .; + } =0 + _reloc_vsize = _evreloc - _reloc; + _reloc_size = _ereloc - _reloc; . = ALIGN(4096); _rodata = .; @@ -117,7 +117,7 @@ SECTIONS _rodata_vsize = _evrodata - _rodata; _rodata_size = _erodata - _rodata; _image_end = .; - _alldata_size = _image_end - _reloc; + _alldata_size = _image_end - _data; . = ALIGN(4096); .dynsym : { *(.dynsym) } diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds index d1e62ab..61966b2 100644 --- a/gnuefi/elf_x86_64_efi.lds +++ b/gnuefi/elf_x86_64_efi.lds @@ -25,11 +25,6 @@ SECTIONS } _etext = .; _text_size = _etext - _text; - . = ALIGN(4096); - .reloc : - { - KEEP (*(.reloc)) - } . = ALIGN(4096); .data : @@ -81,6 +76,11 @@ SECTIONS _edata = .; _data_size = _edata - _etext; . = ALIGN(4096); + .reloc : + { + KEEP (*(.reloc)) + } + . = ALIGN(4096); _DYNAMIC = .; .dynamic : { *(.dynamic) } . = ALIGN(4096); diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds index 81e09f5..b8af109 100644 --- a/gnuefi/elf_x86_64_fbsd_efi.lds +++ b/gnuefi/elf_x86_64_fbsd_efi.lds @@ -24,11 +24,6 @@ SECTIONS } _etext = .; _text_size = _etext - _text; - . = ALIGN(4096); - .reloc : - { - KEEP (*(.reloc)) - } . = ALIGN(4096); .data : @@ -80,6 +75,11 @@ SECTIONS _edata = .; _data_size = _edata - _etext; . = ALIGN(4096); + .reloc : + { + KEEP (*(.reloc)) + } + . = ALIGN(4096); _DYNAMIC = .; .dynamic : { *(.dynamic) } . = ALIGN(4096); From aa58dc8ff1c21e793b175d520728e0f86833239d Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Tue, 29 Oct 2024 14:04:13 +0000 Subject: [PATCH 5/5] Remove label1 No longer needed Signed-off-by: Callum Farmer --- gnuefi/crt0-efi-loongarch64.S | 1 - gnuefi/crt0-efi-riscv64-local.S | 1 - gnuefi/crt0-efi-riscv64.S | 1 - gnuefi/crt0-efi-x86_64.S | 1 - 4 files changed, 4 deletions(-) diff --git a/gnuefi/crt0-efi-loongarch64.S b/gnuefi/crt0-efi-loongarch64.S index f094bf9..182aa59 100644 --- a/gnuefi/crt0-efi-loongarch64.S +++ b/gnuefi/crt0-efi-loongarch64.S @@ -50,7 +50,6 @@ dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc, "a", %progbits -label1: .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-riscv64-local.S b/gnuefi/crt0-efi-riscv64-local.S index 59b2388..e835b8c 100644 --- a/gnuefi/crt0-efi-riscv64-local.S +++ b/gnuefi/crt0-efi-riscv64-local.S @@ -175,7 +175,6 @@ dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc, "a", %progbits -label1: .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-riscv64.S b/gnuefi/crt0-efi-riscv64.S index 648ea40..782e61f 100644 --- a/gnuefi/crt0-efi-riscv64.S +++ b/gnuefi/crt0-efi-riscv64.S @@ -43,7 +43,6 @@ dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc, "a", %progbits -label1: .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnuefi/crt0-efi-x86_64.S b/gnuefi/crt0-efi-x86_64.S index f3d0712..23f64fc 100644 --- a/gnuefi/crt0-efi-x86_64.S +++ b/gnuefi/crt0-efi-x86_64.S @@ -71,7 +71,6 @@ dummy1: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc, "a", %progbits -label1: .4byte dummy1 - dummy0 // Page RVA .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy