misc: Misc EFI linker script improvements and drop .sbat

This commit is contained in:
mintsuki 2023-09-11 04:27:02 -05:00
parent 8f789fc0ae
commit 0ebf0245df
9 changed files with 73 additions and 110 deletions

View File

@ -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");

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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,9 +46,9 @@ SECTIONS
#else
*(.full_map)
#endif
} :rodata
*(.no_unwind)
.data : {
data_begin = .;
*(.data .data.*)
*(.sdata .sdata.*)
@ -59,10 +56,8 @@ SECTIONS
*(.bss .bss.*)
*(COMMON)
data_end = .;
} :data
.rela : {
*(.rela .rela.*)
*(.no_unwind)
} :data
.got : {
@ -74,10 +69,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)

View File

@ -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)

View File

@ -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);

View File

@ -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