2020-08-19 05:37:04 +08:00
|
|
|
//===- 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"
|
2021-04-28 03:22:44 +08:00
|
|
|
#include "InputSection.h"
|
2020-08-19 05:37:04 +08:00
|
|
|
#include "OutputSegment.h"
|
2021-04-03 06:46:18 +08:00
|
|
|
#include "Target.h"
|
2020-08-19 05:37:04 +08:00
|
|
|
|
|
|
|
#include "llvm/BinaryFormat/MachO.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::MachO;
|
|
|
|
using namespace lld;
|
2021-04-03 06:46:18 +08:00
|
|
|
using namespace lld::macho;
|
2020-08-19 05:37:04 +08:00
|
|
|
|
2021-04-03 06:46:18 +08:00
|
|
|
template <class LP> static bool hasObjCSection(MemoryBufferRef mb) {
|
|
|
|
using Section = typename LP::section;
|
|
|
|
|
|
|
|
auto *hdr =
|
|
|
|
reinterpret_cast<const typename LP::mach_header *>(mb.getBufferStart());
|
2021-05-04 06:31:23 +08:00
|
|
|
if (hdr->magic != LP::magic)
|
|
|
|
return false;
|
|
|
|
|
2021-04-21 23:18:20 +08:00
|
|
|
if (const auto *c =
|
|
|
|
findCommand<typename LP::segment_command>(hdr, LP::segmentLCType)) {
|
2021-04-03 06:46:18 +08:00
|
|
|
auto sectionHeaders =
|
|
|
|
ArrayRef<Section>{reinterpret_cast<const Section *>(c + 1), c->nsects};
|
|
|
|
for (const Section &sec : sectionHeaders) {
|
2020-08-19 05:37:04 +08:00
|
|
|
StringRef sectname(sec.sectname,
|
|
|
|
strnlen(sec.sectname, sizeof(sec.sectname)));
|
|
|
|
StringRef segname(sec.segname, strnlen(sec.segname, sizeof(sec.segname)));
|
2021-04-28 03:22:44 +08:00
|
|
|
if ((segname == segment_names::data &&
|
|
|
|
sectname == section_names::objcCatList) ||
|
|
|
|
(segname == segment_names::text &&
|
|
|
|
sectname == section_names::swift)) {
|
2020-08-19 05:37:04 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-03 06:46:18 +08:00
|
|
|
|
|
|
|
bool macho::hasObjCSection(MemoryBufferRef mb) {
|
|
|
|
if (target->wordSize == 8)
|
|
|
|
return ::hasObjCSection<LP64>(mb);
|
|
|
|
else
|
|
|
|
return ::hasObjCSection<ILP32>(mb);
|
|
|
|
}
|