misc: Misc EFI linker script improvements and drop .sbat
diff --git a/common/console.c b/common/console.c
index 958b07c7..ed74252e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -31,7 +31,7 @@ static void console_help(void) {
}
#if defined (UEFI)
-extern symbol __image_base;
+extern symbol __slide;
#endif
void console(void) {
@@ -67,7 +67,7 @@ void console(void) {
#endif
#if defined (UEFI)
} else if (strcmp(prompt, "slide") == 0) {
- print("%p\n", __image_base);
+ print("%p\n", __slide);
#endif
} else if (strcmp(prompt, "version") == 0) {
print(LIMINE_VERSION "\n");
diff --git a/common/entry.s3.c b/common/entry.s3.c
index a4a0bb27..da91b4cc 100644
--- a/common/entry.s3.c
+++ b/common/entry.s3.c
@@ -26,7 +26,7 @@
void stage3_common(void);
#if defined (UEFI)
-extern symbol __image_base;
+extern symbol __slide;
noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
gST = SystemTable;
@@ -52,7 +52,7 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
#endif
#if defined (__x86_64__)
- if ((uintptr_t)__image_base > 0x100000000) {
+ if ((uintptr_t)__slide >= 0x100000000) {
panic(false, "Limine does not support being loaded above 4GiB");
}
#endif
diff --git a/common/lib/trace.s2.c b/common/lib/trace.s2.c
index 6017d78b..5e6ebb30 100644
--- a/common/lib/trace.s2.c
+++ b/common/lib/trace.s2.c
@@ -11,7 +11,7 @@
#if defined (BIOS)
extern symbol stage2_map;
#elif defined (UEFI)
-extern symbol __image_base;
+extern symbol __slide;
#endif
extern symbol full_map;
@@ -27,7 +27,7 @@ static char *trace_address(size_t *off, size_t addr) {
#elif defined (UEFI)
limine_map = full_map;
- addr -= (size_t)__image_base;
+ addr -= (size_t)__slide;
#endif
uintptr_t prev_addr = 0;
diff --git a/common/linker_uefi_aarch64.ld.in b/common/linker_uefi_aarch64.ld.in
index 1deb388a..21b323fb 100644
--- a/common/linker_uefi_aarch64.ld.in
+++ b/common/linker_uefi_aarch64.ld.in
@@ -5,6 +5,7 @@ ENTRY(_start)
PHDRS
{
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
+ rodata PT_LOAD FLAGS((1 << 2)) ;
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ;
}
@@ -12,11 +13,13 @@ PHDRS
SECTIONS
{
. = 0;
- __image_base = .;
- __image_size = __image_end - __image_base;
+ __slide = .;
+ __image_base = ABSOLUTE(.);
+ __image_size = ABSOLUTE(__image_end - __image_base);
.text : {
*(.pe_header)
+
. = ALIGN(0x1000);
__text_start = ABSOLUTE(.);
@@ -24,19 +27,13 @@ SECTIONS
} :text
. = ALIGN(0x1000);
- __text_end = .;
- __text_size = __text_end - __text_start;
-
- .data : {
- __sbat_start = ABSOLUTE(.);
- *(.data.sbat)
- . = ALIGN(0x1000);
- __sbat_end = ABSOLUTE(.);
- __sbat_size = ABSOLUTE(__sbat_end - __sbat_start);
- PROVIDE(__sbat_sizev = ABSOLUTE(0));
+ __text_end = ABSOLUTE(.);
+ __text_size = ABSOLUTE(__text_end - __text_start);
+ .rodata : {
__reloc_start = ABSOLUTE(.);
- *(.data.reloc)
+ *(.reloc)
+
. = ALIGN(0x1000);
__reloc_end = ABSOLUTE(.);
__reloc_size = ABSOLUTE(__reloc_end - __reloc_start);
@@ -49,18 +46,16 @@ SECTIONS
#else
*(.full_map)
#endif
+ } :rodata
- *(.no_unwind)
-
+ .data : {
data_begin = .;
*(.data .data.*)
*(.bss .bss.*)
*(COMMON)
data_end = .;
- } :data
- .rela : {
- *(.rela .rela.*)
+ *(.no_unwind)
} :data
.got : {
@@ -72,10 +67,10 @@ SECTIONS
. = ALIGN(0x1000);
} :data :dynamic
- __data_end = .;
- __data_size = __data_end - __data_start;
+ __data_end = ABSOLUTE(.);
+ __data_size = ABSOLUTE(__data_end - __data_start);
- __image_end = .;
+ __image_end = ABSOLUTE(.);
/DISCARD/ : {
*(.eh_frame)
diff --git a/common/linker_uefi_ia32.ld.in b/common/linker_uefi_ia32.ld.in
index 823ce5f2..ccffe5ce 100644
--- a/common/linker_uefi_ia32.ld.in
+++ b/common/linker_uefi_ia32.ld.in
@@ -5,6 +5,7 @@ ENTRY(_start)
PHDRS
{
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
+ rodata PT_LOAD FLAGS((1 << 2)) ;
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ;
}
@@ -12,11 +13,13 @@ PHDRS
SECTIONS
{
. = 0;
- __image_base = .;
- __image_size = __image_end - __image_base;
+ __slide = .;
+ __image_base = ABSOLUTE(.);
+ __image_size = ABSOLUTE(__image_end - __image_base);
.text : {
*(.pe_header)
+
. = ALIGN(0x1000);
__text_start = ABSOLUTE(.);
@@ -24,19 +27,13 @@ SECTIONS
} :text
. = ALIGN(0x1000);
- __text_end = .;
- __text_size = __text_end - __text_start;
-
- .data : {
- __sbat_start = ABSOLUTE(.);
- *(.data.sbat)
- . = ALIGN(0x1000);
- __sbat_end = ABSOLUTE(.);
- __sbat_size = ABSOLUTE(__sbat_end - __sbat_start);
- PROVIDE(__sbat_sizev = ABSOLUTE(0));
+ __text_end = ABSOLUTE(.);
+ __text_size = ABSOLUTE(__text_end - __text_start);
+ .rodata : {
__reloc_start = ABSOLUTE(.);
- *(.data.reloc)
+ *(.reloc)
+
. = ALIGN(0x1000);
__reloc_end = ABSOLUTE(.);
__reloc_size = ABSOLUTE(__reloc_end - __reloc_start);
@@ -49,18 +46,16 @@ SECTIONS
#else
*(.full_map)
#endif
+ } :rodata
- *(.no_unwind)
-
+ .data : {
data_begin = .;
*(.data .data.*)
*(.bss .bss.*)
*(COMMON)
data_end = .;
- } :data
- .rel : {
- *(.rel .rel.*)
+ *(.no_unwind)
} :data
.got : {
@@ -72,10 +67,10 @@ SECTIONS
. = ALIGN(0x1000);
} :data :dynamic
- __data_end = .;
- __data_size = __data_end - __data_start;
+ __data_end = ABSOLUTE(.);
+ __data_size = ABSOLUTE(__data_end - __data_start);
- __image_end = .;
+ __image_end = ABSOLUTE(.);
/DISCARD/ : {
*(.eh_frame)
diff --git a/common/linker_uefi_x86_64.ld.in b/common/linker_uefi_x86_64.ld.in
index 2f59acb6..7bb8f89f 100644
--- a/common/linker_uefi_x86_64.ld.in
+++ b/common/linker_uefi_x86_64.ld.in
@@ -5,6 +5,7 @@ ENTRY(_start)
PHDRS
{
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
+ rodata PT_LOAD FLAGS((1 << 2)) ;
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ;
}
@@ -12,11 +13,13 @@ PHDRS
SECTIONS
{
. = 0;
- __image_base = .;
- __image_size = __image_end - __image_base;
+ __slide = .;
+ __image_base = ABSOLUTE(.);
+ __image_size = ABSOLUTE(__image_end - __image_base);
.text : {
*(.pe_header)
+
. = ALIGN(0x1000);
__text_start = ABSOLUTE(.);
@@ -24,19 +27,13 @@ SECTIONS
} :text
. = ALIGN(0x1000);
- __text_end = .;
- __text_size = __text_end - __text_start;
-
- .data : {
- __sbat_start = ABSOLUTE(.);
- *(.data.sbat)
- . = ALIGN(0x1000);
- __sbat_end = ABSOLUTE(.);
- __sbat_size = ABSOLUTE(__sbat_end - __sbat_start);
- PROVIDE(__sbat_sizev = ABSOLUTE(0));
+ __text_end = ABSOLUTE(.);
+ __text_size = ABSOLUTE(__text_end - __text_start);
+ .rodata : {
__reloc_start = ABSOLUTE(.);
- *(.data.reloc)
+ *(.reloc)
+
. = ALIGN(0x1000);
__reloc_end = ABSOLUTE(.);
__reloc_size = ABSOLUTE(__reloc_end - __reloc_start);
@@ -49,18 +46,16 @@ SECTIONS
#else
*(.full_map)
#endif
+ } :rodata
- *(.no_unwind)
-
+ .data : {
data_begin = .;
*(.data .data.*)
*(.bss .bss.*)
*(COMMON)
data_end = .;
- } :data
- .rela : {
- *(.rela .rela.*)
+ *(.no_unwind)
} :data
.got : {
@@ -72,10 +67,10 @@ SECTIONS
. = ALIGN(0x1000);
} :data :dynamic
- __data_end = .;
- __data_size = __data_end - __data_start;
+ __data_end = ABSOLUTE(.);
+ __data_size = ABSOLUTE(__data_end - __data_start);
- __image_end = .;
+ __image_end = ABSOLUTE(.);
/DISCARD/ : {
*(.eh_frame)
diff --git a/common/mm/pmm.s2.c b/common/mm/pmm.s2.c
index ce21a55a..86841748 100644
--- a/common/mm/pmm.s2.c
+++ b/common/mm/pmm.s2.c
@@ -288,8 +288,8 @@ void init_memmap(void) {
#if defined (UEFI)
static struct memmap_entry *recl;
-extern symbol __image_base;
-extern symbol __image_end;
+extern symbol __slide;
+extern symbol __image_size;
void init_memmap(void) {
EFI_STATUS status;
@@ -422,10 +422,8 @@ void init_memmap(void) {
sanitiser_keep_first_page = old_skfp;
- size_t bootloader_size = ALIGN_UP((uintptr_t)__image_end - (uintptr_t)__image_base, 4096);
-
// Allocate bootloader itself
- memmap_alloc_range((uintptr_t)__image_base, bootloader_size,
+ memmap_alloc_range((uintptr_t)__slide, (uintptr_t)__image_size,
MEMMAP_BOOTLOADER_RECLAIMABLE, 0, true, false, true);
sanitise_entries(memmap, &memmap_entries, false);
diff --git a/common/sbat.c b/common/sbat.c
deleted file mode 100644
index e0e10c08..00000000
--- a/common/sbat.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#if defined (UEFI)
-
-#include <config.h>
-
-asm (
- ".section .data.sbat\n\t"
- "sbat:\n\t"
- ".ascii \"sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md\\n\"\n\t"
- ".ascii \"limine,1,Limine,limine," LIMINE_VERSION ",https://limine-bootloader.org\\n\"\n\t"
- "__sbat_endv:\n\t"
- ".global __sbat_sizev\n\t"
- ".set __sbat_sizev, __sbat_endv - sbat\n\t"
-);
-
-#endif
