From 574ed1ad936ea38b1dfac651cbe9569a25c80dfa Mon Sep 17 00:00:00 2001 From: Vitaly Cheptsov Date: Sun, 13 Feb 2022 07:59:46 +0300 Subject: [PATCH] BaseTools: Allow .text relocations in CLANGDWARF toolchain UefiCpuPkg modules like ExceptionHandlerAsm.nasm require relocations to .text or PIC as they use instructions like mov or bt against external symbols: 1. mov rax, ASM_PFX(CommonInterruptEntry) 2. mov rax, HookAfterStubHeaderEnd 3. bt [ASM_PFX(mErrorCodeFlag)], ecx 4. mov [rcx + (@VectorNum - HookAfterStubHeaderBegin)], al It is not easily possible to rewrite 3/4 cases without involving more registers or more commands, and EDK II has never targeted read-only .text at load time, only at runtime. Change the defaults to let OVMF compile by CLANGDWARF as per: https://lists.llvm.org/pipermail/llvm-dev/2017-March/111441.html Signed-off-by: Vitaly Cheptsov --- BaseTools/Conf/tools_def.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index ffeb227421..95bb797863 100755 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -2030,7 +2030,7 @@ DEFINE CLANGDWARF_X64_PREFIX = ENV(CLANG_BIN) # LLVM/CLANG doesn't support -n link option. So, it can't share the same IA32_X64_DLINK_COMMON flag. # LLVM/CLANG doesn't support common page size. So, it can't share the same GccBase.lds script. -DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40 +DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40 -Wl,-z,notext DEFINE CLANGDWARF_DLINK2_FLAGS_COMMON = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds DEFINE CLANGDWARF_IA32_X64_ASLDLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive -Wl,-z,notext