xref: /llvm-project/lld/MachO/Sections.cpp (revision 58f3c5e696021d9e571f868ed3bb4b27b3722df4)
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 
15 using namespace llvm;
16 using namespace llvm::MachO;
17 
18 namespace lld::macho::sections {
19 bool 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(section_names::textCoalNt, section_names::staticInit, true)
31         .Default(false);
32 
33   return false;
34 }
35 
36 } // namespace lld::macho::sections
37