diff options
author | Oliver Smith-Denny <osde@microsoft.com> | 2024-12-03 14:44:02 -0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-12-10 23:42:09 +0000 |
commit | bcbb7099594af28b5ba40521ba2ecef253adaa9f (patch) | |
tree | 56fe9494822c949cdabb4042784a76485e0d7ca3 | |
parent | f1e014a5caa576655170ae794dc1907c6304ea1b (diff) | |
download | edk2-bcbb7099594af28b5ba40521ba2ecef253adaa9f.tar.gz |
BaseTools: Add VS2022 XIPFLAGS
BaseTools has a limitation that modules in FVs that are force rebased
must have the same file and section alignment. This is intended for
XIP modules.
VS2019 and previous VS toolchains did not set 4k section alignment,
but VS2022 does, in order for memory protections to be applied to
images. This causes issues when building SEC and PEI modules on
VS2022 as the file alignment is 0x20 but the section alignment
is 0x1000, so BaseTools will fail to generate the FV. One option
is to set the file alignment to 0x1000 for all of these files, but
that is a large waste of space and is not feasible on some platforms
that have limited flash space. The other option is to selectively
set 0x20 as the section alignment for SEC and PEI modules, which is
the approach GCC ARM/AARCH64 took.
This is only an issue for building 64-bit PEI on x86 currently, as
other architectures are not supported by VS2022 in edk2 yet. For IA32,
the section alignment is set to 0x20 and so it matches the file
alignment, however x64 PEI uses the X64 DLINK flags which have 0x1000
set. For other architectures that don't have the PEI/DXE architecture
split, this is also an issue.
This commit is required to use VS2022 as the default CI in edk2, as
OvmfPkgX64.dsc will fail to build. Any platform with 64-bit PEI also
requires this.
This commit also updates CryptoPkg.dsc and SecurityPkg.dsc as they
are setting custom section alignments.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
-rwxr-xr-x | BaseTools/Conf/build_rule.template | 6 | ||||
-rw-r--r-- | BaseTools/Conf/target.template | 2 | ||||
-rwxr-xr-x | BaseTools/Conf/tools_def.template | 12 | ||||
-rw-r--r-- | CryptoPkg/CryptoPkg.dsc | 4 | ||||
-rw-r--r-- | SecurityPkg/SecurityPkg.dsc | 1 |
5 files changed, 23 insertions, 2 deletions
diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template index 041146124e..801b99a4a2 100755 --- a/BaseTools/Conf/build_rule.template +++ b/BaseTools/Conf/build_rule.template @@ -301,7 +301,7 @@ "$(DLINK)" $(DLINK_FLAGS) -o ${dst} $(DLINK_SPATH) -filelist $(STATIC_LIBRARY_FILES_LIST) $(DLINK2_FLAGS)
-[Static-Library-File.SEC.AARCH64, Static-Library-File.PEI_CORE.AARCH64, Static-Library-File.PEIM.AARCH64,Static-Library-File.SEC.ARM, Static-Library-File.PEI_CORE.ARM, Static-Library-File.PEIM.ARM]
+[Static-Library-File.SEC, Static-Library-File.PEI_CORE, Static-Library-File.PEIM]
<InputFile>
*.lib
@@ -311,6 +311,10 @@ <OutputFile>
$(DEBUG_DIR)(+)$(MODULE_NAME).dll
+ <Command.MSFT>
+ "$(DLINK)" /OUT:${dst} $(DLINK_FLAGS) $(DLINK2_FLAGS) $(DLINK_XIPFLAGS) $(DLINK_SPATH) @$(STATIC_LIBRARY_FILES_LIST)
+ "$(DLINK)" /OUT:${dst} $(DLINK_FLAGS) $(DLINK_XIPFLAGS) $(DLINK_SPATH) @$(STATIC_LIBRARY_FILES_LIST)
+
<Command.GCC>
"$(DLINK)" -o ${dst} $(DLINK_FLAGS) $(DLINK_XIPFLAGS) -Wl,--start-group,@$(STATIC_LIBRARY_FILES_LIST),--end-group $(CC_FLAGS) $(CC_XIPFLAGS) $(DLINK2_FLAGS)
"$(OBJCOPY)" $(OBJCOPY_FLAGS) ${dst}
diff --git a/BaseTools/Conf/target.template b/BaseTools/Conf/target.template index 592febf557..29c38142aa 100644 --- a/BaseTools/Conf/target.template +++ b/BaseTools/Conf/target.template @@ -51,7 +51,7 @@ TOOL_CHAIN_CONF = Conf/tools_def.txt # TAGNAME List Optional Specify the name(s) of the tools_def.txt TagName to use.
# If not specified, all applicable TagName tools will be
# used for the build. The list uses space character separation.
-TOOL_CHAIN_TAG = VS2019
+TOOL_CHAIN_TAG = VS2022
# MAX_CONCURRENT_THREAD_NUMBER NUMBER Optional The number of concurrent threads. If not specified or set
# to zero, tool automatically detect number of processor
diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index ff04599f8a..2d8c060c9c 100755 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -795,6 +795,9 @@ NOOPT_VS2022_IA32_NASM_FLAGS = -O0 -f win32 -g RELEASE_VS2022_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data
NOOPT_VS2022_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG
+# BaseTools cannot handle XIP modules with different section and file alignment
+*_VS2022_IA32_DLINK_XIPFLAGS = /ALIGN:32
+
##################
# X64 definitions
##################
@@ -825,6 +828,9 @@ NOOPT_VS2022_X64_NASM_FLAGS = -O0 -f win64 -g RELEASE_VS2022_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data /ALIGN:4096 /DLL
NOOPT_VS2022_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG /ALIGN:4096 /DLL
+# BaseTools cannot handle XIP modules with different section and file alignment
+*_VS2022_X64_DLINK_XIPFLAGS = /ALIGN:32
+
#################
# ARM definitions
#################
@@ -852,6 +858,9 @@ NOOPT_VS2022_ARM_ASM_FLAGS = /nologo RELEASE_VS2022_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data
NOOPT_VS2022_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG
+# BaseTools cannot handle XIP modules with different section and file alignment
+*_VS2022_ARM_DLINK_XIPFLAGS = /ALIGN:32
+
#####################
# AARCH64 definitions
#####################
@@ -879,6 +888,9 @@ NOOPT_VS2022_AARCH64_ASM_FLAGS = /nologo RELEASE_VS2022_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /MERGE:.rdata=.data
NOOPT_VS2022_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /DEBUG
+# BaseTools cannot handle XIP modules with different section and file alignment
+*_VS2022_AARCH64_DLINK_XIPFLAGS = /ALIGN:32
+
####################################################################################
# GCC Common
####################################################################################
diff --git a/CryptoPkg/CryptoPkg.dsc b/CryptoPkg/CryptoPkg.dsc index 62815978ff..475bdd41e4 100644 --- a/CryptoPkg/CryptoPkg.dsc +++ b/CryptoPkg/CryptoPkg.dsc @@ -457,7 +457,9 @@ OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf
<BuildOptions>
MSFT:*_*_IA32_DLINK_FLAGS = /ALIGN:64
+ MSFT:*_*_IA32_DLINK_XIPFLAGS = /ALIGN:64
MSFT:*_*_X64_DLINK_FLAGS = /ALIGN:256
+ MSFT:*_*_X64_DLINK_XIPFLAGS = /ALIGN:256
}
#
@@ -471,7 +473,9 @@ OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
<BuildOptions>
MSFT:*_*_IA32_DLINK_FLAGS = /ALIGN:4096
+ MSFT:*_*_IA32_DLINK_XIPFLAGS = /ALIGN:4096
MSFT:*_*_X64_DLINK_FLAGS = /ALIGN:4096
+ MSFT:*_*_X64_DLINK_XIPFLAGS = /ALIGN:4096
GCC:*_*_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x1000
}
!endif
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 2ff9c256e4..0b167032ea 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -408,5 +408,6 @@ [BuildOptions]
MSFT:*_*_IA32_DLINK_FLAGS = /ALIGN:256
+ MSFT:*_*_IA32_DLINK_XIPFLAGS = /ALIGN:256
INTEL:*_*_IA32_DLINK_FLAGS = /ALIGN:256
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
|