[LLD][COFF] Ignore DEBUG_S_XFGHASH_TYPE/VIRTUAL
[llvm-project.git] / lld / MachO / ObjC.cpp
blobfbc129cf658960921e1f51fe878c1a09f9ec13eb
1 //===- ObjC.cpp -----------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "ObjC.h"
10 #include "InputFiles.h"
11 #include "InputSection.h"
12 #include "OutputSegment.h"
13 #include "Target.h"
15 #include "llvm/BinaryFormat/MachO.h"
16 #include "llvm/Bitcode/BitcodeReader.h"
18 using namespace llvm;
19 using namespace llvm::MachO;
20 using namespace lld;
21 using namespace lld::macho;
23 template <class LP> static bool objectHasObjCSection(MemoryBufferRef mb) {
24 using SectionHeader = typename LP::section;
26 auto *hdr =
27 reinterpret_cast<const typename LP::mach_header *>(mb.getBufferStart());
28 if (hdr->magic != LP::magic)
29 return false;
31 if (const auto *c =
32 findCommand<typename LP::segment_command>(hdr, LP::segmentLCType)) {
33 auto sectionHeaders = ArrayRef<SectionHeader>{
34 reinterpret_cast<const SectionHeader *>(c + 1), c->nsects};
35 for (const SectionHeader &secHead : sectionHeaders) {
36 StringRef sectname(secHead.sectname,
37 strnlen(secHead.sectname, sizeof(secHead.sectname)));
38 StringRef segname(secHead.segname,
39 strnlen(secHead.segname, sizeof(secHead.segname)));
40 if ((segname == segment_names::data &&
41 sectname == section_names::objcCatList) ||
42 (segname == segment_names::text &&
43 sectname.startswith(section_names::swift))) {
44 return true;
48 return false;
51 static bool objectHasObjCSection(MemoryBufferRef mb) {
52 if (target->wordSize == 8)
53 return ::objectHasObjCSection<LP64>(mb);
54 else
55 return ::objectHasObjCSection<ILP32>(mb);
58 bool macho::hasObjCSection(MemoryBufferRef mb) {
59 switch (identify_magic(mb.getBuffer())) {
60 case file_magic::macho_object:
61 return objectHasObjCSection(mb);
62 case file_magic::bitcode:
63 return check(isBitcodeContainingObjCCategory(mb));
64 default:
65 return false;