diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -73,6 +73,8 @@ #include "llvm/TextAPI/Architecture.h" #include "llvm/TextAPI/InterfaceFile.h" +#include "mach-o/compact_unwind_encoding.h" + #include using namespace llvm; @@ -1069,6 +1071,11 @@ // Create pointers from symbols to their associated compact unwind entries. void ObjFile::registerCompactUnwind(Section &compactUnwindSection) { + static_assert(static_cast(UNWIND_X86_64_MODE_MASK) == + static_cast(UNWIND_X86_MODE_MASK) && + static_cast(UNWIND_ARM64_MODE_MASK) == + static_cast(UNWIND_X86_64_MODE_MASK)); + for (const Subsection &subsection : compactUnwindSection.subsections) { ConcatInputSection *isec = cast(subsection.isec); // Hack!! Each compact unwind entry (CUE) has its UNSIGNED relocations embed @@ -1096,7 +1103,8 @@ // llvm-mc omits CU entries for functions that need DWARF encoding, but // `ld -r` doesn't. We can ignore them because we will re-synthesize these // CU entries from the DWARF info during the output phase. - if ((encoding & target->modeDwarfEncoding) == target->modeDwarfEncoding) + if ((encoding & static_cast(UNWIND_MODE_MASK)) == + target->modeDwarfEncoding) continue; ConcatInputSection *referentIsec; diff --git a/lld/MachO/Target.h b/lld/MachO/Target.h --- a/lld/MachO/Target.h +++ b/lld/MachO/Target.h @@ -20,6 +20,8 @@ #include #include +#include "mach-o/compact_unwind_encoding.h" + namespace lld::macho { LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); @@ -29,6 +31,15 @@ class InputSection; class ObjFile; +static_assert(static_cast(UNWIND_X86_64_MODE_MASK) == + static_cast(UNWIND_X86_MODE_MASK) && + static_cast(UNWIND_ARM64_MODE_MASK) == + static_cast(UNWIND_X86_64_MODE_MASK)); + +// Since the mode masks have the same value on all targets, define +// a common one for convenience. +constexpr uint32_t UNWIND_MODE_MASK = UNWIND_X86_64_MODE_MASK; + class TargetInfo { public: template TargetInfo(LP) { diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -393,10 +393,9 @@ // of the unwind info's unwind address, two functions that have identical // unwind info can't be folded if it's using this encoding since both // entries need unique addresses. - static_assert(static_cast(UNWIND_X86_64_MODE_MASK) == - static_cast(UNWIND_X86_MODE_MASK)); static_assert(static_cast(UNWIND_X86_64_MODE_STACK_IND) == static_cast(UNWIND_X86_MODE_STACK_IND)); + if ((target->cpuType == CPU_TYPE_X86_64 || target->cpuType == CPU_TYPE_X86) && (encoding & UNWIND_X86_64_MODE_MASK) == UNWIND_X86_64_MODE_STACK_IND) { // FIXME: Consider passing in the two function addresses and getting