[lld-macho][nfc] define command UNWIND_MODE_MASK for convenience and rewrite mode...
authorVy Nguyen <vyng@google.com>
Thu, 6 Oct 2022 13:08:00 +0000 (09:08 -0400)
committerVy Nguyen <vyng@google.com>
Fri, 14 Oct 2022 19:16:40 +0000 (15:16 -0400)
commita6d6734a41f4960bf7447db4515e2acfd187fea0
tree7a3ce5e8d6fa9662040a0e4e25af817339260db0
parent1fab0ac559a1eb4e74d193c772264b590ad3c317
[lld-macho][nfc] define command UNWIND_MODE_MASK for convenience and rewrite mode-mask checking logic for clarity

The previous form is currently "harmless" and happened to work but may not in the future:

Consider the struct: (for x86-64, but same issue can be said for the ARM/64 families):

```
UNWIND_X86_64_MODE_MASK                    = 0x0F000000,
UNWIND_X86_64_MODE_RBP_FRAME               = 0x01000000,
UNWIND_X86_64_MODE_STACK_IMMD              = 0x02000000,
UNWIND_X86_64_MODE_STACK_IND               = 0x03000000,
UNWIND_X86_64_MODE_DWARF                   = 0x04000000,
```

Previously, we were doing: `(encoding & MODE_DWARF) == MODE_DWARF`

As soon as a new `UNWIND_X86_64_MODE_FOO = 0x05000000` is defined, then the check above would always return true for encoding=MODE_FOO (because `(0b0101 & 0b0100) == 0b0100` )

Differential Revision: https://reviews.llvm.org/D135359
lld/MachO/InputFiles.cpp
lld/MachO/Target.h
lld/MachO/UnwindInfoSection.cpp