misc: Misc EFI linker script improvements and drop .sbat

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

View File

@ -31,7 +31,7 @@ static void console_help(void) {
} }
#if defined (UEFI) #if defined (UEFI)
extern symbol __image_base; extern symbol __slide;
#endif #endif
void console(void) { void console(void) {
@ -67,7 +67,7 @@ void console(void) {
#endif #endif
#if defined (UEFI) #if defined (UEFI)
} else if (strcmp(prompt, "slide") == 0) { } else if (strcmp(prompt, "slide") == 0) {
print("%p\n", __image_base); print("%p\n", __slide);
#endif #endif
} else if (strcmp(prompt, "version") == 0) { } else if (strcmp(prompt, "version") == 0) {
print(LIMINE_VERSION "\n"); print(LIMINE_VERSION "\n");

View File

@ -26,7 +26,7 @@
void stage3_common(void); void stage3_common(void);
#if defined (UEFI) #if defined (UEFI)
extern symbol __image_base; extern symbol __slide;
noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
gST = SystemTable; gST = SystemTable;
@ -52,7 +52,7 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
#endif #endif
#if defined (__x86_64__) #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"); panic(false, "Limine does not support being loaded above 4GiB");
} }
#endif #endif

View File

@ -11,7 +11,7 @@
#if defined (BIOS) #if defined (BIOS)
extern symbol stage2_map; extern symbol stage2_map;
#elif defined (UEFI) #elif defined (UEFI)
extern symbol __image_base; extern symbol __slide;
#endif #endif
extern symbol full_map; extern symbol full_map;
@ -27,7 +27,7 @@ static char *trace_address(size_t *off, size_t addr) {
#elif defined (UEFI) #elif defined (UEFI)
limine_map = full_map; limine_map = full_map;
addr -= (size_t)__image_base; addr -= (size_t)__slide;
#endif #endif
uintptr_t prev_addr = 0; uintptr_t prev_addr = 0;

View File

@ -5,6 +5,7 @@ ENTRY(_start)
PHDRS PHDRS
{ {
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
rodata PT_LOAD FLAGS((1 << 2)) ;
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ;
} }
@ -12,11 +13,13 @@ PHDRS
SECTIONS SECTIONS
{ {
. = 0; . = 0;
__image_base = .; __slide = .;
__image_size = __image_end - __image_base; __image_base = ABSOLUTE(.);
__image_size = ABSOLUTE(__image_end - __image_base);
.text : { .text : {
*(.pe_header) *(.pe_header)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_start = ABSOLUTE(.); __text_start = ABSOLUTE(.);
@ -24,19 +27,13 @@ SECTIONS
} :text } :text
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_end = .; __text_end = ABSOLUTE(.);
__text_size = __text_end - __text_start; __text_size = ABSOLUTE(__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));
.rodata : {
__reloc_start = ABSOLUTE(.); __reloc_start = ABSOLUTE(.);
*(.data.reloc) *(.reloc)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__reloc_end = ABSOLUTE(.); __reloc_end = ABSOLUTE(.);
__reloc_size = ABSOLUTE(__reloc_end - __reloc_start); __reloc_size = ABSOLUTE(__reloc_end - __reloc_start);
@ -49,18 +46,16 @@ SECTIONS
#else #else
*(.full_map) *(.full_map)
#endif #endif
} :rodata
*(.no_unwind) .data : {
data_begin = .; data_begin = .;
*(.data .data.*) *(.data .data.*)
*(.bss .bss.*) *(.bss .bss.*)
*(COMMON) *(COMMON)
data_end = .; data_end = .;
} :data
.rela : { *(.no_unwind)
*(.rela .rela.*)
} :data } :data
.got : { .got : {
@ -72,10 +67,10 @@ SECTIONS
. = ALIGN(0x1000); . = ALIGN(0x1000);
} :data :dynamic } :data :dynamic
__data_end = .; __data_end = ABSOLUTE(.);
__data_size = __data_end - __data_start; __data_size = ABSOLUTE(__data_end - __data_start);
__image_end = .; __image_end = ABSOLUTE(.);
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)

View File

@ -5,6 +5,7 @@ ENTRY(_start)
PHDRS PHDRS
{ {
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
rodata PT_LOAD FLAGS((1 << 2)) ;
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ;
} }
@ -12,11 +13,13 @@ PHDRS
SECTIONS SECTIONS
{ {
. = 0; . = 0;
__image_base = .; __slide = .;
__image_size = __image_end - __image_base; __image_base = ABSOLUTE(.);
__image_size = ABSOLUTE(__image_end - __image_base);
.text : { .text : {
*(.pe_header) *(.pe_header)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_start = ABSOLUTE(.); __text_start = ABSOLUTE(.);
@ -24,19 +27,13 @@ SECTIONS
} :text } :text
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_end = .; __text_end = ABSOLUTE(.);
__text_size = __text_end - __text_start; __text_size = ABSOLUTE(__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));
.rodata : {
__reloc_start = ABSOLUTE(.); __reloc_start = ABSOLUTE(.);
*(.data.reloc) *(.reloc)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__reloc_end = ABSOLUTE(.); __reloc_end = ABSOLUTE(.);
__reloc_size = ABSOLUTE(__reloc_end - __reloc_start); __reloc_size = ABSOLUTE(__reloc_end - __reloc_start);
@ -49,18 +46,16 @@ SECTIONS
#else #else
*(.full_map) *(.full_map)
#endif #endif
} :rodata
*(.no_unwind) .data : {
data_begin = .; data_begin = .;
*(.data .data.*) *(.data .data.*)
*(.bss .bss.*) *(.bss .bss.*)
*(COMMON) *(COMMON)
data_end = .; data_end = .;
} :data
.rel : { *(.no_unwind)
*(.rel .rel.*)
} :data } :data
.got : { .got : {
@ -72,10 +67,10 @@ SECTIONS
. = ALIGN(0x1000); . = ALIGN(0x1000);
} :data :dynamic } :data :dynamic
__data_end = .; __data_end = ABSOLUTE(.);
__data_size = __data_end - __data_start; __data_size = ABSOLUTE(__data_end - __data_start);
__image_end = .; __image_end = ABSOLUTE(.);
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)

View File

@ -5,6 +5,7 @@ ENTRY(_start)
PHDRS PHDRS
{ {
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
rodata PT_LOAD FLAGS((1 << 2)) ;
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ;
} }
@ -12,11 +13,13 @@ PHDRS
SECTIONS SECTIONS
{ {
. = 0; . = 0;
__image_base = .; __slide = .;
__image_size = __image_end - __image_base; __image_base = ABSOLUTE(.);
__image_size = ABSOLUTE(__image_end - __image_base);
.text : { .text : {
*(.pe_header) *(.pe_header)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_start = ABSOLUTE(.); __text_start = ABSOLUTE(.);
@ -24,19 +27,13 @@ SECTIONS
} :text } :text
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_end = .; __text_end = ABSOLUTE(.);
__text_size = __text_end - __text_start; __text_size = ABSOLUTE(__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));
.rodata : {
__reloc_start = ABSOLUTE(.); __reloc_start = ABSOLUTE(.);
*(.data.reloc) *(.reloc)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__reloc_end = ABSOLUTE(.); __reloc_end = ABSOLUTE(.);
__reloc_size = ABSOLUTE(__reloc_end - __reloc_start); __reloc_size = ABSOLUTE(__reloc_end - __reloc_start);
@ -49,9 +46,9 @@ SECTIONS
#else #else
*(.full_map) *(.full_map)
#endif #endif
} :rodata
*(.no_unwind) .data : {
data_begin = .; data_begin = .;
*(.data .data.*) *(.data .data.*)
*(.sdata .sdata.*) *(.sdata .sdata.*)
@ -59,10 +56,8 @@ SECTIONS
*(.bss .bss.*) *(.bss .bss.*)
*(COMMON) *(COMMON)
data_end = .; data_end = .;
} :data
.rela : { *(.no_unwind)
*(.rela .rela.*)
} :data } :data
.got : { .got : {
@ -74,10 +69,10 @@ SECTIONS
. = ALIGN(0x1000); . = ALIGN(0x1000);
} :data :dynamic } :data :dynamic
__data_end = .; __data_end = ABSOLUTE(.);
__data_size = __data_end - __data_start; __data_size = ABSOLUTE(__data_end - __data_start);
__image_end = .; __image_end = ABSOLUTE(.);
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)

View File

@ -5,6 +5,7 @@ ENTRY(_start)
PHDRS PHDRS
{ {
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
rodata PT_LOAD FLAGS((1 << 2)) ;
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ;
} }
@ -12,11 +13,13 @@ PHDRS
SECTIONS SECTIONS
{ {
. = 0; . = 0;
__image_base = .; __slide = .;
__image_size = __image_end - __image_base; __image_base = ABSOLUTE(.);
__image_size = ABSOLUTE(__image_end - __image_base);
.text : { .text : {
*(.pe_header) *(.pe_header)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_start = ABSOLUTE(.); __text_start = ABSOLUTE(.);
@ -24,19 +27,13 @@ SECTIONS
} :text } :text
. = ALIGN(0x1000); . = ALIGN(0x1000);
__text_end = .; __text_end = ABSOLUTE(.);
__text_size = __text_end - __text_start; __text_size = ABSOLUTE(__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));
.rodata : {
__reloc_start = ABSOLUTE(.); __reloc_start = ABSOLUTE(.);
*(.data.reloc) *(.reloc)
. = ALIGN(0x1000); . = ALIGN(0x1000);
__reloc_end = ABSOLUTE(.); __reloc_end = ABSOLUTE(.);
__reloc_size = ABSOLUTE(__reloc_end - __reloc_start); __reloc_size = ABSOLUTE(__reloc_end - __reloc_start);
@ -49,18 +46,16 @@ SECTIONS
#else #else
*(.full_map) *(.full_map)
#endif #endif
} :rodata
*(.no_unwind) .data : {
data_begin = .; data_begin = .;
*(.data .data.*) *(.data .data.*)
*(.bss .bss.*) *(.bss .bss.*)
*(COMMON) *(COMMON)
data_end = .; data_end = .;
} :data
.rela : { *(.no_unwind)
*(.rela .rela.*)
} :data } :data
.got : { .got : {
@ -72,10 +67,10 @@ SECTIONS
. = ALIGN(0x1000); . = ALIGN(0x1000);
} :data :dynamic } :data :dynamic
__data_end = .; __data_end = ABSOLUTE(.);
__data_size = __data_end - __data_start; __data_size = ABSOLUTE(__data_end - __data_start);
__image_end = .; __image_end = ABSOLUTE(.);
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)

View File

@ -288,8 +288,8 @@ void init_memmap(void) {
#if defined (UEFI) #if defined (UEFI)
static struct memmap_entry *recl; static struct memmap_entry *recl;
extern symbol __image_base; extern symbol __slide;
extern symbol __image_end; extern symbol __image_size;
void init_memmap(void) { void init_memmap(void) {
EFI_STATUS status; EFI_STATUS status;
@ -422,10 +422,8 @@ void init_memmap(void) {
sanitiser_keep_first_page = old_skfp; sanitiser_keep_first_page = old_skfp;
size_t bootloader_size = ALIGN_UP((uintptr_t)__image_end - (uintptr_t)__image_base, 4096);
// Allocate bootloader itself // 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); MEMMAP_BOOTLOADER_RECLAIMABLE, 0, true, false, true);
sanitise_entries(memmap, &memmap_entries, false); 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