LLVM: lib/MC/MCSectionMachO.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

12

13namespace llvm {

18}

19

20using namespace llvm;

21

22

23

24

25static constexpr struct {

39 StringLiteral("S_NON_LAZY_SYMBOL_POINTERS")},

44 StringLiteral("S_MOD_INIT_FUNC_POINTERS")},

46 StringLiteral("S_MOD_TERM_FUNC_POINTERS")},

54 StringLiteral("S_LAZY_DYLIB_SYMBOL_POINTERS")},

58 StringLiteral("S_THREAD_LOCAL_ZEROFILL")},

60 StringLiteral("S_THREAD_LOCAL_VARIABLES")},

62 StringLiteral("S_THREAD_LOCAL_VARIABLE_POINTERS")},

63 {StringLiteral("thread_local_init_function_pointers"),

64 StringLiteral("S_THREAD_LOCAL_INIT_FUNCTION_POINTERS")},

68

69

70

71

72static constexpr struct {

76#define ENTRY(ASMNAME, ENUM) \

77 { MachO::ENUM, StringLiteral(ASMNAME), StringLiteral(#ENUM) },

88#undef ENTRY

89 { 0, StringLiteral("none"), StringLiteral("") },

91

93 unsigned TAA, unsigned reserved2, SectionKind K,

97 TypeAndAttributes(TAA), Reserved2(reserved2) {

99 "Segment or section string too long");

100 for (unsigned i = 0; i != 16; ++i) {

101 if (i < Segment.size())

102 SegmentName[i] = Segment[i];

103 else

104 SegmentName[i] = 0;

105 }

106}

107

112

113

115 if (TAA == 0) {

116 OS << '\n';

117 return;

118 }

119

122 "Invalid SectionType specified!");

123

125 OS << ',';

127 } else {

128

129 OS << '\n';

130 return;

131 }

132

133

135 if (SectionAttrs == 0) {

136

137

138 if (Reserved2 != 0)

139 OS << ",none," << Reserved2;

140 OS << '\n';

141 return;

142 }

143

144

145 char Separator = ',';

146 for (unsigned i = 0;

148 ++i) {

149

151 continue;

152

153

154 SectionAttrs &= ~SectionAttrDescriptors[i].AttrFlag;

155

156 OS << Separator;

159 else

161 Separator = '+';

162 }

163

164 assert(SectionAttrs == 0 && "Unknown section attributes!");

165

166

167 if (Reserved2 != 0)

168 OS << ',' << Reserved2;

169 OS << '\n';

170}

171

174}

175

176

177

178

179

180

184 unsigned &TAA,

185 bool &TAAParsed,

186 unsigned &StubSize) {

187 TAAParsed = false;

188

190 Spec.split(SplitSpec, ',');

191

192 auto GetEmptyOrTrim = [&SplitSpec](size_t Idx) -> StringRef {

194 };

195 Segment = GetEmptyOrTrim(0);

196 Section = GetEmptyOrTrim(1);

197 StringRef SectionType = GetEmptyOrTrim(2);

198 StringRef Attrs = GetEmptyOrTrim(3);

199 StringRef StubSizeStr = GetEmptyOrTrim(4);

200

201

202 if (Section.empty())

204 "mach-o section specifier requires a segment "

205 "and section separated by a comma");

206

207

208 if (Section.size() > 16)

210 "mach-o section specifier requires a section "

211 "whose length is between 1 and 16 characters");

212

213

214 TAA = 0;

215 StubSize = 0;

216 if (SectionType.empty())

218

219

220 auto TypeDescriptor =

223 return SectionType == Descriptor.AssemblerName;

224 });

225

226

229 "mach-o section specifier uses an unknown "

230 "section type");

231

232

234 TAAParsed = true;

235

236

237 if (Attrs.empty()) {

238

241 "mach-o section specifier of type "

242 "'symbol_stubs' requires a size specifier");

244 }

245

246

248 Attrs.split(SectionAttrs, '+', -1, false);

249

250 for (StringRef &SectionAttr : SectionAttrs) {

251 auto AttrDescriptorI =

254 return SectionAttr.trim() == Descriptor.AssemblerName;

255 });

258 "mach-o section specifier has invalid "

259 "attribute");

260

261 TAA |= AttrDescriptorI->AttrFlag;

262 }

263

264

265 if (StubSizeStr.empty()) {

266

269 "mach-o section specifier of type "

270 "'symbol_stubs' requires a size specifier");

272 }

273

274

277 "mach-o section specifier cannot have a stub "

278 "size specified because it does not have type "

279 "'symbol_stubs'");

280

281

284 "mach-o section specifier has a malformed "

285 "stub size");

286

288}

289

292 if (L->Tail)

293 Atoms.resize(L->Tail->getLayoutOrder() + 1);

294}

295

297 return I < Atoms.size() ? Atoms[I] : nullptr;

298}

299

Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx

static constexpr struct @511 SectionAttrDescriptors[]

SectionAttrDescriptors - This is an array of descriptors for section attributes.

static constexpr struct @510 SectionTypeDescriptors[MachO::LAST_KNOWN_SECTION_TYPE+1]

SectionTypeDescriptors - These are strings that describe the various section types.

#define ENTRY(ASMNAME, ENUM)

StringLiteral AssemblerName

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

This class is intended to be used as a base class for asm properties and features specific to the tar...

Base class for the full range of assembler expressions which are needed for parsing.

static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)

Parse the section specifier indicated by "Spec".

MachO::SectionType getType() const

void setAtom(size_t I, const MCSymbol *Sym)

StringRef getSegmentName() const

const MCSymbol * getAtom(size_t I) const

bool useCodeAlign() const override

Return true if a .align directive should use "optimized nops" to fill instead of 0s.

unsigned getTypeAndAttributes() const

bool hasAttribute(unsigned Value) const

void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, uint32_t Subsection) const override

Instances of this class represent a uniqued identifier for a section in the current translation unit.

StringRef getName() const

FragList * curFragList() const

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

SectionKind - This is a simple POD value that classifies the properties of a section.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...

StringRef - Represent a constant reference to a string, i.e.

bool getAsInteger(unsigned Radix, T &Result) const

Parse the current string as an integer of the specified radix.

constexpr bool empty() const

empty - Check if the string is empty.

constexpr size_t size() const

size - Get the string size.

Triple - Helper class for working with autoconf configuration names.

This class implements an extremely fast bulk output stream that can only output to a stream.

@ S_ATTR_SOME_INSTRUCTIONS

S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.

@ S_ATTR_EXT_RELOC

S_ATTR_EXT_RELOC - Section has external relocation entries.

@ S_ATTR_DEBUG

S_ATTR_DEBUG - A debug section.

@ S_ATTR_NO_DEAD_STRIP

S_ATTR_NO_DEAD_STRIP - No dead stripping.

@ S_ATTR_LOC_RELOC

S_ATTR_LOC_RELOC - Section has local relocation entries.

@ S_ATTR_NO_TOC

S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents.

@ S_ATTR_LIVE_SUPPORT

S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.

@ S_ATTR_PURE_INSTRUCTIONS

S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.

@ S_ATTR_SELF_MODIFYING_CODE

S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.

@ S_ATTR_STRIP_STATIC_SYMS

S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...

bool isVirtualSection(uint8_t type)

SectionType

These are the section type and attributes fields.

@ LAST_KNOWN_SECTION_TYPE

@ S_SYMBOL_STUBS

S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.

This is an optimization pass for GlobalISel generic memory operations.

std::error_code inconvertibleErrorCode()

The value returned by this function can be returned from convertToErrorCode for Error values where no...

Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)

Create formatted StringError object.

auto find_if(R &&Range, UnaryPredicate P)

Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.