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