<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Ack. The only change in this case was moving <span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;">llvm/test/MC/MachO/emit-dwarf-unwind.s
to <span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); display: inline !important;">llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s. Will include it in the commit message in the future.</span></span></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> David Blaikie <dblaikie@gmail.com><br>
<b>Sent:</b> Monday, June 13, 2022 5:01 PM<br>
<b>To:</b> Jez Ng <jezng@fb.com>; Jez Ng <llvmlistbot@llvm.org><br>
<b>Cc:</b> cfe-commits <cfe-commits@lists.llvm.org><br>
<b>Subject:</b> Re: [clang] d4bcb45 - [MC][re-land] Omit DWARF unwind info if compact unwind is present where eligible</font>
<div> </div>
</div>
<div>
<div dir="ltr">Please include details of what changed between one commit and a recommit of a patch - helpful for reviewers checking what's changed since the last commit, double-checking that the patch fully addresses the issues, etc.</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Sun, Jun 12, 2022 at 2:24 PM Jez Ng via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<br>
Author: Jez Ng<br>
Date: 2022-06-12T17:24:19-04:00<br>
New Revision: d4bcb45db78dc7ca371224cb01bea8dcb14e0698<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/d4bcb45db78dc7ca371224cb01bea8dcb14e0698" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/d4bcb45db78dc7ca371224cb01bea8dcb14e0698</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/d4bcb45db78dc7ca371224cb01bea8dcb14e0698.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/d4bcb45db78dc7ca371224cb01bea8dcb14e0698.diff</a><br>
<br>
LOG: [MC][re-land] Omit DWARF unwind info if compact unwind is present where eligible<br>
<br>
This reverts commit d941d597837d9e1405086f008c9bd6a71e7263c9.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D122258" rel="noreferrer" target="_blank">https://reviews.llvm.org/D122258</a><br>
<br>
Added: <br>
clang/test/Driver/femit-dwarf-unwind.c<br>
clang/test/Driver/femit-dwarf-unwind.s<br>
llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s<br>
llvm/test/MC/X86/compact-unwind-mode-dwarf.s<br>
<br>
Modified: <br>
clang/include/clang/Basic/CodeGenOptions.def<br>
clang/include/clang/Driver/Options.td<br>
clang/lib/CodeGen/BackendUtil.cpp<br>
clang/lib/Driver/ToolChains/Clang.cpp<br>
clang/tools/driver/cc1as_main.cpp<br>
llvm/include/llvm/MC/MCContext.h<br>
llvm/include/llvm/MC/MCTargetOptions.h<br>
llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h<br>
llvm/lib/CodeGen/LLVMTargetMachine.cpp<br>
llvm/lib/CodeGen/MachineModuleInfo.cpp<br>
llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp<br>
llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp<br>
llvm/lib/MC/MCContext.cpp<br>
llvm/lib/MC/MCDwarf.cpp<br>
llvm/lib/MC/MCObjectFileInfo.cpp<br>
llvm/lib/MC/MCTargetOptions.cpp<br>
llvm/lib/MC/MCTargetOptionsCommandFlags.cpp<br>
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def<br>
index d8f667dc387bb..8e89106993c26 100644<br>
--- a/clang/include/clang/Basic/CodeGenOptions.def<br>
+++ b/clang/include/clang/Basic/CodeGenOptions.def<br>
@@ -114,6 +114,10 @@ CODEGENOPT(StackSizeSection , 1, 0) ///< Set when -fstack-size-section is enabl<br>
CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is<br>
///< enabled.<br>
<br>
+///< Set when -femit-dwarf-unwind is passed.<br>
+ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,<br>
+ llvm::EmitDwarfUnwindType::Default)<br>
+<br>
///< Set when -fxray-always-emit-customevents is enabled.<br>
CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)<br>
<br>
<br>
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td<br>
index 95840760f7746..002cd6cc8cb17 100644<br>
--- a/clang/include/clang/Driver/Options.td<br>
+++ b/clang/include/clang/Driver/Options.td<br>
@@ -3044,6 +3044,13 @@ def fmacro_prefix_map_EQ<br>
defm force_dwarf_frame : BoolFOption<"force-dwarf-frame",<br>
CodeGenOpts<"ForceDwarfFrameSection">, DefaultFalse,<br>
PosFlag<SetTrue, [CC1Option], "Always emit a debug frame section">, NegFlag<SetFalse>>;<br>
+def femit_dwarf_unwind_EQ : Joined<["-"], "femit-dwarf-unwind=">,<br>
+ Group<f_Group>, Flags<[CC1Option, CC1AsOption]>,<br>
+ HelpText<"When to emit DWARF unwind (EH frame) info">,<br>
+ Values<"always,no-compact-unwind,default">,<br>
+ NormalizedValues<["Always", "NoCompactUnwind", "Default"]>,<br>
+ NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,<br>
+ MarshallingInfoEnum<CodeGenOpts<"EmitDwarfUnwind">, "Default">;<br>
def g_Flag : Flag<["-"], "g">, Group<g_Group>,<br>
HelpText<"Generate source-level debug information">;<br>
def gline_tables_only : Flag<["-"], "gline-tables-only">, Group<gN_Group>,<br>
<br>
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp<br>
index 0de15b1e48078..4b294c254e476 100644<br>
--- a/clang/lib/CodeGen/BackendUtil.cpp<br>
+++ b/clang/lib/CodeGen/BackendUtil.cpp<br>
@@ -453,6 +453,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,<br>
}<br>
<br>
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;<br>
+ Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();<br>
Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;<br>
Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;<br>
Options.MCOptions.MCUseDwarfDirectory =<br>
<br>
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp<br>
index ceac142653ebe..62e891ce38c49 100644<br>
--- a/clang/lib/Driver/ToolChains/Clang.cpp<br>
+++ b/clang/lib/Driver/ToolChains/Clang.cpp<br>
@@ -2518,6 +2518,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,<br>
DefaultIncrementalLinkerCompatible))<br>
CmdArgs.push_back("-mincremental-linker-compatible");<br>
<br>
+ Args.AddLastArg(CmdArgs, options::OPT_femit_dwarf_unwind_EQ);<br>
+<br>
// If you add more args here, also add them to the block below that<br>
// starts with "// If CollectArgsForIntegratedAssembler() isn't called below".<br>
<br>
@@ -4622,6 +4624,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,<br>
}<br>
Args.ClaimAllArgs(options::OPT_Wa_COMMA);<br>
Args.ClaimAllArgs(options::OPT_Xassembler);<br>
+ Args.ClaimAllArgs(options::OPT_femit_dwarf_unwind_EQ);<br>
}<br>
<br>
if (isa<AnalyzeJobAction>(JA)) {<br>
<br>
diff --git a/clang/test/Driver/femit-dwarf-unwind.c b/clang/test/Driver/femit-dwarf-unwind.c<br>
new file mode 100644<br>
index 0000000000000..6057c5e0e5348<br>
--- /dev/null<br>
+++ b/clang/test/Driver/femit-dwarf-unwind.c<br>
@@ -0,0 +1,14 @@<br>
+// REQUIRES: x86-registered-target<br>
+<br>
+// RUN: rm -rf %t; mkdir %t<br>
+// RUN: %clang -target x86_64-apple-macos11.0 -c %s -o %t/x86_64.o<br>
+// RUN: %clang -target x86_64-apple-macos11.0 -femit-dwarf-unwind=no-compact-unwind -c %s -o %t/x86_64-no-dwarf.o<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/x86_64.o | FileCheck %s --check-prefix=WITH-FDE<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/x86_64-no-dwarf.o | FileCheck %s --check-prefix=NO-FDE<br>
+<br>
+// WITH-FDE: FDE<br>
+// NO-FDE-NOT: FDE<br>
+<br>
+int foo() {<br>
+ return 1;<br>
+}<br>
<br>
diff --git a/clang/test/Driver/femit-dwarf-unwind.s b/clang/test/Driver/femit-dwarf-unwind.s<br>
new file mode 100644<br>
index 0000000000000..f2aa821b0cd5a<br>
--- /dev/null<br>
+++ b/clang/test/Driver/femit-dwarf-unwind.s<br>
@@ -0,0 +1,17 @@<br>
+// REQUIRES: x86-registered-target<br>
+<br>
+// RUN: rm -rf %t; mkdir %t<br>
+// RUN: %clang -target x86_64-apple-macos11.0 -c %s -o %t/x86_64.o<br>
+// RUN: %clang -target x86_64-apple-macos11.0 -femit-dwarf-unwind=no-compact-unwind -c %s -o %t/x86_64-no-dwarf.o<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/x86_64.o | FileCheck %s --check-prefix=WITH-FDE<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/x86_64-no-dwarf.o | FileCheck %s --check-prefix=NO-FDE<br>
+<br>
+// WITH-FDE: FDE<br>
+// NO-FDE-NOT: FDE<br>
+<br>
+.text<br>
+_foo:<br>
+ .cfi_startproc<br>
+ .cfi_def_cfa_offset 8<br>
+ ret<br>
+ .cfi_endproc<br>
<br>
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp<br>
index 6a11c25553ba3..264f747d6d740 100644<br>
--- a/clang/tools/driver/cc1as_main.cpp<br>
+++ b/clang/tools/driver/cc1as_main.cpp<br>
@@ -137,6 +137,9 @@ struct AssemblerInvocation {<br>
unsigned IncrementalLinkerCompatible : 1;<br>
unsigned EmbedBitcode : 1;<br>
<br>
+ /// Whether to emit DWARF unwind info.<br>
+ EmitDwarfUnwindType EmitDwarfUnwind;<br>
+<br>
/// The name of the relocation model to use.<br>
std::string RelocationModel;<br>
<br>
@@ -317,6 +320,14 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,<br>
.Default(0);<br>
}<br>
<br>
+ if (auto *A = Args.getLastArg(OPT_femit_dwarf_unwind_EQ)) {<br>
+ Opts.EmitDwarfUnwind =<br>
+ llvm::StringSwitch<EmitDwarfUnwindType>(A->getValue())<br>
+ .Case("always", EmitDwarfUnwindType::Always)<br>
+ .Case("no-compact-unwind", EmitDwarfUnwindType::NoCompactUnwind)<br>
+ .Case("default", EmitDwarfUnwindType::Default);<br>
+ }<br>
+<br>
return Success;<br>
}<br>
<br>
@@ -367,6 +378,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,<br>
assert(MRI && "Unable to create target register info!");<br>
<br>
MCTargetOptions MCOptions;<br>
+ MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind;<br>
+<br>
std::unique_ptr<MCAsmInfo> MAI(<br>
TheTarget->createMCAsmInfo(*MRI, Opts.Triple, MCOptions));<br>
assert(MAI && "Unable to create target asm info!");<br>
<br>
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h<br>
index 5b81ba31b83c5..c3a4e57fdd753 100644<br>
--- a/llvm/include/llvm/MC/MCContext.h<br>
+++ b/llvm/include/llvm/MC/MCContext.h<br>
@@ -67,6 +67,7 @@ template <typename T> class SmallVectorImpl;<br>
class SMDiagnostic;<br>
class SMLoc;<br>
class SourceMgr;<br>
+enum class EmitDwarfUnwindType;<br>
<br>
/// Context object for machine code objects. This class owns all of the<br>
/// sections that it creates.<br>
@@ -772,6 +773,7 @@ class MCContext {<br>
bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }<br>
void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }<br>
unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }<br>
+ EmitDwarfUnwindType emitDwarfUnwindInfo() const;<br>
<br>
void setGenDwarfFileNumber(unsigned FileNumber) {<br>
GenDwarfFileNumber = FileNumber;<br>
<br>
diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h<br>
index 93712a6b7d44b..9c906cdc90d02 100644<br>
--- a/llvm/include/llvm/MC/MCTargetOptions.h<br>
+++ b/llvm/include/llvm/MC/MCTargetOptions.h<br>
@@ -31,6 +31,12 @@ enum class DebugCompressionType {<br>
Z, ///< zlib style complession<br>
};<br>
<br>
+enum class EmitDwarfUnwindType {<br>
+ Always, // Always emit dwarf unwind<br>
+ NoCompactUnwind, // Only emit if compact unwind isn't available<br>
+ Default, // Default behavior is based on the target<br>
+};<br>
+<br>
class StringRef;<br>
<br>
class MCTargetOptions {<br>
@@ -56,6 +62,9 @@ class MCTargetOptions {<br>
bool PreserveAsmComments : 1;<br>
<br>
bool Dwarf64 : 1;<br>
+<br>
+ EmitDwarfUnwindType EmitDwarfUnwind;<br>
+<br>
int DwarfVersion = 0;<br>
<br>
enum DwarfDirectory {<br>
<br>
diff --git a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h<br>
index 1894841989166..d51e740177f77 100644<br>
--- a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h<br>
+++ b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h<br>
@@ -20,6 +20,7 @@<br>
namespace llvm {<br>
<br>
class MCTargetOptions;<br>
+enum class EmitDwarfUnwindType;<br>
<br>
namespace mc {<br>
<br>
@@ -32,6 +33,8 @@ int getDwarfVersion();<br>
<br>
bool getDwarf64();<br>
<br>
+EmitDwarfUnwindType getEmitDwarfUnwind();<br>
+<br>
bool getShowMCInst();<br>
<br>
bool getFatalWarnings();<br>
<br>
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp<br>
index af05dbced04e1..3192dcadb5f5e 100644<br>
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp<br>
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp<br>
@@ -264,6 +264,9 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,<br>
"Cannot emit MC with limited codegen pipeline");<br>
<br>
Ctx = &MMIWP->getMMI().getContext();<br>
+ // libunwind is unable to load compact unwind dynamically, so we must generate<br>
+ // DWARF unwind info for the JIT.<br>
+ Options.MCOptions.EmitDwarfUnwind = EmitDwarfUnwindType::Always;<br>
if (Options.MCOptions.MCSaveTempLabels)<br>
Ctx->setAllowTemporaryLabels(false);<br>
<br>
<br>
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp<br>
index 07ada255eb83d..23d55a5df9f57 100644<br>
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp<br>
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp<br>
@@ -60,7 +60,7 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)<br>
: TM(std::move(<a href="http://MMI.TM" rel="noreferrer" target="_blank">MMI.TM</a>)),<br>
Context(<a href="http://MMI.TM" target="_blank">MMI.TM</a>.getTargetTriple(), MMI.TM.getMCAsmInfo(),<br>
MMI.TM.getMCRegisterInfo(), MMI.TM.getMCSubtargetInfo(), nullptr,<br>
- nullptr, false),<br>
+ &MMI.TM.Options.MCOptions, false),<br>
MachineFunctions(std::move(MMI.MachineFunctions)) {<br>
Context.setObjectFileInfo(MMI.TM.getObjFileLowering());<br>
ObjFileMMI = MMI.ObjFileMMI;<br>
@@ -72,7 +72,7 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)<br>
MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)<br>
: TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),<br>
TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(),<br>
- nullptr, nullptr, false) {<br>
+ nullptr, &TM->Options.MCOptions, false) {<br>
Context.setObjectFileInfo(TM->getObjFileLowering());<br>
initialize();<br>
}<br>
@@ -81,7 +81,7 @@ MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM,<br>
MCContext *ExtContext)<br>
: TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),<br>
TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(),<br>
- nullptr, nullptr, false),<br>
+ nullptr, &TM->Options.MCOptions, false),<br>
ExternalContext(ExtContext) {<br>
Context.setObjectFileInfo(TM->getObjFileLowering());<br>
initialize();<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
index ed912280ac826..4ac901daa5c83 100644<br>
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
@@ -19,6 +19,7 @@<br>
#include "llvm/IR/LegacyPassManager.h"<br>
#include "llvm/IR/Mangler.h"<br>
#include "llvm/IR/Module.h"<br>
+#include "llvm/MC/MCContext.h"<br>
#include "llvm/Object/Archive.h"<br>
#include "llvm/Object/ObjectFile.h"<br>
#include "llvm/Support/DynamicLibrary.h"<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp b/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp<br>
index f342470052581..fad7428e1f906 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp<br>
@@ -12,6 +12,7 @@<br>
#include "llvm/ExecutionEngine/ObjectCache.h"<br>
#include "llvm/IR/LegacyPassManager.h"<br>
#include "llvm/IR/Module.h"<br>
+#include "llvm/MC/MCContext.h"<br>
#include "llvm/Object/ObjectFile.h"<br>
#include "llvm/Support/Error.h"<br>
#include "llvm/Support/ErrorHandling.h"<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp<br>
index 820d1dbad8f20..bc42eebf3fec9 100644<br>
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp<br>
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp<br>
@@ -95,18 +95,16 @@ void RTDyldMemoryManager::registerEHFramesInProcess(uint8_t *Addr,<br>
// and projects/libunwind/src/UnwindLevel1-gcc-ext.c.<br>
const char *P = (const char *)Addr;<br>
const char *End = P + Size;<br>
- do {<br>
+ while (P != End)<br>
P = processFDE(P, false);<br>
- } while(P != End);<br>
}<br>
<br>
void RTDyldMemoryManager::deregisterEHFramesInProcess(uint8_t *Addr,<br>
size_t Size) {<br>
const char *P = (const char *)Addr;<br>
const char *End = P + Size;<br>
- do {<br>
+ while (P != End)<br>
P = processFDE(P, true);<br>
- } while(P != End);<br>
}<br>
<br>
#else<br>
<br>
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp<br>
index 887969fcd8410..52bf48b6d242b 100644<br>
--- a/llvm/lib/MC/MCContext.cpp<br>
+++ b/llvm/lib/MC/MCContext.cpp<br>
@@ -877,6 +877,12 @@ void MCContext::RemapDebugPaths() {<br>
// Dwarf Management<br>
//===----------------------------------------------------------------------===//<br>
<br>
+EmitDwarfUnwindType MCContext::emitDwarfUnwindInfo() const {<br>
+ if (!TargetOptions)<br>
+ return EmitDwarfUnwindType::Default;<br>
+ return TargetOptions->EmitDwarfUnwind;<br>
+}<br>
+<br>
void MCContext::setGenDwarfRootFile(StringRef InputFileName, StringRef Buffer) {<br>
// MCDwarf needs the root file as well as the compilation directory.<br>
// If we find a '.file 0' directive that will supersede these values.<br>
<br>
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp<br>
index 6152b3e5210e2..d151b8b3f89a6 100644<br>
--- a/llvm/lib/MC/MCDwarf.cpp<br>
+++ b/llvm/lib/MC/MCDwarf.cpp<br>
@@ -1842,8 +1842,6 @@ template <> struct DenseMapInfo<CIEKey> {<br>
<br>
void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,<br>
bool IsEH) {<br>
- Streamer.generateCompactUnwindEncodings(MAB);<br>
-<br>
MCContext &Context = Streamer.getContext();<br>
const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();<br>
const MCAsmInfo *AsmInfo = Context.getAsmInfo();<br>
@@ -1853,6 +1851,7 @@ void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,<br>
// Emit the compact unwind info if available.<br>
bool NeedsEHFrameSection = !MOFI->getSupportsCompactUnwindWithoutEHFrame();<br>
if (IsEH && MOFI->getCompactUnwindSection()) {<br>
+ Streamer.generateCompactUnwindEncodings(MAB);<br>
bool SectionEmitted = false;<br>
for (const MCDwarfFrameInfo &Frame : FrameArray) {<br>
if (Frame.CompactUnwindEncoding == 0) continue;<br>
<br>
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp<br>
index 0d08976d98942..bb39e5aaad7f4 100644<br>
--- a/llvm/lib/MC/MCObjectFileInfo.cpp<br>
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp<br>
@@ -64,8 +64,18 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {<br>
(T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32))<br>
SupportsCompactUnwindWithoutEHFrame = true;<br>
<br>
- if (T.isWatchABI())<br>
+ switch (Ctx->emitDwarfUnwindInfo()) {<br>
+ case EmitDwarfUnwindType::Always:<br>
+ OmitDwarfIfHaveCompactUnwind = false;<br>
+ break;<br>
+ case EmitDwarfUnwindType::NoCompactUnwind:<br>
OmitDwarfIfHaveCompactUnwind = true;<br>
+ break;<br>
+ case EmitDwarfUnwindType::Default:<br>
+ OmitDwarfIfHaveCompactUnwind =<br>
+ T.isWatchABI() || SupportsCompactUnwindWithoutEHFrame;<br>
+ break;<br>
+ }<br>
<br>
FDECFIEncoding = dwarf::DW_EH_PE_pcrel;<br>
<br>
<br>
diff --git a/llvm/lib/MC/MCTargetOptions.cpp b/llvm/lib/MC/MCTargetOptions.cpp<br>
index bb48182c6622b..c2946da3ee66f 100644<br>
--- a/llvm/lib/MC/MCTargetOptions.cpp<br>
+++ b/llvm/lib/MC/MCTargetOptions.cpp<br>
@@ -17,6 +17,7 @@ MCTargetOptions::MCTargetOptions()<br>
MCSaveTempLabels(false), MCIncrementalLinkerCompatible(false),<br>
ShowMCEncoding(false), ShowMCInst(false), AsmVerbose(false),<br>
PreserveAsmComments(true), Dwarf64(false),<br>
+ EmitDwarfUnwind(EmitDwarfUnwindType::Default),<br>
MCUseDwarfDirectory(DefaultDwarfDirectory) {}<br>
<br>
StringRef MCTargetOptions::getABIName() const {<br>
<br>
diff --git a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp<br>
index 762c8d43063c7..a310dc894021f 100644<br>
--- a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp<br>
+++ b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp<br>
@@ -1,5 +1,4 @@<br>
-//===-- MCTargetOptionsCommandFlags.cpp --------------------------*- C++<br>
-//-*-===//<br>
+//===-- MCTargetOptionsCommandFlags.cpp -----------------------*- C++ //-*-===//<br>
//<br>
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
@@ -39,6 +38,7 @@ MCOPT_EXP(bool, RelaxAll)<br>
MCOPT(bool, IncrementalLinkerCompatible)<br>
MCOPT(int, DwarfVersion)<br>
MCOPT(bool, Dwarf64)<br>
+MCOPT(EmitDwarfUnwindType, EmitDwarfUnwind)<br>
MCOPT(bool, ShowMCInst)<br>
MCOPT(bool, FatalWarnings)<br>
MCOPT(bool, NoWarn)<br>
@@ -73,6 +73,19 @@ llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {<br>
cl::desc("Generate debugging info in the 64-bit DWARF format"));<br>
MCBINDOPT(Dwarf64);<br>
<br>
+ static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind(<br>
+ "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),<br>
+ cl::init(EmitDwarfUnwindType::Default),<br>
+ cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always",<br>
+ "Always emit EH frame entries"),<br>
+ clEnumValN(EmitDwarfUnwindType::NoCompactUnwind,<br>
+ "no-compact-unwind",<br>
+ "Only emit EH frame entries when compact unwind is "<br>
+ "not available"),<br>
+ clEnumValN(EmitDwarfUnwindType::Default, "default",<br>
+ "Use target platform default")));<br>
+ MCBINDOPT(EmitDwarfUnwind);<br>
+<br>
static cl::opt<bool> ShowMCInst(<br>
"asm-show-inst",<br>
cl::desc("Emit internal instruction representation to assembly file"));<br>
@@ -116,5 +129,7 @@ MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {<br>
Options.MCNoWarn = getNoWarn();<br>
Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();<br>
Options.MCNoTypeCheck = getNoTypeCheck();<br>
+ Options.EmitDwarfUnwind = getEmitDwarfUnwind();<br>
+<br>
return Options;<br>
}<br>
<br>
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp<br>
index f09c3b36ff3a8..2d92b8d5b574b 100644<br>
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp<br>
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp<br>
@@ -1377,7 +1377,7 @@ class DarwinX86AsmBackend : public X86AsmBackend {<br>
default:<br>
// Any other CFI directives indicate a frame that we aren't prepared<br>
// to represent via compact unwind, so just bail out.<br>
- return 0;<br>
+ return CU::UNWIND_MODE_DWARF;<br>
case MCCFIInstruction::OpDefCfaRegister: {<br>
// Defines a frame pointer. E.g.<br>
//<br>
@@ -1391,7 +1391,7 @@ class DarwinX86AsmBackend : public X86AsmBackend {<br>
// generate a compact unwinding representation, so bail out.<br>
if (*MRI.getLLVMRegNum(Inst.getRegister(), true) !=<br>
(Is64Bit ? X86::RBP : X86::EBP))<br>
- return 0;<br>
+ return CU::UNWIND_MODE_DWARF;<br>
<br>
// Reset the counts.<br>
memset(SavedRegs, 0, sizeof(SavedRegs));<br>
<br>
diff --git a/llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s b/llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s<br>
new file mode 100644<br>
index 0000000000000..89dc56b8aa87f<br>
--- /dev/null<br>
+++ b/llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s<br>
@@ -0,0 +1,33 @@<br>
+// RUN: rm -rf %t; mkdir %t<br>
+// RUN: llvm-mc -triple x86_64-apple-macos11.0 %s -filetype=obj -o %t/x86_64.o<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/x86_64.o | FileCheck %s --check-prefix TWO-FDES<br>
+// RUN: llvm-mc -triple arm64-apple-macos11.0 %s -filetype=obj -o %t/arm64.o<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/arm64.o | FileCheck %s --check-prefix ONE-FDE<br>
+// RUN: llvm-mc -triple x86_64-apple-macos11.0 %s -filetype=obj --emit-dwarf-unwind no-compact-unwind -o %t/x86_64-no-dwarf.o<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/x86_64-no-dwarf.o | FileCheck %s --check-prefix ONE-FDE<br>
+// RUN: llvm-mc -triple arm64-apple-macos11.0 %s -filetype=obj --emit-dwarf-unwind always -o %t/arm64-dwarf.o<br>
+// RUN: llvm-objdump --macho --dwarf=frames %t/arm64-dwarf.o | FileCheck %s --check-prefix TWO-FDES<br>
+<br>
+// TWO-FDES: FDE<br>
+// TWO-FDES: FDE<br>
+<br>
+// ONE-FDE-NOT: FDE<br>
+// ONE-FDE: FDE<br>
+// ONE-FDE-NOT: FDE<br>
+<br>
+_main:<br>
+ .cfi_startproc<br>
+ .cfi_def_cfa_offset 16<br>
+ ret<br>
+ .cfi_endproc<br>
+<br>
+_foo:<br>
+ .cfi_startproc<br>
+ .cfi_def_cfa_offset 16<br>
+ /// This encodes DW_CFA_GNU_args_size which cannot be expressed using compact<br>
+ /// unwind, so we must use DWARf unwind for this function.<br>
+ .cfi_escape 0x2e, 0x10<br>
+ ret<br>
+ .cfi_endproc<br>
+<br>
+.subsections_via_symbols<br>
<br>
diff --git a/llvm/test/MC/X86/compact-unwind-mode-dwarf.s b/llvm/test/MC/X86/compact-unwind-mode-dwarf.s<br>
new file mode 100644<br>
index 0000000000000..ca051b07b59ef<br>
--- /dev/null<br>
+++ b/llvm/test/MC/X86/compact-unwind-mode-dwarf.s<br>
@@ -0,0 +1,50 @@<br>
+// RUN: llvm-mc -triple x86_64-apple-macos10.6 -filetype=obj %s -o %t.o<br>
+// RUN: llvm-objdump --macho --unwind-info --dwarf=frames %t.o | FileCheck %s<br>
+<br>
+/// For functions whose unwind info cannot be encoded with compact unwind, make<br>
+/// sure that we encode them using DWARF unwind, and make sure we emit a compact<br>
+/// unwind entry that indicates that a DWARF encoding is being used.<br>
+<br>
+_f:<br>
+ .cfi_startproc<br>
+ ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact<br>
+ ## unwind, so we must use DWARF unwind instead.<br>
+ .cfi_escape 0x2e, 0x10<br>
+ ret<br>
+ .cfi_endproc<br>
+<br>
+_g:<br>
+ .cfi_startproc<br>
+ ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact<br>
+ ## unwind, so we must use DWARF unwind instead.<br>
+ .cfi_escape 0x2e, 0x10<br>
+ ret<br>
+ .cfi_endproc<br>
+<br>
+// CHECK: Contents of __compact_unwind section:<br>
+// CHECK: Entry at offset 0x0:<br>
+// CHECK: start: 0x[[#%x,F:]] _f<br>
+// CHECK: length: 0x1<br>
+// CHECK: compact encoding: 0x04000000<br>
+// CHECK: Entry at offset 0x20:<br>
+// CHECK: start: 0x[[#%x,G:]] _g<br>
+// CHECK: length: 0x1<br>
+// CHECK: compact encoding: 0x04000000<br>
+<br>
+// CHECK: .eh_frame contents:<br>
+// CHECK: 00000000 00000014 00000000 CIE<br>
+// CHECK: Format: DWARF32<br>
+// CHECK: Version: 1<br>
+// CHECK: Augmentation: "zR"<br>
+// CHECK: Code alignment factor: 1<br>
+// CHECK: Data alignment factor: -8<br>
+// CHECK: Return address column: 16<br>
+// CHECK: Augmentation data: 10<br>
+<br>
+// CHECK: FDE cie=00000000 pc=[[#%.8x,F]]...<br>
+// CHECK: Format: DWARF32<br>
+// CHECK: DW_CFA_GNU_args_size: +16<br>
+<br>
+// CHECK: FDE cie=00000000 pc=[[#%.8x,G]]...<br>
+// CHECK: Format: DWARF32<br>
+// CHECK: DW_CFA_GNU_args_size: +16<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote>
</div>
</div>
</body>
</html>