LLVM  13.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 
51 // finish() - write out any non-empty assembler constant pools and
52 // write out note.gnu.properties if need.
54  ConstantPools->emitAll(Streamer);
55 
56  if (MarkBTIProperty)
58 }
59 
61  if (Flags == 0)
62  return;
63 
64  MCStreamer &OutStreamer = getStreamer();
65  MCContext &Context = OutStreamer.getContext();
66  // Emit a .note.gnu.property section with the flags.
67  MCSectionELF *Nt = Context.getELFSection(".note.gnu.property", ELF::SHT_NOTE,
69  if (Nt->isRegistered()) {
70  SMLoc Loc;
71  Context.reportWarning(
72  Loc,
73  "The .note.gnu.property is not emitted because it is already present.");
74  return;
75  }
76  MCSection *Cur = OutStreamer.getCurrentSectionOnly();
77  OutStreamer.SwitchSection(Nt);
78 
79  // Emit the note header.
80  OutStreamer.emitValueToAlignment(Align(8).value());
81  OutStreamer.emitIntValue(4, 4); // data size for "GNU\0"
82  OutStreamer.emitIntValue(4 * 4, 4); // Elf_Prop size
84  OutStreamer.emitBytes(StringRef("GNU", 4)); // note name
85 
86  // Emit the PAC/BTI properties.
88  OutStreamer.emitIntValue(4, 4); // data size
89  OutStreamer.emitIntValue(Flags, 4); // data
90  OutStreamer.emitIntValue(0, 4); // pad
91 
92  OutStreamer.endSection(Nt);
93  OutStreamer.SwitchSection(Cur);
94 }
95 
97  char Buffer[4];
98 
99  // We can't just use EmitIntValue here, as that will swap the
100  // endianness on big-endian systems (instructions are always
101  // little-endian).
102  for (unsigned I = 0; I < 4; ++I) {
103  Buffer[I] = uint8_t(Inst);
104  Inst >>= 8;
105  }
106 
107  getStreamer().emitBytes(StringRef(Buffer, 4));
108 }
109 
112  const MCSubtargetInfo &STI) {
113  const Triple &TT = STI.getTargetTriple();
114  if (TT.isOSBinFormatELF())
115  return new AArch64TargetELFStreamer(S);
116  if (TT.isOSBinFormatCOFF())
117  return new AArch64TargetWinCOFFStreamer(S);
118  return nullptr;
119 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MCTargetStreamer::getStreamer
MCStreamer & getStreamer()
Definition: MCStreamer.h:99
llvm
Definition: AllocatorList.h:23
llvm::ELF::NT_GNU_PROPERTY_TYPE_0
@ NT_GNU_PROPERTY_TYPE_0
Definition: ELF.h:1514
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
llvm::AArch64TargetStreamer::emitNoteSection
void emitNoteSection(unsigned Flags)
Callback used to implement the .note.gnu.property section.
Definition: AArch64TargetStreamer.cpp:60
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:96
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
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:111
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
CommandLine.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
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
llvm::ELF::GNU_PROPERTY_AARCH64_FEATURE_1_AND
@ GNU_PROPERTY_AARCH64_FEATURE_1_AND
Definition: ELF.h:1521
MCSubtargetInfo.h
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:91
llvm::AArch64TargetELFStreamer
Definition: AArch64TargetStreamer.h:74
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
AArch64MCAsmInfo.h
llvm::MCStreamer::getCurrentSectionOnly
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:374
llvm::MCStreamer::endSection
MCSymbol * endSection(MCSection *Section)
Definition: MCStreamer.cpp:1207
llvm::AArch64TargetWinCOFFStreamer
Definition: AArch64TargetStreamer.h:85
llvm::ELF::SHT_NOTE
@ SHT_NOTE
Definition: ELF.h:910
ConstantPools.h
llvm::cl::opt< bool >
llvm::MCTargetStreamer::Streamer
MCStreamer & Streamer
Definition: MCStreamer.h:93
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:982
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:131
MCSection.h
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:53
llvm::MCSection::isRegistered
bool isRegistered() const
Definition: MCSection.h:154
AArch64TargetStreamer.h
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:278
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:1181
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:1171
llvm::cl::desc
Definition: CommandLine.h:414
llvm::ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI
@ GNU_PROPERTY_AARCH64_FEATURE_1_BTI
Definition: ELF.h:1535
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:1193
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