LLVM 23.0.0git
MCAsmInfoCOFF.cpp
Go to the documentation of this file.
1//===- MCAsmInfoCOFF.cpp - COFF 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 COFF-based targets
11//
12//===----------------------------------------------------------------------===//
13
17#include "llvm/MC/MCSection.h"
19#include "llvm/MC/MCSymbol.h"
21#include <cassert>
22
23using namespace llvm;
24
25void MCAsmInfoCOFF::anchor() {}
26
29 // MingW 4.5 and later support .comm with log2 alignment, but .lcomm uses byte
30 // alignment.
35 WeakRefDirective = "\t.weak\t";
36 AvoidWeakIfComdat = true;
37
38 // Doesn't support visibility:
41
42 // Set up DWARF directives
45
46 // At least MSVC inline-asm does AShr.
47 UseLogicalShr = false;
48
49 // If this is a COFF target, assume that it supports associative comdats. It's
50 // part of the spec.
52
53 // We can generate constants in comdat sections that can be shared,
54 // but in order not to create null typed symbols, we actually need to
55 // make them global symbols as well.
57}
58
59bool MCAsmInfoCOFF::useCodeAlign(const MCSection &Sec) const {
60 return Sec.isText();
61}
62
63void MCAsmInfoMicrosoft::anchor() {}
64
67
68void MCAsmInfoGNUCOFF::anchor() {}
69
72 // If this is a GNU environment (mingw or cygwin), don't use associative
73 // comdats for jump tables, unwind information, and other data associated with
74 // a function.
76
77 // We don't create constants in comdat sections for MinGW.
79}
80
82 if (COMDATSymbol || isUnique())
83 return false;
84
85 // FIXME: Does .section .bss/.data/.text work everywhere??
86 if (Name == ".text" || Name == ".data" || Name == ".bss")
87 return true;
88
89 return false;
90}
91
92void MCSectionCOFF::setSelection(int Selection) const {
93 assert(Selection != 0 && "invalid COMDAT selection type");
94 this->Selection = Selection;
95 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
96}
97
98void MCAsmInfoCOFF::printSwitchToSection(const MCSection &Section, uint32_t,
99 const Triple &T,
100 raw_ostream &OS) const {
101 auto &Sec = static_cast<const MCSectionCOFF &>(Section);
102 // standard sections don't require the '.section'
103 if (Sec.shouldOmitSectionDirective(Sec.getName())) {
104 OS << '\t' << Sec.getName() << '\n';
105 return;
106 }
107
108 OS << "\t.section\t" << Sec.getName() << ",\"";
109 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
110 OS << 'd';
111 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
112 OS << 'b';
113 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
114 OS << 'x';
115 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
116 OS << 'w';
117 else if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
118 OS << 'r';
119 else
120 OS << 'y';
121 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
122 OS << 'n';
123 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
124 OS << 's';
125 if ((Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
126 !Sec.isImplicitlyDiscardable(Sec.getName()))
127 OS << 'D';
128 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_INFO)
129 OS << 'i';
130 OS << '"';
131
132 // unique should be tail of .section directive.
133 if (Sec.isUnique() && !Sec.COMDATSymbol)
134 OS << ",unique," << Sec.UniqueID;
135
136 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
137 if (Sec.COMDATSymbol)
138 OS << ",";
139 else
140 OS << "\n\t.linkonce\t";
141 switch (Sec.Selection) {
143 OS << "one_only";
144 break;
146 OS << "discard";
147 break;
149 OS << "same_size";
150 break;
152 OS << "same_contents";
153 break;
155 OS << "associative";
156 break;
158 OS << "largest";
159 break;
161 OS << "newest";
162 break;
163 default:
164 assert(false && "unsupported COFF selection type");
165 break;
166 }
167 if (Sec.COMDATSymbol) {
168 OS << ",";
169 Sec.COMDATSymbol->print(OS, this);
170 }
171 }
172
173 if (Sec.isUnique() && Sec.COMDATSymbol)
174 OS << ",unique," << Sec.UniqueID;
175
176 OS << '\n';
177}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static LVOptions Options
Definition LVOptions.cpp:25
#define T
MCAsmInfoCOFF(const MCTargetOptions &Options)
MCAsmInfoGNUCOFF(const MCTargetOptions &Options)
MCAsmInfoMicrosoft(const MCTargetOptions &Options)
bool NeedsDwarfSectionOffsetDirective
Definition MCAsmInfo.h:264
MCSymbolAttr ProtectedVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having protected visibility.
Definition MCAsmInfo.h:352
bool AvoidWeakIfComdat
True if we should mark symbols as global instead of weak, for weak*‍/linkonce*, if the symbol has a c...
Definition MCAsmInfo.h:336
MCAsmInfo(const MCTargetOptions &Options)
Definition MCAsmInfo.cpp:44
bool UseLogicalShr
True if the integrated assembler should interpret 'a >> b' constant expressions as logical rather tha...
Definition MCAsmInfo.h:427
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition MCAsmInfo.h:297
bool HasCOFFComdatConstants
True if this is a non-GNU COFF target.
Definition MCAsmInfo.h:110
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:327
bool HasDotTypeDotSizeDirective
True if the target has .type and .size directives, this is true for most ELF targets.
Definition MCAsmInfo.h:308
bool HasCOFFAssociativeComdats
True if this is a non-GNU COFF target.
Definition MCAsmInfo.h:106
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:358
MCSymbolAttr HiddenDeclarationVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare an undefined symbol as having hidden visibili...
Definition MCAsmInfo.h:348
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition MCAsmInfo.h:312
bool COMMDirectiveAlignmentIsInBytes
True is .comm's and .lcomms optional alignment is to be specified in bytes instead of log2(n).
Definition MCAsmInfo.h:293
MCSymbolAttr HiddenVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having hidden visibility.
Definition MCAsmInfo.h:340
This represents a section on Windows.
bool shouldOmitSectionDirective(StringRef Name) const
Decides whether a '.section' directive should be printed before the section name.
bool isUnique() const
void setSelection(int Selection) const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:573
bool isText() const
Definition MCSection.h:644
StringRef Name
Definition MCSection.h:635
StringRef getName() const
Definition MCSection.h:643
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ IMAGE_SCN_MEM_SHARED
Definition COFF.h:334
@ IMAGE_SCN_LNK_REMOVE
Definition COFF.h:308
@ IMAGE_SCN_MEM_READ
Definition COFF.h:336
@ IMAGE_SCN_MEM_EXECUTE
Definition COFF.h:335
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition COFF.h:305
@ IMAGE_SCN_MEM_DISCARDABLE
Definition COFF.h:331
@ IMAGE_SCN_LNK_INFO
Definition COFF.h:307
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition COFF.h:304
@ IMAGE_SCN_LNK_COMDAT
Definition COFF.h:309
@ IMAGE_SCN_MEM_WRITE
Definition COFF.h:337
@ IMAGE_COMDAT_SELECT_NODUPLICATES
Definition COFF.h:455
@ IMAGE_COMDAT_SELECT_LARGEST
Definition COFF.h:460
@ IMAGE_COMDAT_SELECT_NEWEST
Definition COFF.h:461
@ IMAGE_COMDAT_SELECT_SAME_SIZE
Definition COFF.h:457
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition COFF.h:459
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
Definition COFF.h:458
@ IMAGE_COMDAT_SELECT_ANY
Definition COFF.h:456
This is an optimization pass for GlobalISel generic memory operations.
@ MCSA_Invalid
Not a valid directive.