LLVM  14.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 
13 #include "AArch64TargetStreamer.h"
14 #include "AArch64MCAsmInfo.h"
15 #include "AArch64Subtarget.h"
16 #include "llvm/BinaryFormat/ELF.h"
17 #include "llvm/MC/ConstantPools.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCSection.h"
20 #include "llvm/MC/MCSectionELF.h"
23 
24 using 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.
58  if (MarkBTIProperty)
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).value());
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 (unsigned I = 0; I < 4; ++I) {
105  Buffer[I] = 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 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MCTargetStreamer::getStreamer
MCStreamer & getStreamer()
Definition: MCStreamer.h:99
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::AArch64TargetStreamer::emitNoteSection
void emitNoteSection(unsigned Flags)
Callback used to implement the .note.gnu.property section.
Definition: AArch64TargetStreamer.cpp:62
MCSectionELF.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::AArch64TargetStreamer::emitInst
virtual void emitInst(uint32_t Inst)
Callback used to implement the .inst directive.
Definition: AArch64TargetStreamer.cpp:98
llvm::AssemblerConstantPools
Definition: ConstantPools.h:69
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
llvm::ELF::SHT_NOTE
@ SHT_NOTE
Definition: ELF.h:916
new
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Definition: README.txt:125
llvm::createAArch64ObjectTargetStreamer
MCTargetStreamer * createAArch64ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: AArch64TargetStreamer.cpp:113
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
CommandLine.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::AArch64TargetStreamer::AArch64TargetStreamer
AArch64TargetStreamer(MCStreamer &S)
Definition: AArch64TargetStreamer.cpp:34
ELF.h
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::MCSubtargetInfo::getTargetTriple
const Triple & getTargetTriple() const
Definition: MCSubtargetInfo.h:107
MCContext.h
MCSubtargetInfo.h
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:91
llvm::AArch64TargetELFStreamer
Definition: AArch64TargetStreamer.h:75
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
AArch64MCAsmInfo.h
llvm::MCStreamer::getCurrentSectionOnly
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:376
llvm::MCStreamer::endSection
MCSymbol * endSection(MCSection *Section)
Definition: MCStreamer.cpp:1226
llvm::AArch64TargetWinCOFFStreamer
Definition: AArch64TargetStreamer.h:86
ConstantPools.h
llvm::cl::opt< bool >
llvm::MCTargetStreamer::Streamer
MCStreamer & Streamer
Definition: MCStreamer.h:93
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::MCStreamer::emitIntValue
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
MCSection.h
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:988
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AArch64TargetStreamer::~AArch64TargetStreamer
~AArch64TargetStreamer() override
uint32_t
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::AArch64TargetStreamer::finish
void finish() override
Definition: AArch64TargetStreamer.cpp:57
llvm::AArch64TargetStreamer::emitConstantPools
void emitConstantPools() override
Definition: AArch64TargetStreamer.cpp:51
llvm::ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI
@ GNU_PROPERTY_AARCH64_FEATURE_1_BTI
Definition: ELF.h:1541
llvm::MCSection::isRegistered
bool isRegistered() const
Definition: MCSection.h:161
AArch64TargetStreamer.h
llvm::ELF::GNU_PROPERTY_AARCH64_FEATURE_1_AND
@ GNU_PROPERTY_AARCH64_FEATURE_1_AND
Definition: ELF.h:1527
llvm::AArch64TargetStreamer::addConstantPoolEntry
const MCExpr * addConstantPoolEntry(const MCExpr *, unsigned Size, SMLoc Loc)
Callback used to implement the ldr= pseudo.
Definition: AArch64TargetStreamer.cpp:41
AArch64Subtarget.h
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:280
llvm::ELF::NT_GNU_PROPERTY_TYPE_0
@ NT_GNU_PROPERTY_TYPE_0
Definition: ELF.h:1520
llvm::MCStreamer::emitValueToAlignment
virtual void emitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Definition: MCStreamer.cpp:1199
MarkBTIProperty
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))
llvm::MCStreamer::emitBytes
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:1189
llvm::cl::desc
Definition: CommandLine.h:414
llvm::MCStreamer::SwitchSection
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1212
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::AArch64TargetStreamer::emitCurrentConstantPool
void emitCurrentConstantPool()
Callback used to implemnt the .ltorg directive.
Definition: AArch64TargetStreamer.cpp:47