Switch to new mtoc

This commit is contained in:
jief 2020-02-17 12:54:54 +03:00
parent c3a0756851
commit 5a63f45f7d
6 changed files with 5327 additions and 37 deletions

View File

@ -2424,7 +2424,7 @@ RELEASE_GCC48_AARCH64_CC_FLAGS = DEF(GCC48_AARCH64_CC_FLAGS) -Wno-unused-but-s
*_XCODE5_*_*_BUILDRULEFAMILY = XCODE *_XCODE5_*_*_BUILDRULEFAMILY = XCODE
*_XCODE5_*_*_BUILDRULEORDER = S s nasm *_XCODE5_*_*_BUILDRULEORDER = S s nasm
*_XCODE5_*_MTOC_PATH = ENV(MTOC_PREFIX)mtoc.NEW *_XCODE5_*_MTOC_PATH = ENV(MTOC_PREFIX)mtoc.NEW_jief
*_XCODE5_*_MAKE_PATH = make *_XCODE5_*_MAKE_PATH = make
*_XCODE5_*_DSYMUTIL_PATH = /usr/bin/dsymutil *_XCODE5_*_DSYMUTIL_PATH = /usr/bin/dsymutil
@ -2453,9 +2453,9 @@ RELEASE_XCODE5_*_DLINK_PATH = clang
#################### ####################
# IA-32 definitions # IA-32 definitions
#################### ####################
DEBUG_XCODE5_IA32_DLINK_FLAGS = -arch i386 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x240 -read_only_relocs suppress -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map DEBUG_XCODE5_IA32_DLINK_FLAGS = -arch i386 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x260 -read_only_relocs suppress -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
NOOPT_XCODE5_IA32_DLINK_FLAGS = -arch i386 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x240 -read_only_relocs suppress -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map NOOPT_XCODE5_IA32_DLINK_FLAGS = -arch i386 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x260 -read_only_relocs suppress -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
RELEASE_XCODE5_IA32_DLINK_FLAGS = -arch i386 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x240,-read_only_relocs,suppress,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map RELEASE_XCODE5_IA32_DLINK_FLAGS = -arch i386 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x260,-read_only_relocs,suppress,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
*_XCODE5_IA32_SLINK_FLAGS = -static -o *_XCODE5_IA32_SLINK_FLAGS = -static -o
DEBUG_XCODE5_IA32_ASM_FLAGS = -arch i386 -g DEBUG_XCODE5_IA32_ASM_FLAGS = -arch i386 -g
@ -2486,9 +2486,9 @@ RELEASE_XCODE5_IA32_CC_FLAGS = -arch i386 -c -Os -Wall -Werror -inclu
################## ##################
# X64 definitions # X64 definitions
################## ##################
DEBUG_XCODE5_X64_DLINK_FLAGS = -arch x86_64 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x240 -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map DEBUG_XCODE5_X64_DLINK_FLAGS = -arch x86_64 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x260 -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
NOOPT_XCODE5_X64_DLINK_FLAGS = -arch x86_64 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x240 -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map NOOPT_XCODE5_X64_DLINK_FLAGS = -arch x86_64 -u _$(IMAGE_ENTRY_POINT) -e _$(IMAGE_ENTRY_POINT) -preload -segalign 0x20 -pie -all_load -dead_strip -seg1addr 0x260 -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
RELEASE_XCODE5_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x240,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map RELEASE_XCODE5_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x260,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
*_XCODE5_X64_SLINK_FLAGS = -static -o *_XCODE5_X64_SLINK_FLAGS = -static -o
DEBUG_XCODE5_X64_ASM_FLAGS = -arch x86_64 -g DEBUG_XCODE5_X64_ASM_FLAGS = -arch x86_64 -g
@ -2520,7 +2520,7 @@ RELEASE_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -Os -W
*_XCODE5_*_ASLCC_FLAGS = -x c -save-temps -g -O0 -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-missing-braces -c -include AutoGen.h *_XCODE5_*_ASLCC_FLAGS = -x c -save-temps -g -O0 -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-missing-braces -c -include AutoGen.h
# -mdynamic-no-pic # -mdynamic-no-pic
*_XCODE5_*_ASLDLINK_FLAGS = -e _ReferenceAcpiTable -preload -segalign 0x20 -pie -seg1addr 0x240 -read_only_relocs suppress -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map *_XCODE5_*_ASLDLINK_FLAGS = -e _ReferenceAcpiTable -preload -segalign 0x20 -pie -seg1addr 0x260 -read_only_relocs suppress -map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
*_XCODE5_*_ASLPP_FLAGS = DEF(GCC_ASLPP_FLAGS) *_XCODE5_*_ASLPP_FLAGS = DEF(GCC_ASLPP_FLAGS)
*_XCODE5_*_ASL_FLAGS = *_XCODE5_*_ASL_FLAGS =
# -ta # -ta
@ -2536,7 +2536,7 @@ RELEASE_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -Os -W
*_XCODE8_*_*_BUILDRULEFAMILY = XCODE *_XCODE8_*_*_BUILDRULEFAMILY = XCODE
*_XCODE8_*_*_BUILDRULEORDER = nasm S s *_XCODE8_*_*_BUILDRULEORDER = nasm S s
*_XCODE8_*_MTOC_PATH = ENV(MTOC_PREFIX)mtoc.NEW *_XCODE8_*_MTOC_PATH = ENV(MTOC_PREFIX)mtoc.NEW_jief
*_XCODE8_*_MAKE_PATH = make *_XCODE8_*_MAKE_PATH = make
*_XCODE8_*_DSYMUTIL_PATH = /usr/bin/dsymutil *_XCODE8_*_DSYMUTIL_PATH = /usr/bin/dsymutil
@ -2563,8 +2563,8 @@ RELEASE_XCODE8_*_MTOC_FLAGS = -align 0x20
################## ##################
# X64 definitions # X64 definitions
################## ##################
DEBUG_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x240,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map DEBUG_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x260,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
RELEASE_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x240,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map RELEASE_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x260,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
*_XCODE8_X64_SLINK_FLAGS = -static -o *_XCODE8_X64_SLINK_FLAGS = -static -o
DEBUG_XCODE8_X64_ASM_FLAGS = -c -x assembler -arch x86_64 -g DEBUG_XCODE8_X64_ASM_FLAGS = -c -x assembler -arch x86_64 -g
@ -2580,7 +2580,7 @@ RELEASE_XCODE8_X64_CC_FLAGS = -c -Os -Wall -Werror -Wextra -include A
# -Wno-unused-const-variable # -Wno-unused-const-variable
*_XCODE8_*_ASLCC_FLAGS = -x c -save-temps -g -O0 -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-missing-braces -c -include AutoGen.h *_XCODE8_*_ASLCC_FLAGS = -x c -save-temps -g -O0 -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-missing-braces -c -include AutoGen.h
*_XCODE8_*_ASLDLINK_FLAGS = -nostdlib -Wl,-e,_ReferenceAcpiTable,-preload,-segalign,0x20,-pie,-seg1addr,0x240,-read_only_relocs,suppress,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map *_XCODE8_*_ASLDLINK_FLAGS = -nostdlib -Wl,-e,_ReferenceAcpiTable,-preload,-segalign,0x20,-pie,-seg1addr,0x260,-read_only_relocs,suppress,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
*_XCODE8_*_ASLPP_FLAGS = DEF(GCC_ASLPP_FLAGS) *_XCODE8_*_ASLPP_FLAGS = DEF(GCC_ASLPP_FLAGS)
*_XCODE8_*_ASL_FLAGS = *_XCODE8_*_ASL_FLAGS =
*_XCODE8_*_ASL_OUTFLAGS = DEF(IASL_OUTFLAGS) *_XCODE8_*_ASL_OUTFLAGS = DEF(IASL_OUTFLAGS)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,12 @@
# Script for building MTOC # Script for building MTOC
# #
if [ -z "$WORKSPACE" ]
then
echo WORKSPACE must be defined to Clover root path
exit 1
fi
# Ctools source version # Ctools source version
# here we can change source versions of tools # here we can change source versions of tools
# #
@ -134,6 +140,9 @@ fnExtract ()
echo "- ${package} extract..." echo "- ${package} extract..."
rm -rf "${DIR_BUILD}/$top_level_dir" # Remove old directory if exists rm -rf "${DIR_BUILD}/$top_level_dir" # Remove old directory if exists
tar -C "$DIR_BUILD" -x "$tar_filter_option" -f "${tarball}" && touch "${DIR_BUILD}/$package.extracted" tar -C "$DIR_BUILD" -x "$tar_filter_option" -f "${tarball}" && touch "${DIR_BUILD}/$package.extracted"
#jief copy the modified version that keeps __mod_init_func section
cp "$WORKSPACE"/BaseTools/Source/C/mtoc/mtoc-v921_jief.c "$DIR_BUILD/$top_level_dir"/efitools/mtoc.c
fi fi
# Restore stdout for the result and close file desciptor 3 # Restore stdout for the result and close file desciptor 3
@ -170,7 +179,7 @@ fnCompileMtoc ()
exit 1 exit 1
fi fi
echo "- cctools-${CCTOOLS_VERSION} installing mtoc..." echo "- cctools-${CCTOOLS_VERSION} installing mtoc..."
cmd="install -c -s -m 555 efitools/mtoc.NEW ${PREFIX}/bin" cmd="install -c -s -m 555 efitools/mtoc.NEW ${PREFIX}/bin/mtoc.NEW_jief"
logfile="$DIR_LOGS/mtoc.install.log.txt" logfile="$DIR_LOGS/mtoc.install.log.txt"
echo "$cmd" > "$logfile" echo "$cmd" > "$logfile"
eval "$cmd" >> "$logfile" 2>&1 eval "$cmd" >> "$logfile" 2>&1

View File

@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if 0 #if 1
#define DBG(...) DebugLog(2, __VA_ARGS__) #define DBG(...) DebugLog(2, __VA_ARGS__)
#else #else
#define DBG(...) #define DBG(...)
@ -25,23 +25,10 @@ typedef ctor* ctor_ptr;
#if defined(__clang__) #if defined(__clang__)
extern "C" {
/*
* This symbol will be placed at the beginning of the section following the __mod_init_func section.
* This way, will know the size of the __mod_init_func section.
* In the efi file, __mod_init_func section has been merged with the following section. That's why we need this trick.
*/
void __attribute__((section ("__DATA,__const"))) __attribute__((optnone)) beginning_of_section_next_to_mod_init_func() {};
}
void construct_globals_objects() void construct_globals_objects()
{ {
// beginning_of_section_next_to_mod_init_func(); // to not be optimized out
ctor_ptr* beginning_of_section_next_to_mod_init_func_ptr = (ctor_ptr*)&beginning_of_section_next_to_mod_init_func;
DBG("beginning_of_section_next_to_mod_init_func_ptr=%08x\n", (UINTN)beginning_of_section_next_to_mod_init_func_ptr);
UINT32 PeCoffHeaderOffset = 0; UINT32 PeCoffHeaderOffset = 0;
EFI_IMAGE_DOS_HEADER* DosHdr = (EFI_IMAGE_DOS_HEADER*)SelfLoadedImage->ImageBase; EFI_IMAGE_DOS_HEADER* DosHdr = (EFI_IMAGE_DOS_HEADER*)SelfLoadedImage->ImageBase;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) { if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
@ -56,18 +43,21 @@ DBG("beginning_of_section_next_to_mod_init_func_ptr=%08x\n", (UINTN)beginning_of
for (int Index = 0; Index < ImgHdr->Pe32.FileHeader.NumberOfSections; Index++, SectionHeader++) for (int Index = 0; Index < ImgHdr->Pe32.FileHeader.NumberOfSections; Index++, SectionHeader++)
{ {
DBG("name=%a\n", SectionHeader->Name); DBG("SectionHeader->Name=%a\n", SectionHeader->Name);
if (AsciiStrCmp((CONST CHAR8*) SectionHeader->Name, ".data") == 0) // DBG("SectionHeader->PointerToRawData=%8x\n", SectionHeader->PointerToRawData);
// DBG("SectionHeader->SizeOfRawData=%8x\n", SectionHeader->SizeOfRawData);
DBG("SectionHeader->VirtualSize=%8x\n", SectionHeader->Misc.VirtualSize);
if (AsciiStrCmp((CONST CHAR8*) SectionHeader->Name, ".ctorss") == 0)
{ {
DBG("SectionHeader->PointerToRawData=%8x\n", SectionHeader->PointerToRawData);
ctor_ptr* myctor = (ctor_ptr*) (((UINTN) (SelfLoadedImage->ImageBase)) + SectionHeader->PointerToRawData); ctor_ptr* currentCtor = (ctor_ptr*) (((UINTN) (SelfLoadedImage->ImageBase)) + SectionHeader->PointerToRawData);
while (myctor < beginning_of_section_next_to_mod_init_func_ptr) ctor_ptr* ctorend = (ctor_ptr*) (((UINTN) (SelfLoadedImage->ImageBase)) + SectionHeader->PointerToRawData + SectionHeader->Misc.VirtualSize);
while (currentCtor < ctorend)
{ {
DBG("&myctor %x %d\n", (UINTN) (myctor), (UINTN) (myctor)); DBG("&currentCtor %x %d\n", (UINTN) (currentCtor), (UINTN) (currentCtor));
DBG("myctor %x %d\n", (UINTN) (*myctor), (UINTN) (*myctor)); DBG("currentCtor %x %d\n", (UINTN) (*currentCtor), (UINTN) (*currentCtor));
if (*myctor != NULL) (*myctor)(); if (*currentCtor != NULL) (*currentCtor)();
myctor++; currentCtor++;
} }
} }
} }

View File

@ -1,6 +1,6 @@
#include <Platform/Platform.h> #include <Platform/Platform.h>
#if 0 #if 1
#define DBG(...) DebugLog(2, __VA_ARGS__) #define DBG(...) DebugLog(2, __VA_ARGS__)
#else #else
#define DBG(...) #define DBG(...)