1*700637cbSDimitry Andric //===- Sections.cpp ---------------------------------------------------===// 2*700637cbSDimitry Andric // 3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*700637cbSDimitry Andric // 7*700637cbSDimitry Andric //===----------------------------------------------------------------------===// 8*700637cbSDimitry Andric 9*700637cbSDimitry Andric #include "Sections.h" 10*700637cbSDimitry Andric #include "InputSection.h" 11*700637cbSDimitry Andric #include "OutputSegment.h" 12*700637cbSDimitry Andric 13*700637cbSDimitry Andric #include "llvm/ADT/StringSwitch.h" 14*700637cbSDimitry Andric 15*700637cbSDimitry Andric using namespace llvm; 16*700637cbSDimitry Andric using namespace llvm::MachO; 17*700637cbSDimitry Andric 18*700637cbSDimitry Andric namespace lld::macho::sections { isCodeSection(StringRef name,StringRef segName,uint32_t flags)19*700637cbSDimitry Andricbool isCodeSection(StringRef name, StringRef segName, uint32_t flags) { 20*700637cbSDimitry Andric uint32_t type = sectionType(flags); 21*700637cbSDimitry Andric if (type != S_REGULAR && type != S_COALESCED) 22*700637cbSDimitry Andric return false; 23*700637cbSDimitry Andric 24*700637cbSDimitry Andric uint32_t attr = flags & SECTION_ATTRIBUTES_USR; 25*700637cbSDimitry Andric if (attr == S_ATTR_PURE_INSTRUCTIONS) 26*700637cbSDimitry Andric return true; 27*700637cbSDimitry Andric 28*700637cbSDimitry Andric if (segName == segment_names::text) 29*700637cbSDimitry Andric return StringSwitch<bool>(name) 30*700637cbSDimitry Andric .Cases(section_names::textCoalNt, section_names::staticInit, true) 31*700637cbSDimitry Andric .Default(false); 32*700637cbSDimitry Andric 33*700637cbSDimitry Andric return false; 34*700637cbSDimitry Andric } 35*700637cbSDimitry Andric 36*700637cbSDimitry Andric } // namespace lld::macho::sections 37