2009-06-24 03:03:06 +02:00
|
|
|
//===- lib/MC/MCStreamer.cpp - Streaming Machine Code Output --------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-06-24 03:03:06 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2018-02-24 00:01:06 +01:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2017-02-08 00:02:00 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-07 05:48:56 +02:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
2019-10-19 03:44:09 +02:00
|
|
|
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
|
2013-09-09 04:37:14 +02:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2010-12-06 18:27:56 +01:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2016-08-26 19:58:37 +02:00
|
|
|
#include "llvm/MC/MCCodeView.h"
|
2010-11-16 22:20:32 +01:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2017-02-08 00:02:00 +01:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2010-01-19 19:45:47 +01:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2015-05-16 00:19:42 +02:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2015-06-18 22:43:22 +02:00
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2014-01-24 03:42:26 +01:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
[CSSPGO] Pseudo probe encoding and emission.
This change implements pseudo probe encoding and emission for CSSPGO. Please see RFC here for more context: https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s
Pseudo probes are in the form of intrinsic calls on IR/MIR but they do not turn into any machine instructions. Instead they are emitted into the binary as a piece of data in standalone sections. The probe-specific sections are not needed to be loaded into memory at execution time, thus they do not incur a runtime overhead.
**ELF object emission**
The binary data to emit are organized as two ELF sections, i.e, the `.pseudo_probe_desc` section and the `.pseudo_probe` section. The `.pseudo_probe_desc` section stores a function descriptor for each function and the `.pseudo_probe` section stores the actual probes, each fo which corresponds to an IR basic block or an IR function callsite. A function descriptor is stored as a module-level metadata during the compilation and is serialized into the object file during object emission.
Both the probe descriptors and pseudo probes can be emitted into a separate ELF section per function to leverage the linker for deduplication. A `.pseudo_probe` section shares the same COMDAT group with the function code so that when the function is dead, the probes are dead and disposed too. On the contrary, a `.pseudo_probe_desc` section has its own COMDAT group. This is because even if a function is dead, its probes may be inlined into other functions and its descriptor is still needed by the profile generation tool.
The format of `.pseudo_probe_desc` section looks like:
```
.section .pseudo_probe_desc,"",@progbits
.quad 6309742469962978389 // Func GUID
.quad 4294967295 // Func Hash
.byte 9 // Length of func name
.ascii "_Z5funcAi" // Func name
.quad 7102633082150537521
.quad 138828622701
.byte 12
.ascii "_Z8funcLeafi"
.quad 446061515086924981
.quad 4294967295
.byte 9
.ascii "_Z5funcBi"
.quad -2016976694713209516
.quad 72617220756
.byte 7
.ascii "_Z3fibi"
```
For each `.pseudoprobe` section, the encoded binary data consists of a single function record corresponding to an outlined function (i.e, a function with a code entry in the `.text` section). A function record has the following format :
```
FUNCTION BODY (one for each outlined function present in the text section)
GUID (uint64)
GUID of the function
NPROBES (ULEB128)
Number of probes originating from this function.
NUM_INLINED_FUNCTIONS (ULEB128)
Number of callees inlined into this function, aka number of
first-level inlinees
PROBE RECORDS
A list of NPROBES entries. Each entry contains:
INDEX (ULEB128)
TYPE (uint4)
0 - block probe, 1 - indirect call, 2 - direct call
ATTRIBUTE (uint3)
reserved
ADDRESS_TYPE (uint1)
0 - code address, 1 - address delta
CODE_ADDRESS (uint64 or ULEB128)
code address or address delta, depending on ADDRESS_TYPE
INLINED FUNCTION RECORDS
A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined
callees. Each record contains:
INLINE SITE
GUID of the inlinee (uint64)
ID of the callsite probe (ULEB128)
FUNCTION BODY
A FUNCTION BODY entry describing the inlined function.
```
To support building a context-sensitive profile, probes from inlinees are grouped by their inline contexts. An inline context is logically a call path through which a callee function lands in a caller function. The probe emitter builds an inline tree based on the debug metadata for each outlined function in the form of a trie tree. A tree root is the outlined function. Each tree edge stands for a callsite where inlining happens. Pseudo probes originating from an inlinee function are stored in a tree node and the tree path starting from the root all the way down to the tree node is the inline context of the probes. The emission happens on the whole tree top-down recursively. Probes of a tree node will be emitted altogether with their direct parent edge. Since a pseudo probe corresponds to a real code address, for size savings, the address is encoded as a delta from the previous probe except for the first probe. Variant-sized integer encoding, aka LEB128, is used for address delta and probe index.
**Assembling**
Pseudo probes can be printed as assembly directives alternatively. This allows for good assembly code readability and also provides a view of how optimizations and pseudo probes affect each other, especially helpful for diff time assembly analysis.
A pseudo probe directive has the following operands in order: function GUID, probe index, probe type, probe attributes and inline context. The directive is generated by the compiler and can be parsed by the assembler to form an encoded `.pseudoprobe` section in the object file.
A example assembly looks like:
```
foo2: # @foo2
# %bb.0: # %bb0
pushq %rax
testl %edi, %edi
.pseudoprobe 837061429793323041 1 0 0
je .LBB1_1
# %bb.2: # %bb2
.pseudoprobe 837061429793323041 6 2 0
callq foo
.pseudoprobe 837061429793323041 3 0 0
.pseudoprobe 837061429793323041 4 0 0
popq %rax
retq
.LBB1_1: # %bb1
.pseudoprobe 837061429793323041 5 1 0
callq *%rsi
.pseudoprobe 837061429793323041 2 0 0
.pseudoprobe 837061429793323041 4 0 0
popq %rax
retq
# -- End function
.section .pseudo_probe_desc,"",@progbits
.quad 6699318081062747564
.quad 72617220756
.byte 3
.ascii "foo"
.quad 837061429793323041
.quad 281547593931412
.byte 4
.ascii "foo2"
```
With inlining turned on, the assembly may look different around %bb2 with an inlined probe:
```
# %bb.2: # %bb2
.pseudoprobe 837061429793323041 3 0
.pseudoprobe 6699318081062747564 1 0 @ 837061429793323041:6
.pseudoprobe 837061429793323041 4 0
popq %rax
retq
```
**Disassembling**
We have a disassembling tool (llvm-profgen) that can display disassembly alongside with pseudo probes. So far it only supports ELF executable file.
An example disassembly looks like:
```
00000000002011a0 <foo2>:
2011a0: 50 push rax
2011a1: 85 ff test edi,edi
[Probe]: FUNC: foo2 Index: 1 Type: Block
2011a3: 74 02 je 2011a7 <foo2+0x7>
[Probe]: FUNC: foo2 Index: 3 Type: Block
[Probe]: FUNC: foo2 Index: 4 Type: Block
[Probe]: FUNC: foo Index: 1 Type: Block Inlined: @ foo2:6
2011a5: 58 pop rax
2011a6: c3 ret
[Probe]: FUNC: foo2 Index: 2 Type: Block
2011a7: bf 01 00 00 00 mov edi,0x1
[Probe]: FUNC: foo2 Index: 5 Type: IndirectCall
2011ac: ff d6 call rsi
[Probe]: FUNC: foo2 Index: 4 Type: Block
2011ae: 58 pop rax
2011af: c3 ret
```
Reviewed By: wmi
Differential Revision: https://reviews.llvm.org/D91878
2020-12-09 00:37:32 +01:00
|
|
|
#include "llvm/MC/MCPseudoProbe.h"
|
2019-08-30 23:23:05 +02:00
|
|
|
#include "llvm/MC/MCRegister.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2015-03-11 01:51:37 +01:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2016-05-03 01:22:18 +02:00
|
|
|
#include "llvm/MC/MCSectionCOFF.h"
|
2011-04-27 17:21:19 +02:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2014-07-17 05:08:50 +02:00
|
|
|
#include "llvm/MC/MCWin64EH.h"
|
2017-02-08 00:02:00 +01:00
|
|
|
#include "llvm/MC/MCWinEH.h"
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/Support/Casting.h"
|
2010-11-01 15:28:48 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-08-09 01:56:06 +02:00
|
|
|
#include "llvm/Support/LEB128.h"
|
2017-02-08 00:02:00 +01:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-02-08 00:02:00 +01:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
2017-06-06 13:49:48 +02:00
|
|
|
#include <cstdlib>
|
2017-02-08 00:02:00 +01:00
|
|
|
#include <utility>
|
2009-06-24 03:03:06 +02:00
|
|
|
|
2017-02-08 00:02:00 +01:00
|
|
|
using namespace llvm;
|
2014-01-26 07:06:37 +01:00
|
|
|
|
|
|
|
MCTargetStreamer::MCTargetStreamer(MCStreamer &S) : Streamer(S) {
|
|
|
|
S.setTargetStreamer(this);
|
|
|
|
}
|
|
|
|
|
2017-02-08 00:02:00 +01:00
|
|
|
// Pin the vtables to this file.
|
|
|
|
MCTargetStreamer::~MCTargetStreamer() = default;
|
|
|
|
|
2014-01-14 05:25:13 +01:00
|
|
|
void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {}
|
2013-10-08 15:08:17 +02:00
|
|
|
|
2014-02-01 00:10:26 +01:00
|
|
|
void MCTargetStreamer::finish() {}
|
|
|
|
|
2017-12-20 15:55:10 +01:00
|
|
|
void MCTargetStreamer::changeSection(const MCSection *CurSection,
|
|
|
|
MCSection *Section,
|
|
|
|
const MCExpr *Subsection,
|
|
|
|
raw_ostream &OS) {
|
2021-05-05 19:03:02 +02:00
|
|
|
Section->PrintSwitchToSection(*Streamer.getContext().getAsmInfo(),
|
|
|
|
Streamer.getContext().getTargetTriple(), OS,
|
|
|
|
Subsection);
|
2017-12-20 15:55:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
|
2020-02-15 17:52:56 +01:00
|
|
|
Streamer.emitRawText(Directive);
|
2017-12-20 15:55:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCTargetStreamer::emitValue(const MCExpr *Value) {
|
|
|
|
SmallString<128> Str;
|
|
|
|
raw_svector_ostream OS(Str);
|
|
|
|
|
|
|
|
Value->print(OS, Streamer.getContext().getAsmInfo());
|
2020-02-15 17:52:56 +01:00
|
|
|
Streamer.emitRawText(OS.str());
|
2017-12-20 15:55:10 +01:00
|
|
|
}
|
|
|
|
|
[DEBUGINFO, NVPTX] Try to pack bytes data into a single string.
Summary:
If the target does not support `.asciz` and `.ascii` directives, the
strings are represented as bytes and each byte is placed on the new line
as a separate byte directive `.b8 <data>`. NVPTX target allows to
represent the vector of the data of the same type as a vector, where
values are separated using `,` symbol: `.b8 <data1>,<data2>,...`. This
allows to reduce the size of the final PTX file. Ptxas tool includes ptx
files into the resulting binary object, so reducing the size of the PTX
file is important.
Reviewers: tra, jlebar, echristo
Subscribers: jholewinski, llvm-commits
Differential Revision: https://reviews.llvm.org/D45822
llvm-svn: 345142
2018-10-24 16:04:00 +02:00
|
|
|
void MCTargetStreamer::emitRawBytes(StringRef Data) {
|
|
|
|
const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
|
|
|
|
const char *Directive = MAI->getData8bitsDirective();
|
|
|
|
for (const unsigned char C : Data.bytes()) {
|
|
|
|
SmallString<128> Str;
|
|
|
|
raw_svector_ostream OS(Str);
|
|
|
|
|
|
|
|
OS << Directive << (unsigned)C;
|
2020-02-15 17:52:56 +01:00
|
|
|
Streamer.emitRawText(OS.str());
|
[DEBUGINFO, NVPTX] Try to pack bytes data into a single string.
Summary:
If the target does not support `.asciz` and `.ascii` directives, the
strings are represented as bytes and each byte is placed on the new line
as a separate byte directive `.b8 <data>`. NVPTX target allows to
represent the vector of the data of the same type as a vector, where
values are separated using `,` symbol: `.b8 <data1>,<data2>,...`. This
allows to reduce the size of the final PTX file. Ptxas tool includes ptx
files into the resulting binary object, so reducing the size of the PTX
file is important.
Reviewers: tra, jlebar, echristo
Subscribers: jholewinski, llvm-commits
Differential Revision: https://reviews.llvm.org/D45822
llvm-svn: 345142
2018-10-24 16:04:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 10:44:49 +01:00
|
|
|
void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {}
|
|
|
|
|
2014-01-26 07:06:37 +01:00
|
|
|
MCStreamer::MCStreamer(MCContext &Ctx)
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-04-30 21:22:40 +02:00
|
|
|
: Context(Ctx), CurrentWinFrameInfo(nullptr),
|
2020-11-13 21:35:22 +01:00
|
|
|
CurrentProcWinFrameInfoStartIndex(0), UseAssemblerInfoForParsing(false) {
|
2013-04-17 23:18:16 +02:00
|
|
|
SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
|
2009-06-24 03:03:06 +02:00
|
|
|
}
|
|
|
|
|
2017-10-06 19:21:49 +02:00
|
|
|
MCStreamer::~MCStreamer() {}
|
2010-01-19 19:45:47 +01:00
|
|
|
|
2012-12-12 23:59:46 +01:00
|
|
|
void MCStreamer::reset() {
|
2014-09-17 11:25:36 +02:00
|
|
|
DwarfFrameInfos.clear();
|
2014-07-13 21:03:36 +02:00
|
|
|
CurrentWinFrameInfo = nullptr;
|
2017-10-06 19:21:49 +02:00
|
|
|
WinFrameInfos.clear();
|
2014-09-17 19:50:34 +02:00
|
|
|
SymbolOrdering.clear();
|
2012-12-12 23:59:46 +01:00
|
|
|
SectionStack.clear();
|
2013-04-17 23:18:16 +02:00
|
|
|
SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
|
2012-12-12 23:59:46 +01:00
|
|
|
}
|
|
|
|
|
2010-01-22 20:17:48 +01:00
|
|
|
raw_ostream &MCStreamer::GetCommentOS() {
|
|
|
|
// By default, discard comments.
|
|
|
|
return nulls();
|
2013-09-09 04:37:14 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 09:42:35 +02:00
|
|
|
unsigned MCStreamer::getNumFrameInfos() { return DwarfFrameInfos.size(); }
|
|
|
|
ArrayRef<MCDwarfFrameInfo> MCStreamer::getDwarfFrameInfos() const {
|
|
|
|
return DwarfFrameInfos;
|
|
|
|
}
|
|
|
|
|
2014-01-16 17:28:37 +01:00
|
|
|
void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
|
|
|
|
|
2016-07-11 14:42:14 +02:00
|
|
|
void MCStreamer::addExplicitComment(const Twine &T) {}
|
2016-10-11 00:49:37 +02:00
|
|
|
void MCStreamer::emitExplicitComments() {}
|
2016-07-11 14:42:14 +02:00
|
|
|
|
2013-09-09 21:48:37 +02:00
|
|
|
void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) {
|
2014-07-13 21:03:36 +02:00
|
|
|
for (auto &FI : DwarfFrameInfos)
|
|
|
|
FI.CompactUnwindEncoding =
|
|
|
|
(MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0);
|
2010-01-22 20:17:48 +01:00
|
|
|
}
|
|
|
|
|
2010-01-19 23:03:38 +01:00
|
|
|
/// EmitIntValue - Special case of EmitValue that avoids the client having to
|
|
|
|
/// pass in a MCExpr for constant integers.
|
2020-02-15 07:40:47 +01:00
|
|
|
void MCStreamer::emitIntValue(uint64_t Value, unsigned Size) {
|
2014-08-21 00:46:38 +02:00
|
|
|
assert(1 <= Size && Size <= 8 && "Invalid size");
|
2010-12-16 00:14:45 +01:00
|
|
|
assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
|
|
|
|
"Invalid size");
|
2020-04-06 15:21:16 +02:00
|
|
|
const bool IsLittleEndian = Context.getAsmInfo()->isLittleEndian();
|
|
|
|
uint64_t Swapped = support::endian::byte_swap(
|
|
|
|
Value, IsLittleEndian ? support::little : support::big);
|
|
|
|
unsigned Index = IsLittleEndian ? 0 : 8 - Size;
|
|
|
|
emitBytes(StringRef(reinterpret_cast<char *>(&Swapped) + Index, Size));
|
2010-01-19 23:03:38 +01:00
|
|
|
}
|
2020-09-29 22:58:39 +02:00
|
|
|
void MCStreamer::emitIntValue(APInt Value) {
|
|
|
|
if (Value.getNumWords() == 1) {
|
|
|
|
emitIntValue(Value.getLimitedValue(), Value.getBitWidth() / 8);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool IsLittleEndianTarget = Context.getAsmInfo()->isLittleEndian();
|
|
|
|
const bool ShouldSwap = sys::IsLittleEndianHost != IsLittleEndianTarget;
|
|
|
|
const APInt Swapped = ShouldSwap ? Value.byteSwap() : Value;
|
|
|
|
const unsigned Size = Value.getBitWidth() / 8;
|
|
|
|
SmallString<10> Tmp;
|
|
|
|
Tmp.resize(Size);
|
|
|
|
StoreIntToMemory(Swapped, reinterpret_cast<uint8_t *>(Tmp.data()), Size);
|
|
|
|
emitBytes(Tmp.str());
|
|
|
|
}
|
2010-01-19 23:03:38 +01:00
|
|
|
|
2018-02-09 18:00:25 +01:00
|
|
|
/// EmitULEB128IntValue - Special case of EmitULEB128Value that avoids the
|
2010-11-02 18:22:24 +01:00
|
|
|
/// client having to pass in a MCExpr for constant integers.
|
2020-02-13 22:26:21 +01:00
|
|
|
void MCStreamer::emitULEB128IntValue(uint64_t Value, unsigned PadTo) {
|
2012-02-23 22:15:21 +01:00
|
|
|
SmallString<128> Tmp;
|
2010-12-03 02:19:49 +01:00
|
|
|
raw_svector_ostream OSE(Tmp);
|
2019-03-19 14:16:28 +01:00
|
|
|
encodeULEB128(Value, OSE, PadTo);
|
2020-02-15 03:16:24 +01:00
|
|
|
emitBytes(OSE.str());
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:00:25 +01:00
|
|
|
/// EmitSLEB128IntValue - Special case of EmitSLEB128Value that avoids the
|
2010-11-02 18:22:24 +01:00
|
|
|
/// client having to pass in a MCExpr for constant integers.
|
2020-02-13 22:26:21 +01:00
|
|
|
void MCStreamer::emitSLEB128IntValue(int64_t Value) {
|
2012-02-23 22:15:21 +01:00
|
|
|
SmallString<128> Tmp;
|
2010-12-03 02:19:49 +01:00
|
|
|
raw_svector_ostream OSE(Tmp);
|
2012-08-09 01:56:06 +02:00
|
|
|
encodeSLEB128(Value, OSE);
|
2020-02-15 03:16:24 +01:00
|
|
|
emitBytes(OSE.str());
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-15 07:40:47 +01:00
|
|
|
void MCStreamer::emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc) {
|
2020-02-15 04:21:58 +01:00
|
|
|
emitValueImpl(Value, Size, Loc);
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitSymbolValue(const MCSymbol *Sym, unsigned Size,
|
2014-07-19 23:01:58 +02:00
|
|
|
bool IsSectionRelative) {
|
|
|
|
assert((!IsSectionRelative || Size == 4) &&
|
|
|
|
"SectionRelative value requires 4-bytes");
|
|
|
|
|
|
|
|
if (!IsSectionRelative)
|
2020-02-15 04:21:58 +01:00
|
|
|
emitValueImpl(MCSymbolRefExpr::create(Sym, getContext()), Size);
|
2014-07-19 23:01:58 +02:00
|
|
|
else
|
2017-01-02 04:00:19 +01:00
|
|
|
EmitCOFFSecRel32(Sym, /*Offset=*/0);
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitDTPRel64Value(const MCExpr *Value) {
|
2016-08-22 18:18:42 +02:00
|
|
|
report_fatal_error("unsupported directive in streamer");
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitDTPRel32Value(const MCExpr *Value) {
|
2016-08-22 18:18:42 +02:00
|
|
|
report_fatal_error("unsupported directive in streamer");
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitTPRel64Value(const MCExpr *Value) {
|
2016-08-22 18:18:42 +02:00
|
|
|
report_fatal_error("unsupported directive in streamer");
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitTPRel32Value(const MCExpr *Value) {
|
2016-08-22 18:18:42 +02:00
|
|
|
report_fatal_error("unsupported directive in streamer");
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitGPRel64Value(const MCExpr *Value) {
|
2012-02-03 05:33:00 +01:00
|
|
|
report_fatal_error("unsupported directive in streamer");
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitGPRel32Value(const MCExpr *Value) {
|
2010-11-28 16:09:24 +01:00
|
|
|
report_fatal_error("unsupported directive in streamer");
|
|
|
|
}
|
|
|
|
|
2016-06-01 03:59:58 +02:00
|
|
|
/// Emit NumBytes bytes worth of the value specified by FillValue.
|
|
|
|
/// This implements directives such as '.space'.
|
|
|
|
void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
|
2018-01-09 20:29:33 +01:00
|
|
|
emitFill(*MCConstantExpr::create(NumBytes, getContext()), FillValue);
|
2016-05-28 07:57:48 +02:00
|
|
|
}
|
|
|
|
|
2020-07-31 03:33:33 +02:00
|
|
|
void llvm::MCStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLen,
|
|
|
|
llvm::SMLoc) {}
|
|
|
|
|
2016-06-01 03:59:58 +02:00
|
|
|
/// The implementation in this class just redirects to emitFill.
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitZeros(uint64_t NumBytes) { emitFill(NumBytes, 0); }
|
2013-06-27 16:35:03 +02:00
|
|
|
|
2018-02-22 22:03:33 +01:00
|
|
|
Expected<unsigned>
|
|
|
|
MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
|
|
|
|
StringRef Filename,
|
2019-04-05 01:34:38 +02:00
|
|
|
Optional<MD5::MD5Result> Checksum,
|
2018-02-24 00:01:06 +01:00
|
|
|
Optional<StringRef> Source,
|
|
|
|
unsigned CUID) {
|
|
|
|
return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum,
|
|
|
|
Source, CUID);
|
2010-11-16 22:20:32 +01:00
|
|
|
}
|
|
|
|
|
2018-03-29 19:16:41 +02:00
|
|
|
void MCStreamer::emitDwarfFile0Directive(StringRef Directory,
|
|
|
|
StringRef Filename,
|
2019-04-05 01:34:38 +02:00
|
|
|
Optional<MD5::MD5Result> Checksum,
|
2018-03-29 19:16:41 +02:00
|
|
|
Optional<StringRef> Source,
|
|
|
|
unsigned CUID) {
|
|
|
|
getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
|
|
|
|
Source);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIBKeyFrame() {
|
2018-12-21 11:45:08 +01:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
CurFrame->IsBKeyFrame = true;
|
|
|
|
}
|
|
|
|
|
2020-02-13 22:26:21 +01:00
|
|
|
void MCStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
2010-11-16 22:20:32 +01:00
|
|
|
unsigned Column, unsigned Flags,
|
2020-02-13 22:26:21 +01:00
|
|
|
unsigned Isa, unsigned Discriminator,
|
2011-04-18 22:26:49 +02:00
|
|
|
StringRef FileName) {
|
2010-11-16 22:20:32 +01:00
|
|
|
getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa,
|
|
|
|
Discriminator);
|
|
|
|
}
|
|
|
|
|
2014-04-01 10:07:52 +02:00
|
|
|
MCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) {
|
|
|
|
MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
|
|
|
|
if (!Table.getLabel()) {
|
|
|
|
StringRef Prefix = Context.getAsmInfo()->getPrivateGlobalPrefix();
|
|
|
|
Table.setLabel(
|
2015-05-18 20:43:14 +02:00
|
|
|
Context.getOrCreateSymbol(Prefix + "line_table_start" + Twine(CUID)));
|
2014-04-01 10:07:52 +02:00
|
|
|
}
|
|
|
|
return Table.getLabel();
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:25:18 +01:00
|
|
|
bool MCStreamer::hasUnfinishedDwarfFrameInfo() {
|
2017-10-10 03:49:21 +02:00
|
|
|
return !DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End;
|
2016-02-24 23:25:18 +01:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:49:21 +02:00
|
|
|
MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() {
|
|
|
|
if (!hasUnfinishedDwarfFrameInfo()) {
|
2020-11-11 15:27:01 +01:00
|
|
|
getContext().reportError(getStartTokLoc(),
|
|
|
|
"this directive must appear between "
|
|
|
|
".cfi_startproc and .cfi_endproc directives");
|
2017-10-10 03:49:21 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &DwarfFrameInfos.back();
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
|
|
|
|
2017-09-19 20:14:45 +02:00
|
|
|
bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename,
|
|
|
|
ArrayRef<uint8_t> Checksum,
|
|
|
|
unsigned ChecksumKind) {
|
|
|
|
return getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum,
|
|
|
|
ChecksumKind);
|
2016-01-29 01:49:42 +01:00
|
|
|
}
|
|
|
|
|
2016-09-07 18:15:31 +02:00
|
|
|
bool MCStreamer::EmitCVFuncIdDirective(unsigned FunctionId) {
|
|
|
|
return getContext().getCVContext().recordFunctionId(FunctionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MCStreamer::EmitCVInlineSiteIdDirective(unsigned FunctionId,
|
|
|
|
unsigned IAFunc, unsigned IAFile,
|
|
|
|
unsigned IALine, unsigned IACol,
|
|
|
|
SMLoc Loc) {
|
|
|
|
if (getContext().getCVContext().getCVFunctionInfo(IAFunc) == nullptr) {
|
|
|
|
getContext().reportError(Loc, "parent function id not introduced by "
|
|
|
|
".cv_func_id or .cv_inline_site_id");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getContext().getCVContext().recordInlinedCallSiteId(
|
|
|
|
FunctionId, IAFunc, IAFile, IALine, IACol);
|
|
|
|
}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
|
2016-01-29 01:49:42 +01:00
|
|
|
unsigned Line, unsigned Column,
|
|
|
|
bool PrologueEnd, bool IsStmt,
|
2018-08-29 01:25:59 +02:00
|
|
|
StringRef FileName, SMLoc Loc) {}
|
|
|
|
|
2018-08-29 12:40:51 +02:00
|
|
|
bool MCStreamer::checkCVLocSection(unsigned FuncId, unsigned FileNo,
|
2018-08-29 01:25:59 +02:00
|
|
|
SMLoc Loc) {
|
2016-09-07 18:15:31 +02:00
|
|
|
CodeViewContext &CVC = getContext().getCVContext();
|
2018-08-29 12:40:51 +02:00
|
|
|
MCCVFunctionInfo *FI = CVC.getCVFunctionInfo(FuncId);
|
2018-08-29 01:25:59 +02:00
|
|
|
if (!FI) {
|
|
|
|
getContext().reportError(
|
2016-09-07 18:15:31 +02:00
|
|
|
Loc, "function id not introduced by .cv_func_id or .cv_inline_site_id");
|
2018-08-29 01:25:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 18:15:31 +02:00
|
|
|
|
|
|
|
// Track the section
|
|
|
|
if (FI->Section == nullptr)
|
|
|
|
FI->Section = getCurrentSectionOnly();
|
2018-08-29 01:25:59 +02:00
|
|
|
else if (FI->Section != getCurrentSectionOnly()) {
|
|
|
|
getContext().reportError(
|
2016-09-07 18:15:31 +02:00
|
|
|
Loc,
|
|
|
|
"all .cv_loc directives for a function must be in the same section");
|
2018-08-29 01:25:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2016-01-29 01:49:42 +01:00
|
|
|
}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVLinetableDirective(unsigned FunctionId,
|
2016-01-29 01:49:42 +01:00
|
|
|
const MCSymbol *Begin,
|
|
|
|
const MCSymbol *End) {}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
|
2016-09-07 18:15:31 +02:00
|
|
|
unsigned SourceFileId,
|
|
|
|
unsigned SourceLineNum,
|
|
|
|
const MCSymbol *FnStartSym,
|
|
|
|
const MCSymbol *FnEndSym) {}
|
2016-01-29 20:24:12 +01:00
|
|
|
|
2019-08-05 16:16:58 +02:00
|
|
|
/// Only call this on endian-specific types like ulittle16_t and little32_t, or
|
|
|
|
/// structs composed of them.
|
|
|
|
template <typename T>
|
|
|
|
static void copyBytesForDefRange(SmallString<20> &BytePrefix,
|
|
|
|
codeview::SymbolKind SymKind,
|
|
|
|
const T &DefRangeHeader) {
|
|
|
|
BytePrefix.resize(2 + sizeof(T));
|
|
|
|
codeview::ulittle16_t SymKindLE = codeview::ulittle16_t(SymKind);
|
|
|
|
memcpy(&BytePrefix[0], &SymKindLE, 2);
|
|
|
|
memcpy(&BytePrefix[2], &DefRangeHeader, sizeof(T));
|
|
|
|
}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVDefRangeDirective(
|
2016-02-05 02:55:49 +01:00
|
|
|
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
|
|
|
|
StringRef FixedSizePortion) {}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVDefRangeDirective(
|
2019-08-05 16:16:58 +02:00
|
|
|
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
|
2019-10-19 03:44:09 +02:00
|
|
|
codeview::DefRangeRegisterRelHeader DRHdr) {
|
2019-08-05 16:16:58 +02:00
|
|
|
SmallString<20> BytePrefix;
|
|
|
|
copyBytesForDefRange(BytePrefix, codeview::S_DEFRANGE_REGISTER_REL, DRHdr);
|
2020-04-21 04:28:13 +02:00
|
|
|
emitCVDefRangeDirective(Ranges, BytePrefix);
|
2019-08-05 16:16:58 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVDefRangeDirective(
|
2019-08-05 16:16:58 +02:00
|
|
|
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
|
2019-10-19 03:44:09 +02:00
|
|
|
codeview::DefRangeSubfieldRegisterHeader DRHdr) {
|
2019-08-05 16:16:58 +02:00
|
|
|
SmallString<20> BytePrefix;
|
|
|
|
copyBytesForDefRange(BytePrefix, codeview::S_DEFRANGE_SUBFIELD_REGISTER,
|
|
|
|
DRHdr);
|
2020-04-21 04:28:13 +02:00
|
|
|
emitCVDefRangeDirective(Ranges, BytePrefix);
|
2019-08-05 16:16:58 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVDefRangeDirective(
|
2019-08-05 16:16:58 +02:00
|
|
|
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
|
2019-10-19 03:44:09 +02:00
|
|
|
codeview::DefRangeRegisterHeader DRHdr) {
|
2019-08-05 16:16:58 +02:00
|
|
|
SmallString<20> BytePrefix;
|
|
|
|
copyBytesForDefRange(BytePrefix, codeview::S_DEFRANGE_REGISTER, DRHdr);
|
2020-04-21 04:28:13 +02:00
|
|
|
emitCVDefRangeDirective(Ranges, BytePrefix);
|
2019-08-05 16:16:58 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::emitCVDefRangeDirective(
|
2019-08-05 16:16:58 +02:00
|
|
|
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
|
2019-10-19 03:44:09 +02:00
|
|
|
codeview::DefRangeFramePointerRelHeader DRHdr) {
|
2019-08-05 16:16:58 +02:00
|
|
|
SmallString<20> BytePrefix;
|
|
|
|
copyBytesForDefRange(BytePrefix, codeview::S_DEFRANGE_FRAMEPOINTER_REL,
|
|
|
|
DRHdr);
|
2020-04-21 04:28:13 +02:00
|
|
|
emitCVDefRangeDirective(Ranges, BytePrefix);
|
2019-08-05 16:16:58 +02:00
|
|
|
}
|
|
|
|
|
2020-02-15 03:16:24 +01:00
|
|
|
void MCStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
|
2011-04-28 14:50:37 +02:00
|
|
|
MCSymbol *EHSymbol) {
|
|
|
|
}
|
|
|
|
|
2014-10-15 18:12:52 +02:00
|
|
|
void MCStreamer::InitSections(bool NoExecStack) {
|
2014-01-24 03:42:26 +01:00
|
|
|
SwitchSection(getContext().getObjectFileInfo()->getTextSection());
|
|
|
|
}
|
|
|
|
|
2015-10-05 14:07:05 +02:00
|
|
|
void MCStreamer::AssignFragment(MCSymbol *Symbol, MCFragment *Fragment) {
|
|
|
|
assert(Fragment);
|
|
|
|
Symbol->setFragment(Fragment);
|
2013-09-20 01:21:01 +02:00
|
|
|
|
|
|
|
// As we emit symbols into a section, track the order so that they can
|
|
|
|
// be sorted upon later. Zero is reserved to mean 'unemitted'.
|
|
|
|
SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
|
2017-02-10 16:13:12 +01:00
|
|
|
Symbol->redefineIfPossible();
|
|
|
|
|
|
|
|
if (!Symbol->isUndefined() || Symbol->isVariable())
|
2021-03-09 11:54:41 +01:00
|
|
|
return getContext().reportError(Loc, "symbol '" + Twine(Symbol->getName()) +
|
|
|
|
"' is already defined");
|
2017-02-10 16:13:12 +01:00
|
|
|
|
2011-04-27 17:21:19 +02:00
|
|
|
assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
|
2016-10-14 07:47:37 +02:00
|
|
|
assert(getCurrentSectionOnly() && "Cannot emit before setting section!");
|
2015-10-05 14:07:05 +02:00
|
|
|
assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
|
2017-02-10 16:13:12 +01:00
|
|
|
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
|
|
|
|
|
2015-10-05 14:07:05 +02:00
|
|
|
Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment());
|
2014-01-14 05:25:13 +01:00
|
|
|
|
|
|
|
MCTargetStreamer *TS = getTargetStreamer();
|
|
|
|
if (TS)
|
|
|
|
TS->emitLabel(Symbol);
|
2011-04-27 17:21:19 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 07:29:49 +01:00
|
|
|
void MCStreamer::emitCFISections(bool EH, bool Debug) {}
|
2011-05-10 03:10:18 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIStartProc(bool IsSimple, SMLoc Loc) {
|
2016-02-24 23:25:18 +01:00
|
|
|
if (hasUnfinishedDwarfFrameInfo())
|
2018-10-19 14:14:30 +02:00
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "starting new .cfi frame before finishing the previous one");
|
2011-08-02 22:24:22 +02:00
|
|
|
|
2011-08-25 00:31:37 +02:00
|
|
|
MCDwarfFrameInfo Frame;
|
2014-01-27 18:20:25 +01:00
|
|
|
Frame.IsSimple = IsSimple;
|
2020-02-14 06:58:16 +01:00
|
|
|
emitCFIStartProcImpl(Frame);
|
2012-01-07 23:42:19 +01:00
|
|
|
|
2014-10-07 13:03:09 +02:00
|
|
|
const MCAsmInfo* MAI = Context.getAsmInfo();
|
|
|
|
if (MAI) {
|
|
|
|
for (const MCCFIInstruction& Inst : MAI->getInitialFrameState()) {
|
|
|
|
if (Inst.getOperation() == MCCFIInstruction::OpDefCfa ||
|
|
|
|
Inst.getOperation() == MCCFIInstruction::OpDefCfaRegister) {
|
|
|
|
Frame.CurrentCfaRegister = Inst.getRegister();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-13 21:03:36 +02:00
|
|
|
DwarfFrameInfos.push_back(Frame);
|
2012-01-07 23:42:19 +01:00
|
|
|
}
|
2011-08-02 22:24:22 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
|
2014-11-03 13:19:03 +01:00
|
|
|
}
|
2012-01-07 23:42:19 +01:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIEndProc() {
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2020-02-14 06:58:16 +01:00
|
|
|
emitCFIEndProcImpl(*CurFrame);
|
2012-01-09 01:17:29 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
|
2014-06-25 02:13:59 +02:00
|
|
|
// Put a dummy non-null value in Frame.End to mark that this frame has been
|
|
|
|
// closed.
|
[MC] Suppress .Lcfi labels when emitting textual assembly
Summary:
This suppresses the generation of .Lcfi labels in our textual assembler.
It was annoying that this generated cascading .Lcfi labels:
llc foo.ll -o - | llvm-mc | llvm-mc
After three trips through MCAsmStreamer, we'd have three labels in the
output when none are necessary. We should only bother creating the
labels and frame data when making a real object file.
This supercedes D38605, which moved the entire .seh_ implementation into
MCObjectStreamer.
This has the advantage that we do more checking when emitting textual
assembly, as a minor efficiency cost. Outputting textual assembly is not
performance critical, so this shouldn't matter.
Reviewers: majnemer, MatzeB
Subscribers: qcolombet, nemanjai, javed.absar, eraman, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D38638
llvm-svn: 315259
2017-10-10 02:57:36 +02:00
|
|
|
Frame.End = (MCSymbol *)1;
|
2010-11-22 15:27:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *MCStreamer::emitCFILabel() {
|
[MC] Suppress .Lcfi labels when emitting textual assembly
Summary:
This suppresses the generation of .Lcfi labels in our textual assembler.
It was annoying that this generated cascading .Lcfi labels:
llc foo.ll -o - | llvm-mc | llvm-mc
After three trips through MCAsmStreamer, we'd have three labels in the
output when none are necessary. We should only bother creating the
labels and frame data when making a real object file.
This supercedes D38605, which moved the entire .seh_ implementation into
MCObjectStreamer.
This has the advantage that we do more checking when emitting textual
assembly, as a minor efficiency cost. Outputting textual assembly is not
performance critical, so this shouldn't matter.
Reviewers: majnemer, MatzeB
Subscribers: qcolombet, nemanjai, javed.absar, eraman, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D38638
llvm-svn: 315259
2017-10-10 02:57:36 +02:00
|
|
|
// Return a dummy non-null value so that label fields appear filled in when
|
|
|
|
// generating textual assembly.
|
|
|
|
return (MCSymbol *)1;
|
2012-11-24 03:18:49 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIDefCfa(int64_t Register, int64_t Offset) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
2020-05-23 05:18:15 +02:00
|
|
|
MCCFIInstruction::cfiDefCfa(Label, Register, Offset);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-29 02:42:56 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
2014-10-07 13:03:09 +02:00
|
|
|
CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
|
2010-12-29 02:42:56 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIDefCfaOffset(int64_t Offset) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
2020-05-23 04:57:21 +02:00
|
|
|
MCCFIInstruction::cfiDefCfaOffset(Label, Offset);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-28 19:36:23 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
2010-11-22 15:27:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIAdjustCfaOffset(int64_t Adjustment) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2011-04-12 20:53:30 +02:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIDefCfaRegister(int64_t Register) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createDefCfaRegister(Label, Register);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-29 01:26:06 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
2014-10-07 13:03:09 +02:00
|
|
|
CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
|
2010-11-22 15:27:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIOffset(int64_t Register, int64_t Offset) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
2012-11-24 04:10:54 +01:00
|
|
|
MCCFIInstruction::createOffset(Label, Register, Offset);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-29 01:09:59 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
2010-11-22 15:27:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIRelOffset(int64_t Register, int64_t Offset) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createRelOffset(Label, Register, Offset);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2011-04-12 18:12:03 +02:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIPersonality(const MCSymbol *Sym,
|
2010-12-27 01:36:05 +01:00
|
|
|
unsigned Encoding) {
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-10 08:39:47 +01:00
|
|
|
CurFrame->Personality = Sym;
|
2010-12-27 01:36:05 +01:00
|
|
|
CurFrame->PersonalityEncoding = Encoding;
|
2010-11-22 15:27:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-10 08:39:47 +01:00
|
|
|
CurFrame->Lsda = Sym;
|
2010-12-27 16:56:22 +01:00
|
|
|
CurFrame->LsdaEncoding = Encoding;
|
2010-11-22 15:27:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIRememberState() {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction = MCCFIInstruction::createRememberState(Label);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-28 19:36:23 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIRestoreState() {
|
2010-12-28 19:36:23 +01:00
|
|
|
// FIXME: Error if there is no matching cfi_remember_state.
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction = MCCFIInstruction::createRestoreState(Label);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2010-12-28 19:36:23 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFISameValue(int64_t Register) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createSameValue(Label, Register);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2011-04-12 17:31:05 +02:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIRestore(int64_t Register) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createRestore(Label, Register);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2011-12-29 22:43:03 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIEscape(StringRef Values) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction = MCCFIInstruction::createEscape(Label, Values);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2011-12-29 21:24:47 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
2015-10-07 09:01:31 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIGnuArgsSize(int64_t Size) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2018-07-30 21:41:25 +02:00
|
|
|
MCCFIInstruction Instruction =
|
2015-10-07 09:01:31 +02:00
|
|
|
MCCFIInstruction::createGnuArgsSize(Label, Size);
|
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2015-10-07 09:01:31 +02:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
2011-12-29 21:24:47 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFISignalFrame() {
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2012-01-23 22:51:52 +01:00
|
|
|
CurFrame->IsSignalFrame = true;
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIUndefined(int64_t Register) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-24 03:01:08 +01:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createUndefined(Label, Register);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2012-11-23 17:59:41 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIRegister(int64_t Register1, int64_t Register2) {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2012-11-25 16:14:49 +01:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createRegister(Label, Register1, Register2);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2012-11-25 16:14:49 +01:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIWindowSave() {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2013-09-26 16:49:40 +02:00
|
|
|
MCCFIInstruction Instruction =
|
|
|
|
MCCFIInstruction::createWindowSave(Label);
|
2014-07-13 21:03:36 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2013-09-26 16:49:40 +02:00
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFINegateRAState() {
|
|
|
|
MCSymbol *Label = emitCFILabel();
|
2018-12-18 11:37:42 +01:00
|
|
|
MCCFIInstruction Instruction = MCCFIInstruction::createNegateRAState(Label);
|
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
CurFrame->Instructions.push_back(Instruction);
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitCFIReturnColumn(int64_t Register) {
|
2017-07-28 05:39:19 +02:00
|
|
|
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
|
2017-10-10 03:49:21 +02:00
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2017-07-28 05:39:19 +02:00
|
|
|
CurFrame->RAReg = Register;
|
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
WinEH::FrameInfo *MCStreamer::EnsureValidWinFrameInfo(SMLoc Loc) {
|
2015-05-29 19:00:57 +02:00
|
|
|
const MCAsmInfo *MAI = Context.getAsmInfo();
|
2017-10-10 03:26:25 +02:00
|
|
|
if (!MAI->usesWindowsCFI()) {
|
|
|
|
getContext().reportError(
|
|
|
|
Loc, ".seh_* directives are not supported on this target");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) {
|
|
|
|
getContext().reportError(
|
|
|
|
Loc, ".seh_ directive must appear within an active frame");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return CurrentWinFrameInfo;
|
2011-05-19 04:49:00 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) {
|
2015-05-29 19:00:57 +02:00
|
|
|
const MCAsmInfo *MAI = Context.getAsmInfo();
|
|
|
|
if (!MAI->usesWindowsCFI())
|
2017-10-10 03:26:25 +02:00
|
|
|
return getContext().reportError(
|
|
|
|
Loc, ".seh_* directives are not supported on this target");
|
2014-07-13 21:03:36 +02:00
|
|
|
if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
|
2017-10-10 03:26:25 +02:00
|
|
|
getContext().reportError(
|
|
|
|
Loc, "Starting a function before ending the previous one!");
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *StartProc = emitCFILabel();
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2020-11-13 21:35:22 +01:00
|
|
|
CurrentProcWinFrameInfoStartIndex = WinFrameInfos.size();
|
2017-10-06 19:21:49 +02:00
|
|
|
WinFrameInfos.emplace_back(
|
2019-08-15 17:54:37 +02:00
|
|
|
std::make_unique<WinEH::FrameInfo>(Symbol, StartProc));
|
2017-10-06 19:21:49 +02:00
|
|
|
CurrentWinFrameInfo = WinFrameInfos.back().get();
|
2016-05-03 01:22:18 +02:00
|
|
|
CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
|
2011-05-19 04:49:00 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinCFIEndProc(SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
if (CurFrame->ChainedParent)
|
|
|
|
getContext().reportError(Loc, "Not all chained regions terminated!");
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->End = Label;
|
2020-08-20 10:39:25 +02:00
|
|
|
if (!CurFrame->FuncletOrFuncEnd)
|
|
|
|
CurFrame->FuncletOrFuncEnd = CurFrame->End;
|
2020-11-13 21:35:22 +01:00
|
|
|
|
|
|
|
for (size_t I = CurrentProcWinFrameInfoStartIndex, E = WinFrameInfos.size();
|
|
|
|
I != E; ++I)
|
|
|
|
EmitWindowsUnwindTables(WinFrameInfos[I].get());
|
|
|
|
SwitchSection(CurFrame->TextSection);
|
2011-05-15 19:20:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-27 08:13:06 +02:00
|
|
|
void MCStreamer::EmitWinCFIFuncletOrFuncEnd(SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
if (CurFrame->ChainedParent)
|
|
|
|
getContext().reportError(Loc, "Not all chained regions terminated!");
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2018-10-27 08:13:06 +02:00
|
|
|
CurFrame->FuncletOrFuncEnd = Label;
|
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinCFIStartChained(SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *StartProc = emitCFILabel();
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2019-08-15 17:54:37 +02:00
|
|
|
WinFrameInfos.emplace_back(std::make_unique<WinEH::FrameInfo>(
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->Function, StartProc, CurFrame));
|
2017-10-06 19:21:49 +02:00
|
|
|
CurrentWinFrameInfo = WinFrameInfos.back().get();
|
2016-05-03 01:22:18 +02:00
|
|
|
CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
|
2011-05-18 22:54:10 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinCFIEndChained(SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
if (!CurFrame->ChainedParent)
|
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "End of a chained region outside a chained region!");
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->End = Label;
|
|
|
|
CurrentWinFrameInfo = const_cast<WinEH::FrameInfo *>(CurFrame->ChainedParent);
|
2011-05-18 22:54:10 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
|
|
|
|
SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
if (CurFrame->ChainedParent)
|
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "Chained unwind areas can't have handlers!");
|
|
|
|
CurFrame->ExceptionHandler = Sym;
|
2011-05-21 17:57:49 +02:00
|
|
|
if (!Except && !Unwind)
|
2017-10-10 03:26:25 +02:00
|
|
|
getContext().reportError(Loc, "Don't know what kind of handler this is!");
|
2011-05-21 17:57:49 +02:00
|
|
|
if (Unwind)
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->HandlesUnwind = true;
|
2011-05-21 17:57:49 +02:00
|
|
|
if (Except)
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->HandlesExceptions = true;
|
2011-05-19 19:46:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinEHHandlerData(SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
if (CurFrame->ChainedParent)
|
|
|
|
getContext().reportError(Loc, "Chained unwind areas can't have handlers!");
|
2011-05-18 22:54:10 +02:00
|
|
|
}
|
|
|
|
|
[MC] Add assembler support for .cg_profile.
Object FIle Representation
At codegen time this is emitted into the ELF file a pair of symbol indices and a weight. In assembly it looks like:
.cg_profile a, b, 32
.cg_profile freq, a, 11
.cg_profile freq, b, 20
When writing an ELF file these are put into a SHT_LLVM_CALL_GRAPH_PROFILE (0x6fff4c02) section as (uint32_t, uint32_t, uint64_t) tuples as (from symbol index, to symbol index, weight).
Differential Revision: https://reviews.llvm.org/D44965
llvm-svn: 333823
2018-06-02 18:33:01 +02:00
|
|
|
void MCStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
|
|
|
|
const MCSymbolRefExpr *To, uint64_t Count) {
|
|
|
|
}
|
|
|
|
|
2016-05-03 01:22:18 +02:00
|
|
|
static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
|
|
|
|
MCSection *MainCFISec,
|
|
|
|
const MCSection *TextSec) {
|
|
|
|
// If this is the main .text section, use the main unwind info section.
|
|
|
|
if (TextSec == Context.getObjectFileInfo()->getTextSection())
|
|
|
|
return MainCFISec;
|
|
|
|
|
|
|
|
const auto *TextSecCOFF = cast<MCSectionCOFF>(TextSec);
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-21 22:27:38 +02:00
|
|
|
auto *MainCFISecCOFF = cast<MCSectionCOFF>(MainCFISec);
|
2016-05-03 01:22:18 +02:00
|
|
|
unsigned UniqueID = TextSecCOFF->getOrAssignWinCFISectionID(NextWinCFIID);
|
|
|
|
|
|
|
|
// If this section is COMDAT, this unwind section should be COMDAT associative
|
|
|
|
// with its group.
|
|
|
|
const MCSymbol *KeySym = nullptr;
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-21 22:27:38 +02:00
|
|
|
if (TextSecCOFF->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
|
2016-05-03 01:22:18 +02:00
|
|
|
KeySym = TextSecCOFF->getCOMDATSymbol();
|
|
|
|
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-21 22:27:38 +02:00
|
|
|
// In a GNU environment, we can't use associative comdats. Instead, do what
|
|
|
|
// GCC does, which is to make plain comdat selectany section named like
|
|
|
|
// ".[px]data$_Z3foov".
|
|
|
|
if (!Context.getAsmInfo()->hasCOFFAssociativeComdats()) {
|
2020-04-16 00:49:05 +02:00
|
|
|
std::string SectionName = (MainCFISecCOFF->getName() + "$" +
|
|
|
|
TextSecCOFF->getName().split('$').second)
|
|
|
|
.str();
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-21 22:27:38 +02:00
|
|
|
return Context.getCOFFSection(
|
|
|
|
SectionName,
|
|
|
|
MainCFISecCOFF->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT,
|
|
|
|
MainCFISecCOFF->getKind(), "", COFF::IMAGE_COMDAT_SELECT_ANY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Context.getAssociativeCOFFSection(MainCFISecCOFF, KeySym, UniqueID);
|
2016-05-03 01:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MCSection *MCStreamer::getAssociatedPDataSection(const MCSection *TextSec) {
|
|
|
|
return getWinCFISection(getContext(), &NextWinCFIID,
|
|
|
|
getContext().getObjectFileInfo()->getPDataSection(),
|
|
|
|
TextSec);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCSection *MCStreamer::getAssociatedXDataSection(const MCSection *TextSec) {
|
|
|
|
return getWinCFISection(getContext(), &NextWinCFIID,
|
|
|
|
getContext().getObjectFileInfo()->getXDataSection(),
|
|
|
|
TextSec);
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitSyntaxDirective() {}
|
2015-07-22 12:49:44 +02:00
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
static unsigned encodeSEHRegNum(MCContext &Ctx, MCRegister Reg) {
|
|
|
|
return Ctx.getRegisterInfo()->getSEHRegNum(Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCStreamer::EmitWinCFIPushReg(MCRegister Register, SMLoc Loc) {
|
2017-10-10 03:26:25 +02:00
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
WinEH::Instruction Inst = Win64EH::Instruction::PushNonVol(
|
|
|
|
Label, encodeSEHRegNum(Context, Register));
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->Instructions.push_back(Inst);
|
2011-05-18 22:54:10 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
void MCStreamer::EmitWinCFISetFrame(MCRegister Register, unsigned Offset,
|
2017-10-10 03:26:25 +02:00
|
|
|
SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
if (CurFrame->LastFrameInst >= 0)
|
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "frame register and offset can be set at most once");
|
2011-05-22 02:56:20 +02:00
|
|
|
if (Offset & 0x0F)
|
2017-10-10 03:26:25 +02:00
|
|
|
return getContext().reportError(Loc, "offset is not a multiple of 16");
|
2014-06-25 14:41:52 +02:00
|
|
|
if (Offset > 240)
|
2017-10-10 03:26:25 +02:00
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "frame offset must be less than or equal to 240");
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
WinEH::Instruction Inst = Win64EH::Instruction::SetFPReg(
|
|
|
|
Label, encodeSEHRegNum(getContext(), Register), Offset);
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->LastFrameInst = CurFrame->Instructions.size();
|
|
|
|
CurFrame->Instructions.push_back(Inst);
|
2011-05-15 19:20:01 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2014-07-01 02:42:47 +02:00
|
|
|
if (Size == 0)
|
2017-10-10 03:26:25 +02:00
|
|
|
return getContext().reportError(Loc,
|
|
|
|
"stack allocation size must be non-zero");
|
2011-05-22 02:56:20 +02:00
|
|
|
if (Size & 7)
|
2017-10-10 03:26:25 +02:00
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "stack allocation size is not a multiple of 8");
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-07-17 05:08:50 +02:00
|
|
|
|
|
|
|
WinEH::Instruction Inst = Win64EH::Instruction::Alloc(Label, Size);
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->Instructions.push_back(Inst);
|
2011-05-15 19:20:01 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
void MCStreamer::EmitWinCFISaveReg(MCRegister Register, unsigned Offset,
|
2017-10-10 03:26:25 +02:00
|
|
|
SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
|
2011-05-22 02:56:20 +02:00
|
|
|
if (Offset & 7)
|
2017-10-10 03:26:25 +02:00
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "register save offset is not 8 byte aligned");
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
WinEH::Instruction Inst = Win64EH::Instruction::SaveNonVol(
|
|
|
|
Label, encodeSEHRegNum(Context, Register), Offset);
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->Instructions.push_back(Inst);
|
2011-05-15 19:20:01 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
void MCStreamer::EmitWinCFISaveXMM(MCRegister Register, unsigned Offset,
|
2017-10-10 03:26:25 +02:00
|
|
|
SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2011-05-22 02:56:20 +02:00
|
|
|
if (Offset & 0x0F)
|
2017-10-10 03:26:25 +02:00
|
|
|
return getContext().reportError(Loc, "offset is not a multiple of 16");
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2019-08-30 23:23:05 +02:00
|
|
|
WinEH::Instruction Inst = Win64EH::Instruction::SaveXMM(
|
|
|
|
Label, encodeSEHRegNum(Context, Register), Offset);
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->Instructions.push_back(Inst);
|
2011-05-15 19:20:01 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinCFIPushFrame(bool Code, SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
|
|
|
if (!CurFrame->Instructions.empty())
|
|
|
|
return getContext().reportError(
|
|
|
|
Loc, "If present, PushMachFrame must be the first UOP");
|
2014-07-17 05:08:50 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-07-17 05:08:50 +02:00
|
|
|
|
|
|
|
WinEH::Instruction Inst = Win64EH::Instruction::PushMachFrame(Label, Code);
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->Instructions.push_back(Inst);
|
2011-05-15 19:20:01 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
void MCStreamer::EmitWinCFIEndProlog(SMLoc Loc) {
|
|
|
|
WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
|
|
|
|
if (!CurFrame)
|
|
|
|
return;
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
MCSymbol *Label = emitCFILabel();
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2017-10-10 03:26:25 +02:00
|
|
|
CurFrame->PrologEnd = Label;
|
2011-05-16 23:13:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 19:42:31 +01:00
|
|
|
void MCStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {}
|
2015-05-30 06:56:02 +02:00
|
|
|
|
2018-01-10 00:49:30 +01:00
|
|
|
void MCStreamer::EmitCOFFSymbolIndex(MCSymbol const *Symbol) {}
|
|
|
|
|
2019-01-03 19:42:31 +01:00
|
|
|
void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {}
|
2013-12-20 19:15:00 +01:00
|
|
|
|
2017-01-02 04:00:19 +01:00
|
|
|
void MCStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) {}
|
2011-12-17 02:14:52 +01:00
|
|
|
|
2018-07-26 22:11:26 +02:00
|
|
|
void MCStreamer::EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) {}
|
|
|
|
|
2010-05-20 21:45:09 +02:00
|
|
|
/// EmitRawText - If this file is backed by an assembly streamer, this dumps
|
2010-04-03 23:35:55 +02:00
|
|
|
/// the specified string in the output .s file. This capability is
|
|
|
|
/// indicated by the hasRawTextSupport() predicate.
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitRawTextImpl(StringRef String) {
|
2019-01-03 19:42:31 +01:00
|
|
|
// This is not llvm_unreachable for the sake of out of tree backend
|
|
|
|
// developers who may not have assembly streamers and should serve as a
|
|
|
|
// reminder to not accidentally call EmitRawText in the absence of such.
|
|
|
|
report_fatal_error("EmitRawText called on an MCStreamer that doesn't support "
|
|
|
|
"it (target backend is likely missing an AsmStreamer "
|
|
|
|
"implementation)");
|
2010-04-03 23:35:55 +02:00
|
|
|
}
|
2010-04-04 00:12:35 +02:00
|
|
|
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitRawText(const Twine &T) {
|
2010-04-04 00:12:35 +02:00
|
|
|
SmallString<128> Str;
|
2020-02-15 17:52:56 +01:00
|
|
|
emitRawTextImpl(T.toStringRef(Str));
|
2010-04-04 00:12:35 +02:00
|
|
|
}
|
2011-05-10 05:14:15 +02:00
|
|
|
|
2016-10-11 00:49:37 +02:00
|
|
|
void MCStreamer::EmitWindowsUnwindTables() {
|
|
|
|
}
|
|
|
|
|
2020-11-13 21:35:22 +01:00
|
|
|
void MCStreamer::EmitWindowsUnwindTables(WinEH::FrameInfo *Frame) {
|
|
|
|
}
|
|
|
|
|
2020-11-11 15:27:01 +01:00
|
|
|
void MCStreamer::Finish(SMLoc EndLoc) {
|
2018-02-20 10:04:13 +01:00
|
|
|
if ((!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) ||
|
|
|
|
(!WinFrameInfos.empty() && !WinFrameInfos.back()->End)) {
|
2020-11-11 15:27:01 +01:00
|
|
|
getContext().reportError(EndLoc, "Unfinished frame!");
|
2018-02-20 10:04:13 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-01-07 04:13:18 +01:00
|
|
|
|
2014-02-01 00:10:26 +01:00
|
|
|
MCTargetStreamer *TS = getTargetStreamer();
|
|
|
|
if (TS)
|
|
|
|
TS->finish();
|
|
|
|
|
2020-04-21 04:28:13 +02:00
|
|
|
finishImpl();
|
2012-01-07 04:13:18 +01:00
|
|
|
}
|
2013-02-19 22:57:35 +01:00
|
|
|
|
2021-02-24 03:18:47 +01:00
|
|
|
void MCStreamer::maybeEmitDwarf64Mark() {
|
|
|
|
if (Context.getDwarfFormat() != dwarf::DWARF64)
|
|
|
|
return;
|
|
|
|
AddComment("DWARF64 Mark");
|
|
|
|
emitInt32(dwarf::DW_LENGTH_DWARF64);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCStreamer::emitDwarfUnitLength(uint64_t Length, const Twine &Comment) {
|
|
|
|
assert(Context.getDwarfFormat() == dwarf::DWARF64 ||
|
|
|
|
Length <= dwarf::DW_LENGTH_lo_reserved);
|
|
|
|
maybeEmitDwarf64Mark();
|
|
|
|
AddComment(Comment);
|
|
|
|
emitIntValue(Length, dwarf::getDwarfOffsetByteSize(Context.getDwarfFormat()));
|
|
|
|
}
|
|
|
|
|
2021-02-26 02:39:45 +01:00
|
|
|
MCSymbol *MCStreamer::emitDwarfUnitLength(const Twine &Prefix,
|
|
|
|
const Twine &Comment) {
|
2021-02-24 03:18:47 +01:00
|
|
|
maybeEmitDwarf64Mark();
|
|
|
|
AddComment(Comment);
|
2021-02-26 02:39:45 +01:00
|
|
|
MCSymbol *Lo = Context.createTempSymbol(Prefix + "_start");
|
|
|
|
MCSymbol *Hi = Context.createTempSymbol(Prefix + "_end");
|
|
|
|
|
2021-02-24 03:18:47 +01:00
|
|
|
emitAbsoluteSymbolDiff(
|
|
|
|
Hi, Lo, dwarf::getDwarfOffsetByteSize(Context.getDwarfFormat()));
|
2021-02-26 02:39:45 +01:00
|
|
|
// emit the begin symbol after we generate the length field.
|
|
|
|
emitLabel(Lo);
|
|
|
|
// Return the Hi symbol to the caller.
|
|
|
|
return Hi;
|
2021-02-24 03:18:47 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 02:47:41 +01:00
|
|
|
void MCStreamer::emitDwarfLineStartLabel(MCSymbol *StartSym) {
|
|
|
|
// Set the value of the symbol, as we are at the start of the line table.
|
|
|
|
emitLabel(StartSym);
|
|
|
|
}
|
|
|
|
|
2020-02-15 03:16:24 +01:00
|
|
|
void MCStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
|
2014-06-25 20:37:33 +02:00
|
|
|
visitUsedExpr(*Value);
|
2014-03-20 10:44:49 +01:00
|
|
|
Symbol->setVariableValue(Value);
|
|
|
|
|
|
|
|
MCTargetStreamer *TS = getTargetStreamer();
|
|
|
|
if (TS)
|
|
|
|
TS->emitAssignment(Symbol, Value);
|
|
|
|
}
|
2014-06-25 02:27:53 +02:00
|
|
|
|
2019-01-03 07:06:38 +01:00
|
|
|
void MCTargetStreamer::prettyPrintAsm(MCInstPrinter &InstPrinter,
|
2020-01-03 19:55:30 +01:00
|
|
|
uint64_t Address, const MCInst &Inst,
|
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
InstPrinter.printInst(&Inst, Address, "", STI, OS);
|
2015-06-18 22:43:22 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 17:45:33 +02:00
|
|
|
void MCStreamer::visitUsedSymbol(const MCSymbol &Sym) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCStreamer::visitUsedExpr(const MCExpr &Expr) {
|
|
|
|
switch (Expr.getKind()) {
|
|
|
|
case MCExpr::Target:
|
|
|
|
cast<MCTargetExpr>(Expr).visitUsedExpr(*this);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCExpr::Constant:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCExpr::Binary: {
|
|
|
|
const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr);
|
|
|
|
visitUsedExpr(*BE.getLHS());
|
|
|
|
visitUsedExpr(*BE.getRHS());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCExpr::SymbolRef:
|
|
|
|
visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCExpr::Unary:
|
|
|
|
visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void MCStreamer::emitInstruction(const MCInst &Inst, const MCSubtargetInfo &) {
|
2014-06-25 20:37:33 +02:00
|
|
|
// Scan for values.
|
|
|
|
for (unsigned i = Inst.getNumOperands(); i--;)
|
|
|
|
if (Inst.getOperand(i).isExpr())
|
|
|
|
visitUsedExpr(*Inst.getOperand(i).getExpr());
|
|
|
|
}
|
|
|
|
|
[CSSPGO] Pseudo probe encoding and emission.
This change implements pseudo probe encoding and emission for CSSPGO. Please see RFC here for more context: https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s
Pseudo probes are in the form of intrinsic calls on IR/MIR but they do not turn into any machine instructions. Instead they are emitted into the binary as a piece of data in standalone sections. The probe-specific sections are not needed to be loaded into memory at execution time, thus they do not incur a runtime overhead.
**ELF object emission**
The binary data to emit are organized as two ELF sections, i.e, the `.pseudo_probe_desc` section and the `.pseudo_probe` section. The `.pseudo_probe_desc` section stores a function descriptor for each function and the `.pseudo_probe` section stores the actual probes, each fo which corresponds to an IR basic block or an IR function callsite. A function descriptor is stored as a module-level metadata during the compilation and is serialized into the object file during object emission.
Both the probe descriptors and pseudo probes can be emitted into a separate ELF section per function to leverage the linker for deduplication. A `.pseudo_probe` section shares the same COMDAT group with the function code so that when the function is dead, the probes are dead and disposed too. On the contrary, a `.pseudo_probe_desc` section has its own COMDAT group. This is because even if a function is dead, its probes may be inlined into other functions and its descriptor is still needed by the profile generation tool.
The format of `.pseudo_probe_desc` section looks like:
```
.section .pseudo_probe_desc,"",@progbits
.quad 6309742469962978389 // Func GUID
.quad 4294967295 // Func Hash
.byte 9 // Length of func name
.ascii "_Z5funcAi" // Func name
.quad 7102633082150537521
.quad 138828622701
.byte 12
.ascii "_Z8funcLeafi"
.quad 446061515086924981
.quad 4294967295
.byte 9
.ascii "_Z5funcBi"
.quad -2016976694713209516
.quad 72617220756
.byte 7
.ascii "_Z3fibi"
```
For each `.pseudoprobe` section, the encoded binary data consists of a single function record corresponding to an outlined function (i.e, a function with a code entry in the `.text` section). A function record has the following format :
```
FUNCTION BODY (one for each outlined function present in the text section)
GUID (uint64)
GUID of the function
NPROBES (ULEB128)
Number of probes originating from this function.
NUM_INLINED_FUNCTIONS (ULEB128)
Number of callees inlined into this function, aka number of
first-level inlinees
PROBE RECORDS
A list of NPROBES entries. Each entry contains:
INDEX (ULEB128)
TYPE (uint4)
0 - block probe, 1 - indirect call, 2 - direct call
ATTRIBUTE (uint3)
reserved
ADDRESS_TYPE (uint1)
0 - code address, 1 - address delta
CODE_ADDRESS (uint64 or ULEB128)
code address or address delta, depending on ADDRESS_TYPE
INLINED FUNCTION RECORDS
A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined
callees. Each record contains:
INLINE SITE
GUID of the inlinee (uint64)
ID of the callsite probe (ULEB128)
FUNCTION BODY
A FUNCTION BODY entry describing the inlined function.
```
To support building a context-sensitive profile, probes from inlinees are grouped by their inline contexts. An inline context is logically a call path through which a callee function lands in a caller function. The probe emitter builds an inline tree based on the debug metadata for each outlined function in the form of a trie tree. A tree root is the outlined function. Each tree edge stands for a callsite where inlining happens. Pseudo probes originating from an inlinee function are stored in a tree node and the tree path starting from the root all the way down to the tree node is the inline context of the probes. The emission happens on the whole tree top-down recursively. Probes of a tree node will be emitted altogether with their direct parent edge. Since a pseudo probe corresponds to a real code address, for size savings, the address is encoded as a delta from the previous probe except for the first probe. Variant-sized integer encoding, aka LEB128, is used for address delta and probe index.
**Assembling**
Pseudo probes can be printed as assembly directives alternatively. This allows for good assembly code readability and also provides a view of how optimizations and pseudo probes affect each other, especially helpful for diff time assembly analysis.
A pseudo probe directive has the following operands in order: function GUID, probe index, probe type, probe attributes and inline context. The directive is generated by the compiler and can be parsed by the assembler to form an encoded `.pseudoprobe` section in the object file.
A example assembly looks like:
```
foo2: # @foo2
# %bb.0: # %bb0
pushq %rax
testl %edi, %edi
.pseudoprobe 837061429793323041 1 0 0
je .LBB1_1
# %bb.2: # %bb2
.pseudoprobe 837061429793323041 6 2 0
callq foo
.pseudoprobe 837061429793323041 3 0 0
.pseudoprobe 837061429793323041 4 0 0
popq %rax
retq
.LBB1_1: # %bb1
.pseudoprobe 837061429793323041 5 1 0
callq *%rsi
.pseudoprobe 837061429793323041 2 0 0
.pseudoprobe 837061429793323041 4 0 0
popq %rax
retq
# -- End function
.section .pseudo_probe_desc,"",@progbits
.quad 6699318081062747564
.quad 72617220756
.byte 3
.ascii "foo"
.quad 837061429793323041
.quad 281547593931412
.byte 4
.ascii "foo2"
```
With inlining turned on, the assembly may look different around %bb2 with an inlined probe:
```
# %bb.2: # %bb2
.pseudoprobe 837061429793323041 3 0
.pseudoprobe 6699318081062747564 1 0 @ 837061429793323041:6
.pseudoprobe 837061429793323041 4 0
popq %rax
retq
```
**Disassembling**
We have a disassembling tool (llvm-profgen) that can display disassembly alongside with pseudo probes. So far it only supports ELF executable file.
An example disassembly looks like:
```
00000000002011a0 <foo2>:
2011a0: 50 push rax
2011a1: 85 ff test edi,edi
[Probe]: FUNC: foo2 Index: 1 Type: Block
2011a3: 74 02 je 2011a7 <foo2+0x7>
[Probe]: FUNC: foo2 Index: 3 Type: Block
[Probe]: FUNC: foo2 Index: 4 Type: Block
[Probe]: FUNC: foo Index: 1 Type: Block Inlined: @ foo2:6
2011a5: 58 pop rax
2011a6: c3 ret
[Probe]: FUNC: foo2 Index: 2 Type: Block
2011a7: bf 01 00 00 00 mov edi,0x1
[Probe]: FUNC: foo2 Index: 5 Type: IndirectCall
2011ac: ff d6 call rsi
[Probe]: FUNC: foo2 Index: 4 Type: Block
2011ae: 58 pop rax
2011af: c3 ret
```
Reviewed By: wmi
Differential Revision: https://reviews.llvm.org/D91878
2020-12-09 00:37:32 +01:00
|
|
|
void MCStreamer::emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
|
|
|
|
uint64_t Attr,
|
|
|
|
const MCPseudoProbeInlineStack &InlineStack) {
|
|
|
|
auto &Context = getContext();
|
|
|
|
|
|
|
|
// Create a symbol at in the current section for use in the probe.
|
|
|
|
MCSymbol *ProbeSym = Context.createTempSymbol();
|
|
|
|
|
|
|
|
// Set the value of the symbol to use for the MCPseudoProbe.
|
|
|
|
emitLabel(ProbeSym);
|
|
|
|
|
|
|
|
// Create a (local) probe entry with the symbol.
|
|
|
|
MCPseudoProbe Probe(ProbeSym, Guid, Index, Type, Attr);
|
|
|
|
|
|
|
|
// Add the probe entry to this section's entries.
|
|
|
|
Context.getMCPseudoProbeTable().getProbeSections().addPseudoProbe(
|
|
|
|
getCurrentSectionOnly(), Probe, InlineStack);
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:58:08 +02:00
|
|
|
void MCStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
|
|
|
|
unsigned Size) {
|
|
|
|
// Get the Hi-Lo expression.
|
|
|
|
const MCExpr *Diff =
|
|
|
|
MCBinaryExpr::createSub(MCSymbolRefExpr::create(Hi, Context),
|
|
|
|
MCSymbolRefExpr::create(Lo, Context), Context);
|
|
|
|
|
|
|
|
const MCAsmInfo *MAI = Context.getAsmInfo();
|
2016-06-19 01:25:37 +02:00
|
|
|
if (!MAI->doesSetDirectiveSuppressReloc()) {
|
2020-02-15 07:40:47 +01:00
|
|
|
emitValue(Diff, Size);
|
2015-06-11 20:58:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, emit with .set (aka assignment).
|
2020-12-21 23:04:13 +01:00
|
|
|
MCSymbol *SetLabel = Context.createTempSymbol("set");
|
2020-02-15 03:16:24 +01:00
|
|
|
emitAssignment(SetLabel, Diff);
|
2020-02-15 04:21:58 +01:00
|
|
|
emitSymbolValue(SetLabel, Size);
|
2015-06-11 20:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:00:25 +01:00
|
|
|
void MCStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
|
|
|
|
const MCSymbol *Lo) {
|
|
|
|
// Get the Hi-Lo expression.
|
|
|
|
const MCExpr *Diff =
|
|
|
|
MCBinaryExpr::createSub(MCSymbolRefExpr::create(Hi, Context),
|
|
|
|
MCSymbolRefExpr::create(Lo, Context), Context);
|
|
|
|
|
2020-02-13 22:26:21 +01:00
|
|
|
emitULEB128Value(Diff);
|
2018-02-09 18:00:25 +01:00
|
|
|
}
|
|
|
|
|
2020-02-15 03:16:24 +01:00
|
|
|
void MCStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {}
|
|
|
|
void MCStreamer::emitThumbFunc(MCSymbol *Func) {}
|
|
|
|
void MCStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
|
2017-02-27 23:44:37 +01:00
|
|
|
void MCStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
|
|
|
|
llvm_unreachable("this directive only supported on COFF targets");
|
|
|
|
}
|
|
|
|
void MCStreamer::EndCOFFSymbolDef() {
|
|
|
|
llvm_unreachable("this directive only supported on COFF targets");
|
|
|
|
}
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitFileDirective(StringRef Filename) {}
|
2017-02-27 23:44:37 +01:00
|
|
|
void MCStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
|
|
|
|
llvm_unreachable("this directive only supported on COFF targets");
|
|
|
|
}
|
|
|
|
void MCStreamer::EmitCOFFSymbolType(int Type) {
|
|
|
|
llvm_unreachable("this directive only supported on COFF targets");
|
|
|
|
}
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
|
[XCOFF][AIX] Differentiate usage of label symbol and csect symbol
Summary:
We are using symbols to represent label and csect interchangeably before, and that could be a problem.
There are cases we would need to add storage mapping class to the symbol if that symbol is actually the name of a csect, but it's hard for us to figure out whether that symbol is a label or csect.
This patch intend to do the following:
1. Construct a QualName (A name include the storage mapping class)
MCSymbolXCOFF for every MCSectionXCOFF.
2. Keep a pointer to that QualName inside of MCSectionXCOFF.
3. Use that QualName whenever we need a symbol refers to that
MCSectionXCOFF.
4. Adapt the snowball effect from the above changes in
XCOFFObjectWriter.cpp.
Reviewers: xingxue, DiggerLin, sfertile, daltenty, hubert.reinterpretcast
Reviewed By: DiggerLin, daltenty
Subscribers: wuzish, nemanjai, mgorny, hiraditya, kbarton, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69633
2019-11-08 15:26:28 +01:00
|
|
|
MCSymbol *CsectSym,
|
Enable assembly output of local commons for AIX
Summary:
This patch enable assembly output of local commons for AIX using .lcomm
directives. Adds a EmitXCOFFLocalCommonSymbol to MCStreamer so we can emit the
AIX version of .lcomm assembly directives which include a csect name. Handle the
case of BSS locals in PPCAIXAsmPrinter by using EmitXCOFFLocalCommonSymbol. Adds
a test for generating .lcomm on AIX Targets.
Reviewers: cebowleratibm, hubert.reinterpretcast, Xiangling_L, jasonliu, sfertile
Reviewed By: sfertile
Subscribers: wuzish, nemanjai, hiraditya, kbarton, MaskRay, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64825
llvm-svn: 368306
2019-08-08 17:40:35 +02:00
|
|
|
unsigned ByteAlign) {
|
|
|
|
llvm_unreachable("this directive only supported on XCOFF targets");
|
|
|
|
}
|
[AIX] supporting the visibility attribute for aix assembly
SUMMARY:
in the aix assembly , it do not have .hidden and .protected directive.
in current llvm. if a function or a variable which has visibility attribute, it will generate something like the .hidden or .protected , it can not recognize by aix as.
in aix assembly, the visibility attribute are support in the pseudo-op like
.extern Name [ , Visibility ]
.globl Name [, Visibility ]
.weak Name [, Visibility ]
in this patch, we implement the visibility attribute for the global variable, function or extern function .
for example.
extern __attribute__ ((visibility ("hidden"))) int
bar(int* ip);
__attribute__ ((visibility ("hidden"))) int b = 0;
__attribute__ ((visibility ("hidden"))) int
foo(int* ip){
return (*ip)++;
}
the visibility of .comm linkage do not support , we will have a separate patch for it.
we have the unsupported cases ("default" and "internal") , we will implement them in a a separate patch for it.
Reviewers: Jason Liu ,hubert.reinterpretcast,James Henderson
Differential Revision: https://reviews.llvm.org/D75866
2020-06-09 22:15:06 +02:00
|
|
|
|
|
|
|
void MCStreamer::emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
|
|
|
|
MCSymbolAttr Linkage,
|
|
|
|
MCSymbolAttr Visibility) {
|
|
|
|
llvm_unreachable("emitXCOFFSymbolLinkageWithVisibility is only supported on "
|
|
|
|
"XCOFF targets");
|
|
|
|
}
|
|
|
|
|
2020-07-06 16:18:06 +02:00
|
|
|
void MCStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,
|
|
|
|
StringRef Rename) {
|
|
|
|
llvm_unreachable("emitXCOFFRenameDirective is only supported on "
|
|
|
|
"XCOFF targets");
|
|
|
|
}
|
|
|
|
|
2016-12-02 00:39:08 +01:00
|
|
|
void MCStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
|
[MC] Support .symver *, *, remove
As a resolution to https://sourceware.org/bugzilla/show_bug.cgi?id=25295 , GNU as
from binutils 2.35 supports the optional third argument for the .symver directive.
'remove' for a non-default version is useful:
`.symver def_v1, def@v1, remove` => def_v1 is not retained in the symbol table.
Previously the user has to strip the original symbol or specify a `local:`
version node in a version script to localize the symbol.
`.symver def, def@@v1, remove` and `.symver def, def@@@v1, remove` are supported
as well, though they are identical to `.symver def, def@@@v1`.
local/hidden are not useful so this patch does not implement them.
2021-03-07 00:23:02 +01:00
|
|
|
void MCStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
|
|
|
|
StringRef Name, bool KeepOriginalSym) {}
|
2020-02-15 03:16:24 +01:00
|
|
|
void MCStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
2014-06-25 02:27:53 +02:00
|
|
|
unsigned ByteAlignment) {}
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
|
2014-06-25 02:27:53 +02:00
|
|
|
uint64_t Size, unsigned ByteAlignment) {}
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::changeSection(MCSection *, const MCExpr *) {}
|
2020-02-15 03:16:24 +01:00
|
|
|
void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
|
|
|
|
void MCStreamer::emitBytes(StringRef Data) {}
|
|
|
|
void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); }
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
|
2014-06-25 20:37:33 +02:00
|
|
|
visitUsedExpr(*Value);
|
|
|
|
}
|
2020-02-13 22:26:21 +01:00
|
|
|
void MCStreamer::emitULEB128Value(const MCExpr *Value) {}
|
|
|
|
void MCStreamer::emitSLEB128Value(const MCExpr *Value) {}
|
2016-05-28 07:57:48 +02:00
|
|
|
void MCStreamer::emitFill(const MCExpr &NumBytes, uint64_t Value, SMLoc Loc) {}
|
|
|
|
void MCStreamer::emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
|
|
|
|
SMLoc Loc) {}
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitValueToAlignment(unsigned ByteAlignment, int64_t Value,
|
2014-06-25 02:27:53 +02:00
|
|
|
unsigned ValueSize,
|
|
|
|
unsigned MaxBytesToEmit) {}
|
2020-02-15 04:21:58 +01:00
|
|
|
void MCStreamer::emitCodeAlignment(unsigned ByteAlignment,
|
2014-06-25 02:27:53 +02:00
|
|
|
unsigned MaxBytesToEmit) {}
|
2016-12-14 11:43:58 +01:00
|
|
|
void MCStreamer::emitValueToOffset(const MCExpr *Offset, unsigned char Value,
|
|
|
|
SMLoc Loc) {}
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitBundleAlignMode(unsigned AlignPow2) {}
|
|
|
|
void MCStreamer::emitBundleLock(bool AlignToEnd) {}
|
2020-04-21 04:28:13 +02:00
|
|
|
void MCStreamer::finishImpl() {}
|
2020-02-15 17:52:56 +01:00
|
|
|
void MCStreamer::emitBundleUnlock() {}
|
2015-03-10 22:35:16 +01:00
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
void MCStreamer::SwitchSection(MCSection *Section, const MCExpr *Subsection) {
|
2015-03-10 22:35:16 +01:00
|
|
|
assert(Section && "Cannot switch to a null section!");
|
|
|
|
MCSectionSubPair curSection = SectionStack.back().first;
|
|
|
|
SectionStack.back().second = curSection;
|
|
|
|
if (MCSectionSubPair(Section, Subsection) != curSection) {
|
2020-04-21 04:28:13 +02:00
|
|
|
changeSection(Section, Subsection);
|
2015-03-10 22:35:16 +01:00
|
|
|
SectionStack.back().first = MCSectionSubPair(Section, Subsection);
|
2015-03-23 22:22:04 +01:00
|
|
|
assert(!Section->hasEnded() && "Section already ended");
|
2015-03-11 01:51:37 +01:00
|
|
|
MCSymbol *Sym = Section->getBeginSymbol();
|
|
|
|
if (Sym && !Sym->isInSection())
|
2020-02-15 04:21:58 +01:00
|
|
|
emitLabel(Sym);
|
2015-03-10 22:35:16 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-23 22:22:04 +01:00
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
MCSymbol *MCStreamer::endSection(MCSection *Section) {
|
2015-03-23 22:22:04 +01:00
|
|
|
// TODO: keep track of the last subsection so that this symbol appears in the
|
|
|
|
// correct place.
|
|
|
|
MCSymbol *Sym = Section->getEndSymbol(Context);
|
|
|
|
if (Sym->isInSection())
|
|
|
|
return Sym;
|
|
|
|
|
|
|
|
SwitchSection(Section);
|
2020-02-15 04:21:58 +01:00
|
|
|
emitLabel(Sym);
|
2015-03-23 22:22:04 +01:00
|
|
|
return Sym;
|
|
|
|
}
|
2017-12-14 04:59:24 +01:00
|
|
|
|
2020-06-30 06:04:25 +02:00
|
|
|
static VersionTuple
|
|
|
|
targetVersionOrMinimumSupportedOSVersion(const Triple &Target,
|
|
|
|
VersionTuple TargetVersion) {
|
|
|
|
VersionTuple Min = Target.getMinimumSupportedOSVersion();
|
|
|
|
return !Min.empty() && Min > TargetVersion ? Min : TargetVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCVersionMinType
|
|
|
|
getMachoVersionMinLoadCommandType(const Triple &Target) {
|
|
|
|
assert(Target.isOSDarwin() && "expected a darwin OS");
|
|
|
|
switch (Target.getOS()) {
|
|
|
|
case Triple::MacOSX:
|
|
|
|
case Triple::Darwin:
|
|
|
|
return MCVM_OSXVersionMin;
|
|
|
|
case Triple::IOS:
|
|
|
|
assert(!Target.isMacCatalystEnvironment() &&
|
|
|
|
"mac Catalyst should use LC_BUILD_VERSION");
|
|
|
|
return MCVM_IOSVersionMin;
|
|
|
|
case Triple::TvOS:
|
|
|
|
return MCVM_TvOSVersionMin;
|
|
|
|
case Triple::WatchOS:
|
|
|
|
return MCVM_WatchOSVersionMin;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unexpected OS type");
|
|
|
|
}
|
|
|
|
|
|
|
|
static VersionTuple getMachoBuildVersionSupportedOS(const Triple &Target) {
|
|
|
|
assert(Target.isOSDarwin() && "expected a darwin OS");
|
|
|
|
switch (Target.getOS()) {
|
|
|
|
case Triple::MacOSX:
|
|
|
|
case Triple::Darwin:
|
|
|
|
return VersionTuple(10, 14);
|
|
|
|
case Triple::IOS:
|
|
|
|
// Mac Catalyst always uses the build version load command.
|
|
|
|
if (Target.isMacCatalystEnvironment())
|
|
|
|
return VersionTuple();
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case Triple::TvOS:
|
|
|
|
return VersionTuple(12);
|
|
|
|
case Triple::WatchOS:
|
|
|
|
return VersionTuple(5);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unexpected OS type");
|
|
|
|
}
|
|
|
|
|
|
|
|
static MachO::PlatformType
|
|
|
|
getMachoBuildVersionPlatformType(const Triple &Target) {
|
|
|
|
assert(Target.isOSDarwin() && "expected a darwin OS");
|
|
|
|
switch (Target.getOS()) {
|
|
|
|
case Triple::MacOSX:
|
|
|
|
case Triple::Darwin:
|
|
|
|
return MachO::PLATFORM_MACOS;
|
|
|
|
case Triple::IOS:
|
|
|
|
if (Target.isMacCatalystEnvironment())
|
|
|
|
return MachO::PLATFORM_MACCATALYST;
|
|
|
|
return Target.isSimulatorEnvironment() ? MachO::PLATFORM_IOSSIMULATOR
|
|
|
|
: MachO::PLATFORM_IOS;
|
|
|
|
case Triple::TvOS:
|
|
|
|
return Target.isSimulatorEnvironment() ? MachO::PLATFORM_TVOSSIMULATOR
|
|
|
|
: MachO::PLATFORM_TVOS;
|
|
|
|
case Triple::WatchOS:
|
|
|
|
return Target.isSimulatorEnvironment() ? MachO::PLATFORM_WATCHOSSIMULATOR
|
|
|
|
: MachO::PLATFORM_WATCHOS;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unexpected OS type");
|
|
|
|
}
|
|
|
|
|
2020-02-15 03:16:24 +01:00
|
|
|
void MCStreamer::emitVersionForTarget(const Triple &Target,
|
2018-12-14 02:14:10 +01:00
|
|
|
const VersionTuple &SDKVersion) {
|
2017-12-14 04:59:24 +01:00
|
|
|
if (!Target.isOSBinFormatMachO() || !Target.isOSDarwin())
|
|
|
|
return;
|
|
|
|
// Do we even know the version?
|
|
|
|
if (Target.getOSMajorVersion() == 0)
|
|
|
|
return;
|
|
|
|
|
2020-06-30 06:04:25 +02:00
|
|
|
unsigned Major = 0;
|
|
|
|
unsigned Minor = 0;
|
|
|
|
unsigned Update = 0;
|
|
|
|
switch (Target.getOS()) {
|
|
|
|
case Triple::MacOSX:
|
|
|
|
case Triple::Darwin:
|
|
|
|
Target.getMacOSXVersion(Major, Minor, Update);
|
|
|
|
break;
|
|
|
|
case Triple::IOS:
|
|
|
|
case Triple::TvOS:
|
2019-07-03 01:47:11 +02:00
|
|
|
Target.getiOSVersion(Major, Minor, Update);
|
2020-06-30 06:04:25 +02:00
|
|
|
break;
|
|
|
|
case Triple::WatchOS:
|
2017-12-14 04:59:24 +01:00
|
|
|
Target.getWatchOSVersion(Major, Minor, Update);
|
2020-06-30 06:04:25 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unexpected OS type");
|
2017-12-14 04:59:24 +01:00
|
|
|
}
|
2020-06-30 06:04:25 +02:00
|
|
|
assert(Major != 0 && "A non-zero major version is expected");
|
|
|
|
auto LinkedTargetVersion = targetVersionOrMinimumSupportedOSVersion(
|
|
|
|
Target, VersionTuple(Major, Minor, Update));
|
|
|
|
auto BuildVersionOSVersion = getMachoBuildVersionSupportedOS(Target);
|
|
|
|
if (BuildVersionOSVersion.empty() ||
|
|
|
|
LinkedTargetVersion >= BuildVersionOSVersion)
|
|
|
|
return emitBuildVersion(getMachoBuildVersionPlatformType(Target),
|
|
|
|
LinkedTargetVersion.getMajor(),
|
|
|
|
*LinkedTargetVersion.getMinor(),
|
|
|
|
*LinkedTargetVersion.getSubminor(), SDKVersion);
|
|
|
|
|
|
|
|
emitVersionMin(getMachoVersionMinLoadCommandType(Target),
|
|
|
|
LinkedTargetVersion.getMajor(),
|
|
|
|
*LinkedTargetVersion.getMinor(),
|
|
|
|
*LinkedTargetVersion.getSubminor(), SDKVersion);
|
2017-12-14 04:59:24 +01:00
|
|
|
}
|