diff --git a/llvm/include/llvm/MC/MCAsmBackend.h b/llvm/include/llvm/MC/MCAsmBackend.h --- a/llvm/include/llvm/MC/MCAsmBackend.h +++ b/llvm/include/llvm/MC/MCAsmBackend.h @@ -25,7 +25,7 @@ class MCSymbol; class MCAsmLayout; class MCAssembler; -class MCCFIInstruction; +class MCDwarfFrameInfo; struct MCFixupKindInfo; class MCInst; class MCObjectStreamer; @@ -211,7 +211,7 @@ /// Generate the compact unwind encoding for the CFI instructions. virtual uint32_t - generateCompactUnwindEncoding(ArrayRef) const { + generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI) const { return 0; } @@ -219,6 +219,8 @@ virtual bool isMicroMips(const MCSymbol *Sym) const { return false; } + + bool isDarwinCanonicalPersonality(const MCSymbol *Sym) const; }; } // end namespace llvm diff --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp --- a/llvm/lib/MC/MCAsmBackend.cpp +++ b/llvm/lib/MC/MCAsmBackend.cpp @@ -115,3 +115,12 @@ return true; return fixupNeedsRelaxation(Fixup, Value, DF, Layout); } + +bool MCAsmBackend::isDarwinCanonicalPersonality(const MCSymbol *Sym) const { + if (Sym && Sym->isMachO()) { + StringRef name = Sym->getName(); + return name.compare("__gxx_personality_v0,") == 0 || + name.compare("__objc_personality_v0") == 0; + } + return false; +} diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -126,7 +126,7 @@ void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) { for (auto &FI : DwarfFrameInfos) FI.CompactUnwindEncoding = - (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0); + (MAB ? MAB->generateCompactUnwindEncoding(&FI) : 0); } /// EmitIntValue - Special case of EmitValue that avoids the client having to diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp @@ -564,8 +564,11 @@ } /// Generate the compact unwind encoding from the CFI directives. - uint32_t generateCompactUnwindEncoding( - ArrayRef Instrs) const override { + uint32_t + generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI) const override { + if (!isDarwinCanonicalPersonality(FI->Personality)) + return 0; + ArrayRef Instrs = FI->Instructions; if (Instrs.empty()) return CU::UNWIND_ARM64_MODE_FRAMELESS; diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -1109,7 +1109,8 @@ /// encoded in compact unwind, the method returns UNWIND_ARM_MODE_DWARF which /// tells the runtime to fallback and unwind using dwarf. uint32_t ARMAsmBackendDarwin::generateCompactUnwindEncoding( - ArrayRef Instrs) const { + const MCDwarfFrameInfo *FI) const { + ArrayRef Instrs = FI->Instructions; DEBUG_WITH_TYPE("compact-unwind", llvm::dbgs() << "generateCU()\n"); // Only armv7k uses CFI based unwinding. if (Subtype != MachO::CPU_SUBTYPE_ARM_V7K) @@ -1117,6 +1118,9 @@ // No .cfi directives means no frame. if (Instrs.empty()) return 0; + if (!isDarwinCanonicalPersonality(FI->Personality)) + return 0; + // Start off assuming CFA is at SP+0. unsigned CFARegister = ARM::SP; int CFARegisterOffset = 0; diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendDarwin.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendDarwin.h --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendDarwin.h +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendDarwin.h @@ -32,8 +32,8 @@ /*Is64Bit=*/false, cantFail(MachO::getCPUType(TT)), Subtype); } - uint32_t generateCompactUnwindEncoding( - ArrayRef Instrs) const override; + uint32_t + generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI) const override; }; } // end namespace llvm diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -1353,8 +1353,11 @@ /// Implementation of algorithm to generate the compact unwind encoding /// for the CFI instructions. uint32_t - generateCompactUnwindEncoding(ArrayRef Instrs) const override { + generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI) const override { + ArrayRef Instrs = FI->Instructions; if (Instrs.empty()) return 0; + if (!isDarwinCanonicalPersonality(FI->Personality)) + return 0; // Reset the saved registers. unsigned SavedRegIdx = 0;