v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
platform-embedded-file-writer-generic.cc
Go to the documentation of this file.
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <algorithm>
8#include <cinttypes>
9
11
12namespace v8 {
13namespace internal {
14
15#define SYMBOL_PREFIX ""
16
17namespace {
18
19const char* DirectiveAsString(DataDirective directive) {
20 switch (directive) {
21 case kByte:
22 return ".byte";
23 case kLong:
24 return ".long";
25 case kQuad:
26 return ".quad";
27 case kOcta:
28 return ".octa";
29 }
31}
32
33} // namespace
34
37 fprintf(fp_, ".section .text.hot.embedded\n");
38 } else {
39 fprintf(fp_, ".section .text\n");
40 }
41}
42
44 fprintf(fp_, ".section .rodata\n");
45}
46
48 uint32_t value) {
50 DeclareLabel(name);
52 fprintf(fp_, "%d", value);
53 Newline();
54}
55
57 fprintf(fp_, ".global %s%s\n", SYMBOL_PREFIX, name);
58 // These symbols are not visible outside of the final binary, this allows for
59 // reduced binary size, and less work for the dynamic linker.
60 fprintf(fp_, ".hidden %s\n", name);
61}
62
64#if (V8_OS_ANDROID || V8_OS_LINUX) && \
65 (V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_ARM64)
66 // On these architectures and platforms, we remap the builtins, so need these
67 // to be aligned on a page boundary.
68 fprintf(fp_, ".balign 4096\n");
69#elif V8_TARGET_ARCH_X64
70 // On x64 use 64-bytes code alignment to allow 64-bytes loop header alignment.
71 static_assert(64 >= kCodeAlignment);
72 fprintf(fp_, ".balign 64\n");
73#elif V8_TARGET_ARCH_PPC64
74 // 64 byte alignment is needed on ppc64 to make sure p10 prefixed instructions
75 // don't cross 64-byte boundaries.
76 static_assert(64 >= kCodeAlignment);
77 fprintf(fp_, ".balign 64\n");
78#else
79 static_assert(32 >= kCodeAlignment);
80 fprintf(fp_, ".balign 32\n");
81#endif
82}
83
85#if (V8_OS_ANDROID || V8_OS_LINUX) && \
86 (V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_ARM64)
87 // Since the builtins are remapped, need to pad until the next page boundary.
88 fprintf(fp_, ".balign 4096\n");
89#endif
90}
91
93 // On Windows ARM64, s390, PPC and possibly more platforms, aligned load
94 // instructions are used to retrieve v8_Default_embedded_blob_ and/or
95 // v8_Default_embedded_blob_size_. The generated instructions require the
96 // load target to be aligned at 8 bytes (2^3).
97 static_assert(8 >= InstructionStream::kMetadataAlignment);
98 fprintf(fp_, ".balign 8\n");
99}
100
102 fprintf(fp_, "// %s\n", string);
103}
104
106 fprintf(fp_, "%s%s:\n", SYMBOL_PREFIX, name);
107}
108
110 const char* filename,
111 int line) {
112 fprintf(fp_, ".loc %d %d\n", fileid, line);
113}
114
116 uint32_t size) {
117#if V8_ENABLE_DRUMBRAKE
118 if (IsDrumBrakeInstructionHandler(name)) {
120 }
121#endif // V8_ENABLE_DRUMBRAKE
122
123 DeclareLabel(name);
124
127 // ELF format binaries on ARM use ".type <function name>, %function"
128 // to create a DWARF subprogram entry.
129 fprintf(fp_, ".type %s, %%function\n", name);
130 } else {
131 // Other ELF Format binaries use ".type <function name>, @function"
132 // to create a DWARF subprogram entry.
133 fprintf(fp_, ".type %s, @function\n", name);
134 }
135 fprintf(fp_, ".size %s, %u\n", name, size);
136}
137
139
141
143 int fileid, const char* filename) {
144 // Replace any Windows style paths (backslashes) with forward
145 // slashes.
146 std::string fixed_filename(filename);
147 std::replace(fixed_filename.begin(), fixed_filename.end(), '\\', '/');
148 fprintf(fp_, ".file %d \"%s\"\n", fileid, fixed_filename.c_str());
149}
150
152 // Omitting this section can imply an executable stack, which is usually
153 // a linker warning/error. C++ compilers add these automatically, but
154 // compiling assembly requires the .note.GNU-stack section to be inserted
155 // manually.
156 // Additional documentation:
157 // https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
158 fprintf(fp_, ".section .note.GNU-stack,\"\",%%progbits\n");
159}
160
162 DataDirective directive) {
163 return fprintf(fp_, " %s ", DirectiveAsString(directive));
164}
165
167 const {
168#if defined(V8_TARGET_ARCH_MIPS64) || defined(V8_TARGET_ARCH_LOONG64)
169 // MIPS and LOONG64 uses a fixed 4 byte instruction set, using .long
170 // to prevent any unnecessary padding.
171 return kLong;
172#else
173 // Other ISAs just listen to the base
175#endif
176}
177
178#undef SYMBOL_PREFIX
179
180} // namespace internal
181} // namespace v8
static constexpr int kMetadataAlignment
void DeclareFunctionBegin(const char *name, uint32_t size) override
void DeclareExternalFilename(int fileid, const char *filename) override
void DeclareUint32(const char *name, uint32_t value) override
void SourceInfo(int fileid, const char *filename, int line) override
std::string filename
constexpr intptr_t kCodeAlignment
Definition globals.h:964