1//===- MCAsmInfoDarwin.cpp - Darwin asm properties ------------------------===//
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// This file defines target asm properties related what form asm statements
10// should take in general on Darwin-based targets
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/MC/MCAsmInfoDarwin.h"
15#include "llvm/BinaryFormat/MachO.h"
16#include "llvm/MC/MCDirectives.h"
17#include "llvm/MC/MCSectionMachO.h"
18#include "llvm/MC/MCTargetOptions.h"
19
20using namespace llvm;
21
22bool MCAsmInfoDarwin::isSectionAtomizableBySymbols(
23 const MCSection &Section) {
24 const MCSectionMachO &SMO = static_cast<const MCSectionMachO &>(Section);
25
26 // Sections holding 1 byte strings are atomized based on the data they
27 // contain.
28 // Sections holding 2 byte strings require symbols in order to be atomized.
29 // There is no dedicated section for 4 byte strings.
30 if (SMO.getType() == MachO::S_CSTRING_LITERALS)
31 return false;
32
33 if (SMO.getSegmentName() == "__DATA" && SMO.getName() == "__cfstring")
34 return false;
35
36 if (SMO.getSegmentName() == "__DATA" && SMO.getName() == "__objc_classrefs")
37 return false;
38
39 switch (SMO.getType()) {
40 default:
41 return true;
42
43 // These sections are atomized at the element boundaries without using
44 // symbols.
45 case MachO::S_4BYTE_LITERALS:
46 case MachO::S_8BYTE_LITERALS:
47 case MachO::S_16BYTE_LITERALS:
48 case MachO::S_LITERAL_POINTERS:
49 case MachO::S_NON_LAZY_SYMBOL_POINTERS:
50 case MachO::S_LAZY_SYMBOL_POINTERS:
51 case MachO::S_THREAD_LOCAL_VARIABLE_POINTERS:
52 case MachO::S_MOD_INIT_FUNC_POINTERS:
53 case MachO::S_MOD_TERM_FUNC_POINTERS:
54 case MachO::S_INTERPOSING:
55 return false;
56 }
57}
58
59MCAsmInfoDarwin::MCAsmInfoDarwin(const MCTargetOptions &Options)
60 : MCAsmInfo(Options) {
61 // Common settings for all Darwin targets.
62 // Syntax:
63 LinkerPrivateGlobalPrefix = "l";
64 HasSingleParameterDotFile = false;
65 HasSubsectionsViaSymbols = true;
66
67 AlignmentIsInBytes = false;
68 COMMDirectiveAlignmentIsInBytes = false;
69 LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
70 InlineAsmStart = " InlineAsm Start";
71 InlineAsmEnd = " InlineAsm End";
72
73 // Directives:
74 HasWeakDefCanBeHiddenDirective = true;
75 WeakRefDirective = "\t.weak_reference ";
76 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
77
78 HiddenVisibilityAttr = MCSA_PrivateExtern;
79 HiddenDeclarationVisibilityAttr = MCSA_Invalid;
80
81 // Doesn't support protected visibility.
82 ProtectedVisibilityAttr = MCSA_Invalid;
83
84 HasDotTypeDotSizeDirective = false;
85 HasNoDeadStrip = true;
86
87 DwarfUsesRelocationsAcrossSections = Options.MachORelocatableDwarf;
88 SetDirectiveSuppressesReloc = true;
89}
90
91bool MCAsmInfoDarwin::useCodeAlign(const MCSection &Sec) const {
92 return static_cast<const MCSectionMachO &>(Sec).hasAttribute(
93 Value: MachO::S_ATTR_PURE_INSTRUCTIONS);
94}
95