[llvm] [CodeGen][X86] Honor LargeEHEncoding when selecting x86-64 EH encoding (PR #210109)
Farid Zakaria via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 09:45:04 PDT 2026
https://github.com/fzakaria created https://github.com/llvm/llvm-project/pull/210109
Apply suggestion from https://github.com/llvm/llvm-project/pull/174508#discussion_r3589397222
On x86-64, select the exception-handling pointer encodings as if the Large code model were in use when MCOptions.LargeEHEncoding is set. This uses a case-scoped local (EHCM) rather than mutating the object file's code model, so only the EH encoding selection is affected as recommended by @jrtc27
>From c0a0ac18cc0fbc5392f0069a334524e10da5054c Mon Sep 17 00:00:00 2001
From: Farid Zakaria <fmzakari at fb.com>
Date: Thu, 16 Jul 2026 09:42:24 -0700
Subject: [PATCH] [CodeGen][X86] Honor LargeEHEncoding when selecting x86-64 EH
pointer encodings
On x86-64, select the exception-handling pointer encodings as if the
Large code model were in use when MCOptions.LargeEHEncoding is set. This
uses a case-scoped local (EHCM) rather than mutating the object file's
code model, so only the EH encoding selection is affected.
---
.../CodeGen/TargetLoweringObjectFileImpl.cpp | 22 +++++++++++--------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index c7d07c1e40393..855db870f2a59 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -150,29 +150,33 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
break;
- case Triple::x86_64:
- if (TgtM.Options.MCOptions.LargeEHEncoding)
- CM = CodeModel::Large;
+ case Triple::x86_64: {
+ // The large EH encoding forces 64-bit-wide EH pointers regardless of the
+ // code model, so treat it like the Large code model when selecting
+ // encodings below.
+ CodeModel::Model EHCM =
+ TgtM.Options.MCOptions.LargeEHEncoding ? CodeModel::Large : CM;
if (isPositionIndependent()) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
- ((CM == CodeModel::Small || CM == CodeModel::Medium)
+ ((EHCM == CodeModel::Small || EHCM == CodeModel::Medium)
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
LSDAEncoding = dwarf::DW_EH_PE_pcrel |
- (CM == CodeModel::Small
+ (EHCM == CodeModel::Small
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
- ((CM == CodeModel::Small || CM == CodeModel::Medium)
+ ((EHCM == CodeModel::Small || EHCM == CodeModel::Medium)
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
} else {
PersonalityEncoding =
- (CM == CodeModel::Small || CM == CodeModel::Medium)
+ (EHCM == CodeModel::Small || EHCM == CodeModel::Medium)
? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
- LSDAEncoding = (CM == CodeModel::Small)
+ LSDAEncoding = (EHCM == CodeModel::Small)
? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
- TTypeEncoding = (CM == CodeModel::Small)
+ TTypeEncoding = (EHCM == CodeModel::Small)
? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
}
break;
+ }
case Triple::hexagon:
PersonalityEncoding = dwarf::DW_EH_PE_absptr;
LSDAEncoding = dwarf::DW_EH_PE_absptr;
More information about the llvm-commits
mailing list