[FREELDR]

Put uninitialized/zero-initialized data into .bss. Fill it with 0s at startup.

svn path=/trunk/; revision=53798
This commit is contained in:
Dmitry Gorbachev 2011-09-22 06:06:51 +00:00
parent 7931e63ab8
commit 719a1ff1cf
4 changed files with 101 additions and 59 deletions

View file

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

View file

@ -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! */

View file

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

View file

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