LLVM 17.0.0git
AArch64TargetStreamer.cpp
Go to the documentation of this file.
1//===- AArch64TargetStreamer.cpp - AArch64TargetStreamer class ------------===//
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 implements the AArch64TargetStreamer class.
10//
11//===----------------------------------------------------------------------===//
12
14#include "AArch64MCAsmInfo.h"
15#include "AArch64Subtarget.h"
18#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCSection.h"
23
24using namespace llvm;
25
27 "aarch64-mark-bti-property", cl::Hidden,
28 cl::desc("Add .note.gnu.property with BTI to assembly files"),
29 cl::init(false));
30
31//
32// AArch64TargetStreamer Implemenation
33//
35 : MCTargetStreamer(S), ConstantPools(new AssemblerConstantPools()) {}
36
38
39// The constant pool handling is shared by all AArch64TargetStreamer
40// implementations.
42 unsigned Size,
43 SMLoc Loc) {
44 return ConstantPools->addEntry(Streamer, Expr, Size, Loc);
45}
46
48 ConstantPools->emitForCurrentSection(Streamer);
49}
50
52 ConstantPools->emitAll(Streamer);
53}
54
55// finish() - write out any non-empty assembler constant pools and
56// write out note.gnu.properties if need.
60}
61
63 if (Flags == 0)
64 return;
65
66 MCStreamer &OutStreamer = getStreamer();
67 MCContext &Context = OutStreamer.getContext();
68 // Emit a .note.gnu.property section with the flags.
69 MCSectionELF *Nt = Context.getELFSection(".note.gnu.property", ELF::SHT_NOTE,
71 if (Nt->isRegistered()) {
72 SMLoc Loc;
73 Context.reportWarning(
74 Loc,
75 "The .note.gnu.property is not emitted because it is already present.");
76 return;
77 }
78 MCSection *Cur = OutStreamer.getCurrentSectionOnly();
79 OutStreamer.switchSection(Nt);
80
81 // Emit the note header.
82 OutStreamer.emitValueToAlignment(Align(8));
83 OutStreamer.emitIntValue(4, 4); // data size for "GNU\0"
84 OutStreamer.emitIntValue(4 * 4, 4); // Elf_Prop size
86 OutStreamer.emitBytes(StringRef("GNU", 4)); // note name
87
88 // Emit the PAC/BTI properties.
90 OutStreamer.emitIntValue(4, 4); // data size
91 OutStreamer.emitIntValue(Flags, 4); // data
92 OutStreamer.emitIntValue(0, 4); // pad
93
94 OutStreamer.endSection(Nt);
95 OutStreamer.switchSection(Cur);
96}
97
99 char Buffer[4];
100
101 // We can't just use EmitIntValue here, as that will swap the
102 // endianness on big-endian systems (instructions are always
103 // little-endian).
104 for (char &C : Buffer) {
105 C = uint8_t(Inst);
106 Inst >>= 8;
107 }
108
109 getStreamer().emitBytes(StringRef(Buffer, 4));
110}
111
114 const MCSubtargetInfo &STI) {
115 const Triple &TT = STI.getTargetTriple();
116 if (TT.isOSBinFormatELF())
117 return new AArch64TargetELFStreamer(S);
118 if (TT.isOSBinFormatCOFF())
119 return new AArch64TargetWinCOFFStreamer(S);
120 return nullptr;
121}
122
124 return new AArch64TargetStreamer(S);
125}
static cl::opt< bool > MarkBTIProperty("aarch64-mark-bti-property", cl::Hidden, cl::desc("Add .note.gnu.property with BTI to assembly files"), cl::init(false))
uint64_t Size
LLVMContext & Context
@ Flags
Definition: TextStubV5.cpp:93
void emitNoteSection(unsigned Flags)
Callback used to implement the .note.gnu.property section.
const MCExpr * addConstantPoolEntry(const MCExpr *, unsigned Size, SMLoc Loc)
Callback used to implement the ldr= pseudo.
void emitCurrentConstantPool()
Callback used to implement the .ltorg directive.
virtual void emitInst(uint32_t Inst)
Callback used to implement the .inst directive.
Context object for machine code objects.
Definition: MCContext.h:76
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:26
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
bool isRegistered() const
Definition: MCSection.h:169
Streaming machine code generation interface.
Definition: MCStreamer.h:212
MCContext & getContext() const
Definition: MCStreamer.h:297
virtual void emitValueToAlignment(Align Alignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
Definition: MCStreamer.cpp:134
MCSymbol * endSection(MCSection *Section)
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:393
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
Target specific streamer interface.
Definition: MCStreamer.h:93
MCStreamer & getStreamer()
Definition: MCStreamer.h:101
MCStreamer & Streamer
Definition: MCStreamer.h:95
Represents a location in source code.
Definition: SMLoc.h:23
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ SHF_ALLOC
Definition: ELF.h:1088
@ NT_GNU_PROPERTY_TYPE_0
Definition: ELF.h:1632
@ SHT_NOTE
Definition: ELF.h:1006
@ GNU_PROPERTY_AARCH64_FEATURE_1_BTI
Definition: ELF.h:1679
@ GNU_PROPERTY_AARCH64_FEATURE_1_AND
Definition: ELF.h:1665
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCTargetStreamer * createAArch64NullTargetStreamer(MCStreamer &S)
MCTargetStreamer * createAArch64ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39