From 719a1ff1cf14bce787bd9b3d9ea708ed1b27f9d1 Mon Sep 17 00:00:00 2001 From: Dmitry Gorbachev Date: Thu, 22 Sep 2011 06:06:51 +0000 Subject: [PATCH] [FREELDR] Put uninitialized/zero-initialized data into .bss. Fill it with 0s at startup. svn path=/trunk/; revision=53798 --- reactos/boot/freeldr/freeldr/CMakeLists.txt | 4 - .../boot/freeldr/freeldr/arch/i386/entry.S | 14 +- .../freeldr/freeldr/arch/i386/multiboot.S | 11 +- reactos/boot/freeldr/freeldr/freeldr_i386.lnk | 131 ++++++++++++------ 4 files changed, 101 insertions(+), 59 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/CMakeLists.txt b/reactos/boot/freeldr/freeldr/CMakeLists.txt index 57a86a98b7b..7851e56dca1 100644 --- a/reactos/boot/freeldr/freeldr/CMakeLists.txt +++ b/reactos/boot/freeldr/freeldr/CMakeLists.txt @@ -203,10 +203,6 @@ if(ARCH MATCHES i386 OR ARCH MATCHES amd64) list(APPEND SETUPLDR_SOURCE windows/setupldr.c) endif() -if(NOT MSVC) - set_source_files_properties(${SETUPLDR_SOURCE} PROPERTIES COMPILE_FLAGS "-ffreestanding -fno-builtin -fno-inline -fno-zero-initialized-in-bss") -endif() - add_executable(setupldr_pe ${FREELDR_BASE_SOURCE} ${SETUPLDR_SOURCE}) if(NOT MSVC) diff --git a/reactos/boot/freeldr/freeldr/arch/i386/entry.S b/reactos/boot/freeldr/freeldr/arch/i386/entry.S index 61d44b08038..d352f10e79f 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/entry.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/entry.S @@ -70,11 +70,19 @@ _FrldrStartup: /* Initialize the idt */ call _InitIdt - /* Pass the command line to BootMain */ -#ifdef _USE_ML +#ifndef _USE_ML + /* Clean out bss */ xor eax, eax -#else + mov edi, offset __bss_start__ + mov ecx, offset __bss_end__ + 3 + sub ecx, edi + shr ecx, 2 + rep stosd + + /* Pass the command line to BootMain */ mov eax, offset cmdline +#else + xor eax, eax #endif /* GO! */ diff --git a/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S b/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S index 72a40c49e2f..d00333e2646 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/multiboot.S @@ -58,7 +58,7 @@ MultibootHeader: /* load_addr */ .long INITIAL_BASE /* load_end_addr */ - .long INITIAL_BASE + __bss_start__ - FREELDR_BASE + .long 0 /* bss_end_addr */ .long 0 /* entry_addr */ @@ -98,17 +98,10 @@ mb3: /* Relocate itself to lower address */ mov esi, INITIAL_BASE mov edi, FREELDR_BASE - mov ecx, (offset __bss_start__ - FREELDR_BASE + 3) + mov ecx, offset __bss_start__ - FREELDR_BASE shr ecx, 2 rep movsd - /* Clean out bss */ - xor eax, eax - mov ecx, offset __bss_end__ + 3 - sub ecx, offset __bss_start__ - shr ecx, 2 - rep stosd - /* Load segment registers for real-address mode */ lgdt gdtptr mov ax, HEX(10) diff --git a/reactos/boot/freeldr/freeldr/freeldr_i386.lnk b/reactos/boot/freeldr/freeldr/freeldr_i386.lnk index 41a6da04766..29997a4193a 100644 --- a/reactos/boot/freeldr/freeldr/freeldr_i386.lnk +++ b/reactos/boot/freeldr/freeldr/freeldr_i386.lnk @@ -1,58 +1,103 @@ -OUTPUT_FORMAT(pei-i386) -ENTRY(_mainCRTStartup) SECTIONS { - .text __image_base__ + __section_alignment__ : + .text __image_base__ + __section_alignment__ : { - __text_start__ = .; - *(.init) *(.text) - *(SORT(.text$*)) - *(.glue_7t) - *(.glue_7) - ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; - LONG (-1); *(.ctors); *(.ctor); LONG (0); - ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; - LONG (-1); *(.dtors); *(.dtor); LONG (0); - *(.fini) - /* ??? Why is .gcc_exc here? */ - *(.gcc_exc) - __text_end__ = .; - *(.gcc_except_table) - } - init BLOCK(__section_alignment__) : - { - __init_start__ = . ; - *(init) - __init_end__ = . ; - } - .data BLOCK(__section_alignment__) : - { - __data_start__ = . ; + *(SORT(.text*)) *(.data) - *(.data2) - *(SORT(.data$*)) + *(SORT(.data*)) *(.rdata) - *(SORT(.rdata$*)) - *(.eh_frame) - __data_end__ = . ; + *(SORT(.rdata*)) + } + + .bss : + { __bss_start__ = . ; *(.bss) *(COMMON) __bss_end__ = . ; } + + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section. Unlike other targets that fake this by putting the + section VMA at 0, the PE format will not allow it. */ + /* DWARF 1.1 and DWARF 2. */ + .debug_aranges BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_aranges) + } + .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_pubnames) + } + .debug_pubtypes BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_pubtypes) + } + /* DWARF 2. */ + .debug_info BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_info) *(.gnu.linkonce.wi.*) + } + .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_abbrev) + } + .debug_line BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_line) + } + .debug_frame BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_frame*) + } + .debug_str BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_str) + } + .debug_loc BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_loc) + } + .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_macinfo) + } + /* SGI/MIPS DWARF 2 extensions. */ + .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_weaknames) + } + .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_funcnames) + } + .debug_typenames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_typenames) + } + .debug_varnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_varnames) + } + .debug_macro BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_macro) + } + /* DWARF 3. */ + .debug_ranges BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_ranges) + } + /* DWARF 4. */ + .debug_types BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_types) *(.gnu.linkonce.wt.*) + } + /DISCARD/ : { - *(.drectve) + *(*) } - .stab BLOCK(__section_alignment__) (NOLOAD) : - { - [ .stab ] - } - .stabstr BLOCK(__section_alignment__) (NOLOAD) : - { - [ .stabstr ] - } - } -