LLVM 20.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 uint64_t PAuthABIPlatform,
63 uint64_t PAuthABIVersion) {
64 assert((PAuthABIPlatform == uint64_t(-1)) ==
65 (PAuthABIVersion == uint64_t(-1)));
66 uint64_t DescSz = 0;
67 if (Flags != 0)
68 DescSz += 4 * 4;
69 if (PAuthABIPlatform != uint64_t(-1))
70 DescSz += 4 + 4 + 8 * 2;
71 if (DescSz == 0)
72 return;
73
74 MCStreamer &OutStreamer = getStreamer();
75 MCContext &Context = OutStreamer.getContext();
76 // Emit a .note.gnu.property section with the flags.
77 MCSectionELF *Nt = Context.getELFSection(".note.gnu.property", ELF::SHT_NOTE,
79 if (Nt->isRegistered()) {
80 SMLoc Loc;
81 Context.reportWarning(
82 Loc,
83 "The .note.gnu.property is not emitted because it is already present.");
84 return;
85 }
86 MCSection *Cur = OutStreamer.getCurrentSectionOnly();
87 OutStreamer.switchSection(Nt);
88
89 // Emit the note header.
90 OutStreamer.emitValueToAlignment(Align(8));
91 OutStreamer.emitIntValue(4, 4); // data size for "GNU\0"
92 OutStreamer.emitIntValue(DescSz, 4); // Elf_Prop array size
94 OutStreamer.emitBytes(StringRef("GNU", 4)); // note name
95
96 // Emit the PAC/BTI properties.
97 if (Flags != 0) {
99 OutStreamer.emitIntValue(4, 4); // data size
100 OutStreamer.emitIntValue(Flags, 4); // data
101 OutStreamer.emitIntValue(0, 4); // pad
102 }
103
104 // Emit the PAuth ABI compatibility info
105 if (PAuthABIPlatform != uint64_t(-1)) {
107 OutStreamer.emitIntValue(8 * 2, 4); // data size
108 OutStreamer.emitIntValue(PAuthABIPlatform, 8);
109 OutStreamer.emitIntValue(PAuthABIVersion, 8);
110 }
111
112 OutStreamer.endSection(Nt);
113 OutStreamer.switchSection(Cur);
114}
115
117 char Buffer[4];
118
119 // We can't just use EmitIntValue here, as that will swap the
120 // endianness on big-endian systems (instructions are always
121 // little-endian).
122 for (char &C : Buffer) {
123 C = uint8_t(Inst);
124 Inst >>= 8;
125 }
126
127 getStreamer().emitBytes(StringRef(Buffer, 4));
128}
129
132 const MCSubtargetInfo &STI) {
133 const Triple &TT = STI.getTargetTriple();
134 if (TT.isOSBinFormatELF())
135 return new AArch64TargetELFStreamer(S);
136 if (TT.isOSBinFormatCOFF())
137 return new AArch64TargetWinCOFFStreamer(S);
138 return nullptr;
139}
140
142 return new AArch64TargetStreamer(S);
143}
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * addConstantPoolEntry(const MCExpr *, unsigned Size, SMLoc Loc)
Callback used to implement the ldr= pseudo.
void emitNoteSection(unsigned Flags, uint64_t PAuthABIPlatform=-1, uint64_t PAuthABIVersion=-1)
Callback used to implement the .note.gnu.property section.
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:83
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:551
void reportWarning(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1075
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
bool isRegistered() const
Definition: MCSection.h:175
Streaming machine code generation interface.
Definition: MCStreamer.h:213
MCContext & getContext() const
Definition: MCStreamer.h:300
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:133
MCSymbol * endSection(MCSection *Section)
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:398
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:94
MCStreamer & getStreamer()
Definition: MCStreamer.h:102
MCStreamer & Streamer
Definition: MCStreamer.h:96
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
@ NT_GNU_PROPERTY_TYPE_0
Definition: ELF.h:1742
@ GNU_PROPERTY_AARCH64_FEATURE_PAUTH
Definition: ELF.h:1776
@ GNU_PROPERTY_AARCH64_FEATURE_1_AND
Definition: ELF.h:1775
@ GNU_PROPERTY_AARCH64_FEATURE_1_BTI
Definition: ELF.h:1790
@ SHT_NOTE
Definition: ELF.h:1095
@ SHF_ALLOC
Definition: ELF.h:1186
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
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