Optimize the x86 binary size

This commit is contained in:
Ruihan Li 2025-07-19 00:53:07 +08:00 committed by Junyang Zhang
parent 424fcda239
commit e475009fe7
3 changed files with 20 additions and 13 deletions

View File

@ -61,16 +61,21 @@ SECTIONS
# --------------------------------------------------------------------------- #
. = BSP_BOOT_LMA;
.bsp_boot : AT(BSP_BOOT_LMA) {
KEEP(*(.bsp_boot .bsp_boot.*))
.bsp_boot : AT(ADDR(.bsp_boot)) {
KEEP(*(.bsp_boot))
} : bsp_boot
# Create a separate .bsp_boot.stack section so that the executable doesn't
# contain the boot stack (which is just hundreds of kilobytes of zeros).
.bsp_boot.stack : AT(ADDR(.bsp_boot.stack)) {
KEEP(*(.bsp_boot.stack))
. = ALIGN(4096);
} : bsp_boot
. = AP_EXEC_MA;
.ap_boot : AT(BSP_BOOT_LMA + SIZEOF(.bsp_boot)) {
__ap_boot_start = BSP_BOOT_LMA + SIZEOF(.bsp_boot) + KERNEL_VMA;
KEEP(*(.ap_boot .ap_boot.*))
.ap_boot : AT(LOADADDR(.bsp_boot.stack) + SIZEOF(.bsp_boot.stack)) {
__ap_boot_start = LOADADDR(.ap_boot) + KERNEL_VMA;
KEEP(*(.ap_boot))
__ap_boot_end = __ap_boot_start + (. - AP_EXEC_MA);
. = ALIGN(4096);
} : ap_boot
@ -78,7 +83,7 @@ SECTIONS
# --------------------------------------------------------------------------- #
# Here are the rest of the virtual memory sections which can be relocated. #
# --------------------------------------------------------------------------- #
. = BSP_BOOT_LMA + KERNEL_VMA + SIZEOF(.bsp_boot) + SIZEOF(.ap_boot);
. = LOADADDR(.ap_boot) + SIZEOF(.ap_boot) + KERNEL_VMA;
.text : AT(ADDR(.text) - KERNEL_VMA) {
*(.text .text.*)

View File

@ -5,7 +5,7 @@
.global ap_boot_from_real_mode
.global ap_boot_from_long_mode
.section ".ap_boot", "awx"
.section ".ap_boot", "awx", @progbits
.align 4096
IA32_EFER_MSR = 0xC0000080

View File

@ -5,7 +5,7 @@
// The boot header, initial boot setup code, temporary GDT and page tables are
// in the boot section. The boot section is mapped writable since kernel may
// modify the initial page table.
.section ".bsp_boot", "awx"
.section ".bsp_boot", "awx", @progbits
.code32
// With every entry types we could go through common paging or machine
@ -285,11 +285,6 @@ boot_l2pt_3g_4g:
.skip 4096
boot_page_table_end:
.global boot_stack_top
boot_stack_bottom:
.skip 0x40000
boot_stack_top:
.code64
long_mode_in_low_address:
mov ax, 0
@ -305,6 +300,13 @@ long_mode_in_low_address:
mov rax, offset long_mode
jmp rax
.section ".bsp_boot.stack", "aw", @nobits
.global boot_stack_top
boot_stack_bottom:
.align 4096
.skip 0x40000 # 256 KiB
boot_stack_top:
// From here, we're in the .text section: we no longer use physical address.
.text
.code64