1//===- Sections.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//===----------------------------------------------------------------------===//
8
9#include "Sections.h"
10#include "InputSection.h"
11#include "OutputSegment.h"
12
13#include "llvm/ADT/StringSwitch.h"
14
15using namespace llvm;
16using namespace llvm::MachO;
17
18namespace lld::macho::sections {
19bool isCodeSection(StringRef name, StringRef segName, uint32_t flags) {
20 uint32_t type = sectionType(flags);
21 if (type != S_REGULAR && type != S_COALESCED)
22 return false;
23
24 uint32_t attr = flags & SECTION_ATTRIBUTES_USR;
25 if (attr == S_ATTR_PURE_INSTRUCTIONS)
26 return true;
27
28 if (segName == segment_names::text)
29 return StringSwitch<bool>(name)
30 .Cases(S0: section_names::textCoalNt, S1: section_names::staticInit, Value: true)
31 .Default(Value: false);
32
33 return false;
34}
35
36} // namespace lld::macho::sections
37