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
110
111
|
// 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.
#include "src/snapshot/embedded/platform-embedded-file-writer-mac.h"
namespace v8 {
namespace internal {
namespace {
const char* DirectiveAsString(DataDirective directive) {
switch (directive) {
case kByte:
return ".byte";
case kLong:
return ".long";
case kQuad:
return ".quad";
case kOcta:
return ".octa";
}
UNREACHABLE();
}
} // namespace
void PlatformEmbeddedFileWriterMac::SectionText() { fprintf(fp_, ".text\n"); }
void PlatformEmbeddedFileWriterMac::SectionData() { fprintf(fp_, ".data\n"); }
void PlatformEmbeddedFileWriterMac::SectionRoData() {
fprintf(fp_, ".const_data\n");
}
void PlatformEmbeddedFileWriterMac::DeclareUint32(const char* name,
uint32_t value) {
DeclareSymbolGlobal(name);
DeclareLabel(name);
IndentedDataDirective(kLong);
fprintf(fp_, "%d", value);
Newline();
}
void PlatformEmbeddedFileWriterMac::DeclarePointerToSymbol(const char* name,
const char* target) {
DeclareSymbolGlobal(name);
DeclareLabel(name);
fprintf(fp_, " %s _%s\n", DirectiveAsString(PointerSizeDirective()), target);
}
void PlatformEmbeddedFileWriterMac::DeclareSymbolGlobal(const char* name) {
// TODO(jgruber): Investigate switching to .globl. Using .private_extern
// prevents something along the compilation chain from messing with the
// embedded blob. Using .global here causes embedded blob hash verification
// failures at runtime.
fprintf(fp_, ".private_extern _%s\n", name);
}
void PlatformEmbeddedFileWriterMac::AlignToCodeAlignment() {
fprintf(fp_, ".balign 32\n");
}
void PlatformEmbeddedFileWriterMac::AlignToDataAlignment() {
fprintf(fp_, ".balign 8\n");
}
void PlatformEmbeddedFileWriterMac::Comment(const char* string) {
fprintf(fp_, "// %s\n", string);
}
void PlatformEmbeddedFileWriterMac::DeclareLabel(const char* name) {
fprintf(fp_, "_%s:\n", name);
}
void PlatformEmbeddedFileWriterMac::SourceInfo(int fileid, const char* filename,
int line) {
fprintf(fp_, ".loc %d %d\n", fileid, line);
}
// TODO(mmarchini): investigate emitting size annotations for OS X
void PlatformEmbeddedFileWriterMac::DeclareFunctionBegin(const char* name,
uint32_t size) {
if (ENABLE_CONTROL_FLOW_INTEGRITY_BOOL) {
DeclareSymbolGlobal(name);
}
DeclareLabel(name);
// TODO(mvstanton): Investigate the proper incantations to mark the label as
// a function on OSX.
}
void PlatformEmbeddedFileWriterMac::DeclareFunctionEnd(const char* name) {}
void PlatformEmbeddedFileWriterMac::FilePrologue() {}
void PlatformEmbeddedFileWriterMac::DeclareExternalFilename(
int fileid, const char* filename) {
fprintf(fp_, ".file %d \"%s\"\n", fileid, filename);
}
void PlatformEmbeddedFileWriterMac::FileEpilogue() {}
int PlatformEmbeddedFileWriterMac::IndentedDataDirective(
DataDirective directive) {
return fprintf(fp_, " %s ", DirectiveAsString(directive));
}
} // namespace internal
} // namespace v8
|