1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_BASE_H_
#define V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_BASE_H_
#include <cinttypes>
#include <cstdio> // For FILE.
#include <memory>
#include "src/flags/flags.h" // For ENABLE_CONTROL_FLOW_INTEGRITY_BOOL
namespace v8 {
namespace internal {
class EmbeddedData;
enum DataDirective {
kByte,
kLong,
kQuad,
kOcta,
};
DataDirective PointerSizeDirective();
int DataDirectiveSize(DataDirective directive);
enum class EmbeddedTargetOs {
kAIX,
kChromeOS,
kFuchsia,
kMac,
kWin,
kStarboard,
kGeneric, // Everything not covered above falls in here.
};
enum class EmbeddedTargetArch {
kArm,
kArm64,
kIA32,
kX64,
kGeneric, // Everything not covered above falls in here.
};
// The platform-dependent logic for emitting assembly code for the generated
// embedded.S file.
class PlatformEmbeddedFileWriterBase {
public:
virtual ~PlatformEmbeddedFileWriterBase() = default;
void SetFile(FILE* fp) { fp_ = fp; }
FILE* fp() const { return fp_; }
virtual void SectionText() = 0;
virtual void SectionData() = 0;
virtual void SectionRoData() = 0;
virtual void AlignToCodeAlignment() = 0;
virtual void AlignToDataAlignment() = 0;
virtual void DeclareUint32(const char* name, uint32_t value) = 0;
virtual void DeclarePointerToSymbol(const char* name, const char* target) = 0;
virtual void DeclareSymbolGlobal(const char* name) = 0;
virtual void DeclareLabel(const char* name) = 0;
virtual void SourceInfo(int fileid, const char* filename, int line) = 0;
virtual void DeclareFunctionBegin(const char* name, uint32_t size) = 0;
virtual void DeclareFunctionEnd(const char* name) = 0;
// Returns the number of printed characters.
virtual int HexLiteral(uint64_t value);
virtual void Comment(const char* string) = 0;
virtual void Newline() { fprintf(fp_, "\n"); }
virtual void FilePrologue() = 0;
virtual void DeclareExternalFilename(int fileid, const char* filename) = 0;
virtual void FileEpilogue() = 0;
virtual int IndentedDataDirective(DataDirective directive) = 0;
virtual DataDirective ByteChunkDataDirective() const { return kOcta; }
virtual int WriteByteChunk(const uint8_t* data);
// This awkward interface works around the fact that unwind data emission
// is both high-level and platform-dependent. The former implies it should
// live in EmbeddedFileWriter, but code there should be platform-independent.
//
// Emits unwinding data on x64 Windows, and does nothing otherwise.
virtual void MaybeEmitUnwindData(const char* unwind_info_symbol,
const char* embedded_blob_data_symbol,
const EmbeddedData* blob,
const void* unwind_infos) {}
protected:
FILE* fp_ = nullptr;
};
// The factory function. Returns the appropriate platform-specific instance.
std::unique_ptr<PlatformEmbeddedFileWriterBase> NewPlatformEmbeddedFileWriter(
const char* target_arch, const char* target_os);
} // namespace internal
} // namespace v8
#endif // V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_BASE_H_
|