56 bool DWARFMustBeAtTheEnd;
57 bool CreatedADWARFSection;
67 void emitDataRegionEnd();
71 std::unique_ptr<MCObjectWriter> OW,
72 std::unique_ptr<MCCodeEmitter> Emitter,
73 bool DWARFMustBeAtTheEnd,
bool label)
76 LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
77 CreatedADWARFSection(
false) {}
80 void reset()
override {
81 CreatedADWARFSection =
false;
82 HasSectionLabel.
clear();
98 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
100 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
101 unsigned Minor,
unsigned Update,
103 void emitThumbFunc(
MCSymbol *Func)
override;
105 void emitSymbolDesc(
MCSymbol *
Symbol,
unsigned DescValue)
override;
117 void emitIdent(
StringRef IdentString)
override {
122 getAssembler().getLOHContainer().addDirective(
Kind,
Args);
127 getAssembler().CGProfile.push_back({
From, To, Count});
130 void finishImpl()
override;
133 void finalizeCGProfile();
134 void createAddrSigSection();
145 if (SegName ==
"__LD" && SecName ==
"__compact_unwind")
148 if (SegName ==
"__IMPORT") {
149 if (SecName ==
"__jump_table")
152 if (SecName ==
"__pointers")
156 if (SegName ==
"__TEXT" && SecName ==
"__eh_frame")
159 if (SegName ==
"__DATA" && (SecName ==
"__nl_symbol_ptr" ||
160 SecName ==
"__thread_ptr"))
162 if (SegName ==
"__LLVM" && SecName ==
"__cg_profile")
167 void MCMachOStreamer::changeSection(
MCSection *Section,
168 const MCExpr *Subsection) {
170 bool Created = changeSectionImpl(Section, Subsection);
173 if (SegName ==
"__DWARF")
174 CreatedADWARFSection =
true;
176 assert((!CreatedADWARFSection ||
177 Section == getContext().getObjectFileInfo()->getStackMapSection())
178 &&
"Creating regular section after DWARF");
182 if (LabelSections && !HasSectionLabel[Section] &&
184 MCSymbol *
Label = getContext().createLinkerPrivateTempSymbol();
185 Section->setBeginSymbol(Label);
186 HasSectionLabel[
Section] =
true;
192 getAssembler().registerSymbol(*
Symbol);
195 if (cast<MCSymbolMachO>(
Symbol)->isWeakDefinition())
197 if (
Symbol->isPrivateExtern())
204 if (getAssembler().isSymbolLinkerVisible(*
Symbol))
216 cast<MCSymbolMachO>(
Symbol)->clearReferenceType();
222 if (
Value->evaluateAsRelocatable(Res,
nullptr,
nullptr)) {
224 const MCSymbol &SymA = SymAExpr->getSymbol();
226 cast<MCSymbolMachO>(
Symbol)->setAltEntry();
234 MCSymbol *Start = getContext().createTempSymbol();
238 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
239 Regions.push_back(
Data);
242 void MCMachOStreamer::emitDataRegionEnd() {
243 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
244 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
246 assert(!
Data.End &&
"Mismatched .end_data_region!");
248 Data.End = getContext().createTempSymbol();
254 getAssembler().getBackend().handleAssemblerFlag(
Flag);
262 getAssembler().setSubsectionsViaSymbols(
true);
268 getAssembler().getLinkerOptions().push_back(
Options);
292 unsigned Minor,
unsigned Update,
294 getAssembler().setVersionMin(
Kind, Major, Minor, Update, SDKVersion);
297 void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
298 unsigned Minor,
unsigned Update,
304 void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
305 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
307 getAssembler().setDarwinTargetVariantBuildVersion(
314 getAssembler().setIsThumbFunc(
Symbol);
315 cast<MCSymbolMachO>(
Symbol)->setThumbFunc();
318 bool MCMachOStreamer::emitSymbolAttribute(
MCSymbol *Sym,
329 ISD.
Section = getCurrentSectionOnly();
330 getAssembler().getIndirectSymbols().push_back(ISD);
337 getAssembler().registerSymbol(*
Symbol);
366 Symbol->setExternal(
true);
373 Symbol->setReferenceTypeUndefinedLazy(
false);
379 if (
Symbol->isUndefined())
380 Symbol->setReferenceTypeUndefinedLazy(
true);
391 Symbol->setSymbolResolver();
399 Symbol->setExternal(
true);
400 Symbol->setPrivateExtern(
true);
405 if (
Symbol->isUndefined())
406 Symbol->setWeakReference();
412 Symbol->setWeakDefinition();
416 Symbol->setWeakDefinition();
417 Symbol->setWeakReference();
428 void MCMachOStreamer::emitSymbolDesc(
MCSymbol *
Symbol,
unsigned DescValue) {
430 getAssembler().registerSymbol(*
Symbol);
431 cast<MCSymbolMachO>(
Symbol)->setDesc(DescValue);
437 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
439 getAssembler().registerSymbol(*
Symbol);
440 Symbol->setExternal(
true);
447 return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
457 if (!
Section->isVirtualSection()) {
458 getContext().reportError(
459 Loc,
"The usage of .zerofill is restricted to sections of "
460 "ZEROFILL type. Use .zero or .space instead.");
466 SwitchSection(Section);
484 void MCMachOStreamer::emitInstToData(
const MCInst &Inst,
491 getAssembler().getEmitter().encodeInstruction(Inst, VecOS,
Fixups, STI);
495 Fixup.setOffset(
Fixup.getOffset() +
DF->getContents().size());
496 DF->getFixups().push_back(Fixup);
498 DF->setHasInstructions(STI);
499 DF->getContents().append(
Code.begin(),
Code.end());
502 void MCMachOStreamer::finishImpl() {
503 emitFrames(&getAssembler().getBackend());
512 if (getAssembler().isSymbolLinkerVisible(
Symbol) &&
Symbol.isInSection() &&
516 "Invalid offset in atom defining symbol!");
524 const MCSymbol *CurrentAtom =
nullptr;
528 Frag.setAtom(CurrentAtom);
534 createAddrSigSection();
538 void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
541 getAssembler().registerSymbol(*
S, &Created);
543 S->setExternal(
true);
546 void MCMachOStreamer::finalizeCGProfile() {
548 if (
Asm.CGProfile.empty())
551 finalizeCGProfileEntry(
E.From);
552 finalizeCGProfileEntry(
E.To);
557 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
559 Asm.registerSection(*CGProfileSection);
562 size_t SectionBytes =
564 Frag->getContents().resize(SectionBytes);
568 std::unique_ptr<MCAsmBackend> &&MAB,
569 std::unique_ptr<MCObjectWriter> &&OW,
570 std::unique_ptr<MCCodeEmitter> &&CE,
571 bool RelaxAll,
bool DWARFMustBeAtTheEnd,
572 bool LabelSections) {
575 DWARFMustBeAtTheEnd, LabelSections);
577 S->emitVersionForTarget(
579 Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
580 Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
582 S->getAssembler().setRelaxAll(
true);
588 void MCMachOStreamer::createAddrSigSection() {
591 if (!
writer.getEmitAddrsigSection())
594 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
595 Asm.registerSection(*AddrSigSection);