[FREELDR]

- The PE code can be built as an executable, it works as expected and nothing changes (the size of the generated code doesn't change).
- Export the Scsi functions also on x86 MSVC builds. Because of that, increase the number of expected PE sections in the FreeLdr image check function. Note that x64 MSVC build do not have the Scsi code ready yet, hence it doesn't export the corresponding functions.
- The spec2def command should have the name of the generated PE file.
- Remove one hardcoded value.

During my investigations I noticed that using a section alignment of 0x400 for freeldr MSVC builds (instead of the default 0x1000) made the MSVC builds *bigger*. Furthermore, using the default alignment of 0x1000 makes the freeldr MSVC builds unbootable. I don't understand why. Maybe a freeldr guru knows that?

svn path=/trunk/; revision=70687
This commit is contained in:
Hermès Bélusca-Maïto 2016-02-03 22:18:05 +00:00
parent 3f9bbc9a01
commit bc01b35fdf
3 changed files with 13 additions and 14 deletions

View file

@ -10,7 +10,7 @@ if(MSVC)
replace_compile_flags("/hotpatch" " ")
endif()
spec2def(freeldr.sys freeldr.spec)
spec2def(freeldr_pe.exe freeldr.spec)
if(ARCH STREQUAL "i386")
CreateBootSectorTarget(frldr16
@ -177,12 +177,14 @@ list(APPEND FREELDR_BASE_SOURCE
lib/inffile/inffile.c
lib/rtl/libsupp.c)
if(NOT MSVC)
list(APPEND FREELDR_BASE_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.def)
if(ARCH STREQUAL "i386")
# Must be included together with disk/scsiport.c
list(APPEND FREELDR_BASE_SOURCE
${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
endif()
add_library(freeldr_pe SHARED ${FREELDR_BASE_SOURCE})
add_library(freeldr_pe_dbg SHARED EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
if(NOT MSVC AND SEPARATE_DBG)
set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
@ -234,12 +236,10 @@ add_dependencies(freeldr_pe_dbg asm)
get_target_property(_freeldr_pe_output_file freeldr_pe LOCATION)
if(NOT ARCH STREQUAL "arm")
concatenate_files(
${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
${_freeldr_pe_output_file})
add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
else()
add_custom_target(freeldr ALL DEPENDS ${_freeldr_pe_output_file})
@ -250,16 +250,13 @@ add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINAT
add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB NOT_IN_HYBRIDCD FOR livecd hybridcd NAME_ON_CD setupldr.sys)
if(NOT ARCH STREQUAL "arm")
concatenate_files(
${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
${_freeldr_pe_output_file})
add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
else()
add_custom_target(setupldr ALL DEPENDS ${_freeldr_pe_output_file})
endif()
add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)

View file

@ -21,13 +21,15 @@
extern char __ImageBase;
#ifdef __GNUC__
/* .text, .edata and .bss */
#define FREELDR_SECTION_COUNT 3
#else
#ifdef _M_AMD64
/* .text and .pdata */
#define FREELDR_SECTION_COUNT 2
#else
#define FREELDR_SECTION_COUNT 1
/* .text and .edata */
#define FREELDR_SECTION_COUNT 2
#endif
#endif

View file

@ -258,8 +258,8 @@ MmCheckFreeldrImageFile(VOID)
FileHeader = &NtHeaders->FileHeader;
if ((FileHeader->Machine != IMAGE_FILE_MACHINE_NATIVE) ||
(FileHeader->NumberOfSections != FREELDR_SECTION_COUNT) ||
(FileHeader->PointerToSymbolTable != 0) ||
(FileHeader->NumberOfSymbols != 0) ||
(FileHeader->PointerToSymbolTable != 0) || // Symbols stripped
(FileHeader->NumberOfSymbols != 0) || // "" ""
(FileHeader->SizeOfOptionalHeader != sizeof(IMAGE_OPTIONAL_HEADER)))
{
ERR("FreeLdr FileHeader is invalid.\n");
@ -283,7 +283,7 @@ MmCheckFreeldrImageFile(VOID)
/* Check the optional header */
OptionalHeader = &NtHeaders->OptionalHeader;
if ((OptionalHeader->Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC) ||
(OptionalHeader->Subsystem != 1) || // native
(OptionalHeader->Subsystem != IMAGE_SUBSYSTEM_NATIVE) ||
(OptionalHeader->ImageBase != FREELDR_PE_BASE) ||
(OptionalHeader->SizeOfImage > MAX_FREELDR_PE_SIZE) ||
(OptionalHeader->SectionAlignment != OptionalHeader->FileAlignment))