LLVM 19.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"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCSection.h"
22
23using namespace llvm;
24
26 "aarch64-mark-bti-property", cl::Hidden,
27 cl::desc("Add .note.gnu.property with BTI to assembly files"),
28 cl::init(false));
29
30//
31// AArch64TargetStreamer Implemenation
32//
34 : MCTargetStreamer(S), ConstantPools(new AssemblerConstantPools()) {}
35
37
38// The constant pool handling is shared by all AArch64TargetStreamer
39// implementations.
41 unsigned Size,
42 SMLoc Loc) {
43 return ConstantPools->addEntry(Streamer, Expr, Size, Loc);
44}
45
47 ConstantPools->emitForCurrentSection(Streamer);
48}
49
51 ConstantPools->emitAll(Streamer);
52}
53
54// finish() - write out any non-empty assembler constant pools and
55// write out note.gnu.properties if need.
59}
60
62 if (Flags == 0)
63 return;
64
65 MCStreamer &OutStreamer = getStreamer();
66 MCContext &Context = OutStreamer.getContext();
67 // Emit a .note.gnu.property section with the flags.
68 MCSectionELF *Nt = Context.getELFSection(".note.gnu.property", ELF::SHT_NOTE,
70 if (Nt->isRegistered()) {
71 SMLoc Loc;
72 Context.reportWarning(
73 Loc,
74 "The .note.gnu.property is not emitted because it is already present.");
75 return;
76 }
77 MCSection *Cur = OutStreamer.getCurrentSectionOnly();
78 OutStreamer.switchSection(Nt);
79
80 // Emit the note header.
81 OutStreamer.emitValueToAlignment(Align(8));
82 OutStreamer.emitIntValue(4, 4); // data size for "GNU\0"
83 OutStreamer.emitIntValue(4 * 4, 4); // Elf_Prop size
85 OutStreamer.emitBytes(StringRef("GNU", 4)); // note name
86
87 // Emit the PAC/BTI properties.
89 OutStreamer.emitIntValue(4, 4); // data size
90 OutStreamer.emitIntValue(Flags, 4); // data
91 OutStreamer.emitIntValue(0, 4); // pad
92
93 OutStreamer.endSection(Nt);
94 OutStreamer.switchSection(Cur);
95}
96
98 char Buffer[4];
99
100 // We can't just use EmitIntValue here, as that will swap the
101 // endianness on big-endian systems (instructions are always
102 // little-endian).
103 for (char &C : Buffer) {
104 C = uint8_t(Inst);
105 Inst >>= 8;
106 }
107
108 getStreamer().emitBytes(StringRef(Buffer, 4));
109}
110
113 const MCSubtargetInfo &STI) {
114 const Triple &TT = STI.getTargetTriple();
115 if (TT.isOSBinFormatELF())
116 return new AArch64TargetELFStreamer(S);
117 if (TT.isOSBinFormatCOFF())
118 return new AArch64TargetWinCOFFStreamer(S);
119 return nullptr;
120}
121
123 return new AArch64TargetStreamer(S);
124}
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
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:1157
@ NT_GNU_PROPERTY_TYPE_0
Definition: ELF.h:1704
@ SHT_NOTE
Definition: ELF.h:1069
@ GNU_PROPERTY_AARCH64_FEATURE_1_BTI
Definition: ELF.h:1756
@ GNU_PROPERTY_AARCH64_FEATURE_1_AND
Definition: ELF.h:1742
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:450
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