From 58bbae335e8d70b83040a30aaa5ac6d0bc0eb061 Mon Sep 17 00:00:00 2001 From: Openkylin Developers Date: Tue, 16 Aug 2022 11:14:23 +0800 Subject: [PATCH] upstream mips fix Origin: https://github.com/nodejs/node/issues/31118 Last-Update: 2020-05-30 Gbp-Pq: Name mips-fix.patch --- deps/v8/AUTHORS | 1 + .../platform-embedded-file-writer-aix.cc | 10 ----- .../platform-embedded-file-writer-aix.h | 3 -- .../platform-embedded-file-writer-base.cc | 41 +++++++++++++------ .../platform-embedded-file-writer-base.h | 2 +- .../platform-embedded-file-writer-generic.cc | 16 ++++++-- .../platform-embedded-file-writer-generic.h | 4 +- .../platform-embedded-file-writer-mac.cc | 4 -- .../platform-embedded-file-writer-mac.h | 2 - 9 files changed, 45 insertions(+), 38 deletions(-) diff --git a/deps/v8/AUTHORS b/deps/v8/AUTHORS index 1198de8f..632ec59a 100644 --- a/deps/v8/AUTHORS +++ b/deps/v8/AUTHORS @@ -106,6 +106,7 @@ James Pike James M Snell Jianghua Yang Jiawen Geng +Jiaxun Yang Joel Stanley Johan Bergström Jonathan Liu diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.cc b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.cc index 3aef77e3..7a068c70 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.cc +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.cc @@ -94,10 +94,6 @@ void PlatformEmbeddedFileWriterAIX::DeclareFunctionBegin(const char* name) { void PlatformEmbeddedFileWriterAIX::DeclareFunctionEnd(const char* name) {} -int PlatformEmbeddedFileWriterAIX::HexLiteral(uint64_t value) { - return fprintf(fp_, "0x%" PRIx64, value); -} - void PlatformEmbeddedFileWriterAIX::FilePrologue() {} void PlatformEmbeddedFileWriterAIX::DeclareExternalFilename( @@ -120,12 +116,6 @@ DataDirective PlatformEmbeddedFileWriterAIX::ByteChunkDataDirective() const { return kLong; } -int PlatformEmbeddedFileWriterAIX::WriteByteChunk(const uint8_t* data) { - DCHECK_EQ(ByteChunkDataDirective(), kLong); - const uint32_t* long_ptr = reinterpret_cast(data); - return HexLiteral(*long_ptr); -} - #undef SYMBOL_PREFIX } // namespace internal diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.h b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.h index 6119d506..94a3273e 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.h +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.h @@ -37,8 +37,6 @@ class PlatformEmbeddedFileWriterAIX : public PlatformEmbeddedFileWriterBase { void DeclareFunctionBegin(const char* name) override; void DeclareFunctionEnd(const char* name) override; - int HexLiteral(uint64_t value) override; - void Comment(const char* string) override; void FilePrologue() override; @@ -48,7 +46,6 @@ class PlatformEmbeddedFileWriterAIX : public PlatformEmbeddedFileWriterBase { int IndentedDataDirective(DataDirective directive) override; DataDirective ByteChunkDataDirective() const override; - int WriteByteChunk(const uint8_t* data) override; private: void DeclareSymbolGlobal(const char* name); diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc index a17f039f..a0d84212 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc @@ -24,6 +24,10 @@ DataDirective PointerSizeDirective() { } } +int PlatformEmbeddedFileWriterBase::HexLiteral(uint64_t value) { + return fprintf(fp_, "0x%" PRIx64, value); +} + int DataDirectiveSize(DataDirective directive) { switch (directive) { case kByte: @@ -39,24 +43,37 @@ int DataDirectiveSize(DataDirective directive) { } int PlatformEmbeddedFileWriterBase::WriteByteChunk(const uint8_t* data) { - DCHECK_EQ(ByteChunkDataDirective(), kOcta); + size_t kSize = DataDirectiveSize(ByteChunkDataDirective()); + size_t kHalfSize = kSize / 2; + uint64_t high = 0, low = 0; - static constexpr size_t kSize = kInt64Size; - - uint64_t part1, part2; - // Use memcpy for the reads since {data} is not guaranteed to be aligned. + switch (kSize) { + case 1: + low = *data; + break; + case 4: + low = *reinterpret_cast(data); + break; + case 8: + low = *reinterpret_cast(data); + break; + case 16: #ifdef V8_TARGET_BIG_ENDIAN - memcpy(&part1, data, kSize); - memcpy(&part2, data + kSize, kSize); + memcpy(&high, data, kHalfSize); + memcpy(&low, data + kHalfSize, kHalfSize); #else - memcpy(&part1, data + kSize, kSize); - memcpy(&part2, data, kSize); + memcpy(&high, data + kHalfSize, kHalfSize); + memcpy(&low, data, kHalfSize); #endif // V8_TARGET_BIG_ENDIAN + break; + default: + UNREACHABLE(); + } - if (part1 != 0) { - return fprintf(fp(), "0x%" PRIx64 "%016" PRIx64, part1, part2); + if (high != 0) { + return fprintf(fp(), "0x%" PRIx64 "%016" PRIx64, high, low); } else { - return fprintf(fp(), "0x%" PRIx64, part2); + return fprintf(fp(), "0x%" PRIx64, low); } } diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.h b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.h index 0f1763ba..b0b5f787 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.h +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.h @@ -67,7 +67,7 @@ class PlatformEmbeddedFileWriterBase { virtual void DeclareFunctionEnd(const char* name) = 0; // Returns the number of printed characters. - virtual int HexLiteral(uint64_t value) = 0; + virtual int HexLiteral(uint64_t value); virtual void Comment(const char* string) = 0; virtual void Newline() { fprintf(fp_, "\n"); } diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.cc b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.cc index f4183b4b..71e278b7 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.cc +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.cc @@ -112,10 +112,6 @@ void PlatformEmbeddedFileWriterGeneric::DeclareFunctionBegin(const char* name) { void PlatformEmbeddedFileWriterGeneric::DeclareFunctionEnd(const char* name) {} -int PlatformEmbeddedFileWriterGeneric::HexLiteral(uint64_t value) { - return fprintf(fp_, "0x%" PRIx64, value); -} - void PlatformEmbeddedFileWriterGeneric::FilePrologue() {} void PlatformEmbeddedFileWriterGeneric::DeclareExternalFilename( @@ -142,6 +138,18 @@ int PlatformEmbeddedFileWriterGeneric::IndentedDataDirective( return fprintf(fp_, " %s ", DirectiveAsString(directive)); } +DataDirective PlatformEmbeddedFileWriterGeneric::ByteChunkDataDirective() + const { +#if defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64) + // MIPS uses a fixed 4 byte instruction set, using .long + // to prevent any unnecessary padding. + return kLong; +#else + // Other ISAs just listen to the base + return PlatformEmbeddedFileWriterBase::ByteChunkDataDirective(); +#endif +} + #undef SYMBOL_PREFIX } // namespace internal diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.h b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.h index 0c76e7df..7c59eb9f 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.h +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.h @@ -39,8 +39,6 @@ class PlatformEmbeddedFileWriterGeneric void DeclareFunctionBegin(const char* name) override; void DeclareFunctionEnd(const char* name) override; - int HexLiteral(uint64_t value) override; - void Comment(const char* string) override; void FilePrologue() override; @@ -49,6 +47,8 @@ class PlatformEmbeddedFileWriterGeneric int IndentedDataDirective(DataDirective directive) override; + DataDirective ByteChunkDataDirective() const override; + private: void DeclareSymbolGlobal(const char* name); diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.cc b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.cc index 4be3c7ac..7d50617c 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.cc +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.cc @@ -87,10 +87,6 @@ void PlatformEmbeddedFileWriterMac::DeclareFunctionBegin(const char* name) { void PlatformEmbeddedFileWriterMac::DeclareFunctionEnd(const char* name) {} -int PlatformEmbeddedFileWriterMac::HexLiteral(uint64_t value) { - return fprintf(fp_, "0x%" PRIx64, value); -} - void PlatformEmbeddedFileWriterMac::FilePrologue() {} void PlatformEmbeddedFileWriterMac::DeclareExternalFilename( diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.h b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.h index 4f2cd3d6..7bcfaaac 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.h +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.h @@ -37,8 +37,6 @@ class PlatformEmbeddedFileWriterMac : public PlatformEmbeddedFileWriterBase { void DeclareFunctionBegin(const char* name) override; void DeclareFunctionEnd(const char* name) override; - int HexLiteral(uint64_t value) override; - void Comment(const char* string) override; void FilePrologue() override;