From nobody Sun Feb 8 14:53:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+102409+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102409+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1680532183; cv=none; d=zohomail.com; s=zohoarc; b=PCqFdpaYaa+z0ksjtptaC3dn7bG7QX/M0w5f53dFRaJKkMH+vLd6nikxnWg3Y/jb2tVRL6Q5idk9nfan0Cv+328pytVKOI7zV6Ckf3jH6dOhXmqOGNI+GCAFAqpesVfNXQ9e8XbN0F0EJD9n2dqEcmrOTBKHjzvGGDOgiQVaJ6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680532183; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=b3wmf81JIptsZtUzAxv+oaLrlOWx1LbLP2h5FqZlpk8=; b=nLUzs/4QbxAp67dtVwMxVrVW4eJrwzbp0oNKdx/o8VJvWO72wFX7RIumOqKetoe02JPaHO/B/34MJS0Be/OoA1vhKb2mLGMBuvpHCf4DCFwdb1JOSw1F+F6JKQP2q3qypVQD6bF4mFgISz+oz10m1+/6oY0g31KbzgTrQYeFGhU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102409+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1680532183598519.992826148999; Mon, 3 Apr 2023 07:29:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eyU6YY1788612xfHKssDEcDr; Mon, 03 Apr 2023 07:29:43 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.72012.1680532182181725317 for ; Mon, 03 Apr 2023 07:29:42 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 63E29B81C4E; Mon, 3 Apr 2023 14:29:40 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46864C4339B; Mon, 3 Apr 2023 14:29:37 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , "Ni, Ray" , Andrew Fish , "Kinney, Michael D" , "Liu, Zhiguang" , Rebecca Cran , Tom Lendacky , =?UTF-8?q?Marvin=20H=C3=A4user?= Subject: [edk2-devel] [PATCH v4 4/6] UefiCpuPkg/CpuExceptionHandlerLib: Make runtime fixups XCODE-only Date: Mon, 3 Apr 2023 16:29:18 +0200 Message-Id: <20230403142920.1921619-5-ardb@kernel.org> In-Reply-To: <20230403142920.1921619-1-ardb@kernel.org> References: <20230403142920.1921619-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org X-Gm-Message-State: Z9SbnWdjs5iGas6zpMYi562Vx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680532183; bh=ce4Pba8QVJIvLJ0nm8YTQ2O/8+wkSYj3YkOmELkzY+Y=; h=Cc:Date:From:Reply-To:Subject:To; b=J5Q/dsqg9ThqYPhLzOP9BsOB4aL91a/62GzL06/kI13vasg4AOX0MXf9EPDaIB6Ku9K Ko/QBZmkQPdNi3mYkDFOVrG3gv9mq0NhOLntQ4UUFrDYlFVQjR0LjmimzN/f+ck/+H4B9 65LQpG9AZONTV3N4OEICJlEfz+Q3nb6nmg0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680532184436100001 Content-Type: text/plain; charset="utf-8" The CPU exception handler library code was rewritten at some point to populate the vector code templates with absolute references at runtime, given that the XCODE linker does not permit absolute references in executable code when creating PIE executables. This is rather unfortunate, as this prevents us from using strict permissions on the memory mappings, given that the .text section needs to be writable at runtime for this arrangement to work. So let's make this hack XCODE-only, by setting a preprocessor #define from the command line when using the XCODE toolchain, and only including the runtime fixup code when the macro is defined. While at it, rename the Xcode5ExceptionHandlerAsm.nasm source file and drop the Xcode5 prefix: this code is used by other toolchains too. Signed-off-by: Ard Biesheuvel Reviewed-by: Ray Ni --- UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf = | 5 ++++- UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf = | 4 +++- UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/{Xcode5ExceptionHandlerAsm.n= asm =3D> ExceptionHandlerAsm.nasm} | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index d0f82095cf926e99..fdbebadab93df756 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -28,7 +28,7 @@ [Sources.Ia32] Ia32/ArchInterruptDefs.h =20 [Sources.X64] - X64/Xcode5ExceptionHandlerAsm.nasm + X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h =20 @@ -61,3 +61,6 @@ [LibraryClasses] MemoryAllocationLib DebugLib CcExitLib + +[BuildOptions] + XCODE:*_*_X64_NASM_FLAGS =3D -D NO_ABSOLUTE_RELOCS_IN_TEXT diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandle= rLib.inf index 8f8a5dab79303f87..27f0b96fa9e97705 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf @@ -28,7 +28,7 @@ [Sources.Ia32] Ia32/ArchInterruptDefs.h =20 [Sources.X64] - X64/Xcode5ExceptionHandlerAsm.nasm + X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h =20 @@ -61,3 +61,5 @@ [Pcd] [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONS= UMES =20 +[BuildOptions] + XCODE:*_*_X64_NASM_FLAGS =3D -D NO_ABSOLUTE_RELOCS_IN_TEXT diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionH= andlerAsm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHan= dlerAsm.nasm similarity index 95% rename from UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHa= ndlerAsm.nasm rename to UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm= .nasm index 957478574253e619..3d64ac908010562f 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA= sm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm @@ -59,7 +59,11 @@ AsmIdtVectorBegin: %rep 256 push strict dword %[Vector] ; This instruction pushes sign-extended= 8-byte value on stack push rax +%ifdef NO_ABSOLUTE_RELOCS_IN_TEXT mov rax, strict qword 0 ; mov rax, ASM_PFX(CommonInterruptE= ntry) +%else + mov rax, ASM_PFX(CommonInterruptEntry) +%endif jmp rax %assign Vector Vector+1 %endrep @@ -69,8 +73,12 @@ HookAfterStubHeaderBegin: push strict dword 0 ; 0 will be fixed VectorNum: push rax +%ifdef NO_ABSOLUTE_RELOCS_IN_TEXT mov rax, strict qword 0 ; mov rax, HookAfterStubHeaderEnd JmpAbsoluteAddress: +%else + mov rax, HookAfterStubHeaderEnd +%endif jmp rax HookAfterStubHeaderEnd: mov rax, rsp @@ -457,6 +465,7 @@ ASM_PFX(AsmGetTemplateAddressMap): lea rax, [HookAfterStubHeaderBegin] mov qword [rcx + 0x10], rax =20 +%ifdef NO_ABSOLUTE_RELOCS_IN_TEXT ; Fix up CommonInterruptEntry address lea rax, [ASM_PFX(CommonInterruptEntry)] lea rcx, [AsmIdtVectorBegin] @@ -468,6 +477,7 @@ ASM_PFX(AsmGetTemplateAddressMap): lea rax, [HookAfterStubHeaderEnd] lea rcx, [JmpAbsoluteAddress] mov qword [rcx - 8], rax +%endif =20 ret =20 --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#102409): https://edk2.groups.io/g/devel/message/102409 Mute This Topic: https://groups.io/mt/98036444/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-