From c70a9439a091c6026c500d79be4b5f0afb0ab911 Mon Sep 17 00:00:00 2001 From: barracuda156 Date: Fri, 10 Nov 2023 11:40:20 +0800 Subject: [PATCH 09/12] embedded-file-writer-mac: support powerpc --- .../platform-embedded-file-writer-mac.cc | 40 ++++++++++++++++++- .../platform-embedded-file-writer-mac.h | 5 +++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/snapshot/embedded/platform-embedded-file-writer-mac.cc b/src/snapshot/embedded/platform-embedded-file-writer-mac.cc index 234f8a1f485..f27966eba86 100644 --- a/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.cc +++ b/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.cc @@ -17,8 +17,10 @@ const char* DirectiveAsString(DataDirective directive) { return ".long"; case kQuad: return ".quad"; +#ifndef __POWERPC__ case kOcta: return ".octa"; +#endif } UNREACHABLE(); } @@ -50,23 +52,40 @@ void PlatformEmbeddedFileWriterMac::DeclarePointerToSymbol(const char* name, } void PlatformEmbeddedFileWriterMac::DeclareSymbolGlobal(const char* name) { +#ifdef __POWERPC__ + // Follow AIX here. + fprintf(fp_, ".globl _%s\n", name); +#else // 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); +#endif } void PlatformEmbeddedFileWriterMac::AlignToCodeAlignment() { +#ifdef __POWERPC__ + fprintf(fp_, ".align 5\n"); +#else fprintf(fp_, ".balign 32\n"); +#endif } void PlatformEmbeddedFileWriterMac::AlignToDataAlignment() { +#ifdef __POWERPC__ + fprintf(fp_, ".align 3\n"); +#else fprintf(fp_, ".balign 8\n"); +#endif } void PlatformEmbeddedFileWriterMac::Comment(const char* string) { +#ifdef __POWERPC__ + fprintf(fp_, "; %s\n", string); +#else fprintf(fp_, "// %s\n", string); +#endif } void PlatformEmbeddedFileWriterMac::DeclareLabel(const char* name) { @@ -75,14 +94,17 @@ void PlatformEmbeddedFileWriterMac::DeclareLabel(const char* name) { void PlatformEmbeddedFileWriterMac::SourceInfo(int fileid, const char* filename, int line) { +#ifdef __POWERPC__ + fprintf(fp_, ".line %d, \"%s\"\n", line, filename); +#else fprintf(fp_, ".loc %d %d\n", fileid, line); +#endif } // TODO(mmarchini): investigate emitting size annotations for OS X void PlatformEmbeddedFileWriterMac::DeclareFunctionBegin(const char* name, uint32_t size) { DeclareLabel(name); - // TODO(mvstanton): Investigate the proper incantations to mark the label as // a function on OSX. } @@ -107,5 +129,21 @@ int PlatformEmbeddedFileWriterMac::IndentedDataDirective( return fprintf(fp_, " %s ", DirectiveAsString(directive)); } +#ifdef __POWERPC__ + +DataDirective PlatformEmbeddedFileWriterMac::ByteChunkDataDirective() const { + // PPC uses a fixed 4 byte instruction set, using .long + // to prevent any unnecessary padding. + return kLong; +} + +int PlatformEmbeddedFileWriterMac::WriteByteChunk(const uint8_t* data) { + DCHECK_EQ(ByteChunkDataDirective(), kLong); + const uint32_t* long_ptr = reinterpret_cast(data); + return HexLiteral(*long_ptr); +} + +#endif // __POWERPC__ + } // namespace internal } // namespace v8 diff --git a/src/snapshot/embedded/platform-embedded-file-writer-mac.h b/src/snapshot/embedded/platform-embedded-file-writer-mac.h index 76780d75f36..d69225ec3d7 100644 --- a/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.h +++ b/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.h @@ -47,6 +47,11 @@ class PlatformEmbeddedFileWriterMac : public PlatformEmbeddedFileWriterBase { int IndentedDataDirective(DataDirective directive) override; +#ifdef __POWERPC__ + DataDirective ByteChunkDataDirective() const override; + int WriteByteChunk(const uint8_t* data) override; +#endif + private: void DeclareSymbolGlobal(const char* name);