+/// @brief Indicates whether this relocation should hidden when listing
+/// relocations, usually because it is the trailing part of a multipart
+/// relocation that will be printed as part of the leading relocation.
+static bool getHidden(RelocationRef RelRef) {
+ const ObjectFile *Obj = RelRef.getObject();
+ auto *MachO = dyn_cast<MachOObjectFile>(Obj);
+ if (!MachO)
+ return false;
+
+ unsigned Arch = MachO->getArch();
+ DataRefImpl Rel = RelRef.getRawDataRefImpl();
+ uint64_t Type = MachO->getRelocationType(Rel);
+
+ // On arches that use the generic relocations, GENERIC_RELOC_PAIR
+ // is always hidden.
+ if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) {
+ if (Type == MachO::GENERIC_RELOC_PAIR)
+ return true;
+ } else if (Arch == Triple::x86_64) {
+ // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows
+ // an X86_64_RELOC_SUBTRACTOR.
+ if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
+ DataRefImpl RelPrev = Rel;
+ RelPrev.d.a--;
+ uint64_t PrevType = MachO->getRelocationType(RelPrev);
+ if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
+ return true;
+ }
+ }
+
+ return false;
+}
+