diff options
Diffstat (limited to 'lld/MachO/ObjC.cpp')
| -rw-r--r-- | lld/MachO/ObjC.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp new file mode 100644 index 000000000000..21691ef5255b --- /dev/null +++ b/lld/MachO/ObjC.cpp @@ -0,0 +1,36 @@ +//===- ObjC.cpp -----------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ObjC.h" +#include "InputFiles.h" +#include "OutputSegment.h" + +#include "llvm/BinaryFormat/MachO.h" + +using namespace llvm; +using namespace llvm::MachO; +using namespace lld; + +bool macho::hasObjCSection(MemoryBufferRef mb) { + auto *hdr = reinterpret_cast<const mach_header_64 *>(mb.getBufferStart()); + if (const load_command *cmd = findCommand(hdr, LC_SEGMENT_64)) { + auto *c = reinterpret_cast<const segment_command_64 *>(cmd); + auto sectionHeaders = ArrayRef<section_64>{ + reinterpret_cast<const section_64 *>(c + 1), c->nsects}; + for (const section_64 &sec : sectionHeaders) { + StringRef sectname(sec.sectname, + strnlen(sec.sectname, sizeof(sec.sectname))); + StringRef segname(sec.segname, strnlen(sec.segname, sizeof(sec.segname))); + if ((segname == segment_names::data && sectname == "__objc_catlist") || + (segname == segment_names::text && sectname == "__swift")) { + return true; + } + } + } + return false; +} |
