LLVM 22.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
28 // MingW 4.5 and later support .comm with log2 alignment, but .lcomm uses byte
29 // alignment.
34 WeakRefDirective = "\t.weak\t";
35 AvoidWeakIfComdat = true;
36
37 // Doesn't support visibility:
40
41 // Set up DWARF directives
44
45 // At least MSVC inline-asm does AShr.
46 UseLogicalShr = false;
47
48 // If this is a COFF target, assume that it supports associative comdats. It's
49 // part of the spec.
51
52 // We can generate constants in comdat sections that can be shared,
53 // but in order not to create null typed symbols, we actually need to
54 // make them global symbols as well.
56}
57
58bool MCAsmInfoCOFF::useCodeAlign(const MCSection &Sec) const {
59 return Sec.isText();
60}
61
62void MCAsmInfoMicrosoft::anchor() {}
63
65
66void MCAsmInfoGNUCOFF::anchor() {}
67
69 // If this is a GNU environment (mingw or cygwin), don't use associative
70 // comdats for jump tables, unwind information, and other data associated with
71 // a function.
73
74 // We don't create constants in comdat sections for MinGW.
76}
77
79 if (COMDATSymbol || isUnique())
80 return false;
81
82 // FIXME: Does .section .bss/.data/.text work everywhere??
83 if (Name == ".text" || Name == ".data" || Name == ".bss")
84 return true;
85
86 return false;
87}
88
89void MCSectionCOFF::setSelection(int Selection) const {
90 assert(Selection != 0 && "invalid COMDAT selection type");
91 this->Selection = Selection;
92 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
93}
94
95void MCAsmInfoCOFF::printSwitchToSection(const MCSection &Section, uint32_t,
96 const Triple &T,
97 raw_ostream &OS) const {
98 auto &Sec = static_cast<const MCSectionCOFF &>(Section);
99 // standard sections don't require the '.section'
100 if (Sec.shouldOmitSectionDirective(Sec.getName())) {
101 OS << '\t' << Sec.getName() << '\n';
102 return;
103 }
104
105 OS << "\t.section\t" << Sec.getName() << ",\"";
106 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
107 OS << 'd';
108 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
109 OS << 'b';
110 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
111 OS << 'x';
112 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
113 OS << 'w';
114 else if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
115 OS << 'r';
116 else
117 OS << 'y';
118 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
119 OS << 'n';
120 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
121 OS << 's';
122 if ((Sec.getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
123 !Sec.isImplicitlyDiscardable(Sec.getName()))
124 OS << 'D';
125 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_INFO)
126 OS << 'i';
127 OS << '"';
128
129 // unique should be tail of .section directive.
130 if (Sec.isUnique() && !Sec.COMDATSymbol)
131 OS << ",unique," << Sec.UniqueID;
132
133 if (Sec.getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
134 if (Sec.COMDATSymbol)
135 OS << ",";
136 else
137 OS << "\n\t.linkonce\t";
138 switch (Sec.Selection) {
140 OS << "one_only";
141 break;
143 OS << "discard";
144 break;
146 OS << "same_size";
147 break;
149 OS << "same_contents";
150 break;
152 OS << "associative";
153 break;
155 OS << "largest";
156 break;
158 OS << "newest";
159 break;
160 default:
161 assert(false && "unsupported COFF selection type");
162 break;
163 }
164 if (Sec.COMDATSymbol) {
165 OS << ",";
166 Sec.COMDATSymbol->print(OS, this);
167 }
168 }
169
170 if (Sec.isUnique() && Sec.COMDATSymbol)
171 OS << ",unique," << Sec.UniqueID;
172
173 OS << '\n';
174}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define T
bool NeedsDwarfSectionOffsetDirective
Definition MCAsmInfo.h:265
MCSymbolAttr ProtectedVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having protected visibility.
Definition MCAsmInfo.h:350
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:334
bool UseLogicalShr
True if the integrated assembler should interpret 'a >> b' constant expressions as logical rather tha...
Definition MCAsmInfo.h:425
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition MCAsmInfo.h:298
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:325
bool HasDotTypeDotSizeDirective
True if the target has .type and .size directives, this is true for most ELF targets.
Definition MCAsmInfo.h:306
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:356
MCSymbolAttr HiddenDeclarationVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare an undefined symbol as having hidden visibili...
Definition MCAsmInfo.h:346
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition MCAsmInfo.h:310
bool COMMDirectiveAlignmentIsInBytes
True is .comm's and .lcomms optional alignment is to be specified in bytes instead of log2(n).
Definition MCAsmInfo.h:294
MCSymbolAttr HiddenVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having hidden visibility.
Definition MCAsmInfo.h:338
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:521
bool isText() const
Definition MCSection.h:591
StringRef Name
Definition MCSection.h:582
StringRef getName() const
Definition MCSection.h:590
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.