From ec19706fef042e3a89573c096ca0448d65f670b0 Mon Sep 17 00:00:00 2001 From: wupengyong Date: Tue, 19 Nov 2024 21:38:54 +0800 Subject: [PATCH] Reason:fix aot codegen bug Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB586E?from=project-issue Test: Build & Boot devices Signed-off-by: wupengyong Change-Id: I23f0683f54e4e47843e1d4141a9329f3f096ed1f --- ecmascript/compiler/aot_file/aot_file_info.h | 1 + ecmascript/compiler/aot_file/elf_builder.cpp | 2 +- ecmascript/compiler/aot_file/elf_reader.cpp | 4 ++-- ecmascript/compiler/codegen/llvm/llvm_codegen.cpp | 6 ++++-- ecmascript/compiler/file_generators.cpp | 6 +++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ecmascript/compiler/aot_file/aot_file_info.h b/ecmascript/compiler/aot_file/aot_file_info.h index ecc8685782..888a70cfa5 100644 --- a/ecmascript/compiler/aot_file/aot_file_info.h +++ b/ecmascript/compiler/aot_file/aot_file_info.h @@ -36,6 +36,7 @@ public: virtual ~AOTFileInfo() = default; static constexpr uint32_t TEXT_SEC_ALIGN = 16; + static constexpr uint32_t RODATA_SEC_ALIGN = 16; static constexpr uint32_t DATA_SEC_ALIGN = 8; static constexpr uint32_t PAGE_ALIGN = 4096; diff --git a/ecmascript/compiler/aot_file/elf_builder.cpp b/ecmascript/compiler/aot_file/elf_builder.cpp index 21522376ad..1eca0fd5fc 100644 --- a/ecmascript/compiler/aot_file/elf_builder.cpp +++ b/ecmascript/compiler/aot_file/elf_builder.cpp @@ -379,7 +379,7 @@ void ElfBuilder::MergeTextSections(std::ofstream &file, curInfo.textSize = curSecSize; curSecOffset += curSecSize; if (rodataSizeAfterText != 0) { - curSecOffset = AlignUp(curSecOffset, AOTFileInfo::DATA_SEC_ALIGN); + curSecOffset = AlignUp(curSecOffset, AOTFileInfo::RODATA_SEC_ALIGN); file.seekp(curSecOffset); file.write(reinterpret_cast(rodataAddrAfterText), rodataSizeAfterText); curInfo.rodataSizeAfterText = rodataSizeAfterText; diff --git a/ecmascript/compiler/aot_file/elf_reader.cpp b/ecmascript/compiler/aot_file/elf_reader.cpp index fe56983946..f912259be8 100644 --- a/ecmascript/compiler/aot_file/elf_reader.cpp +++ b/ecmascript/compiler/aot_file/elf_reader.cpp @@ -293,7 +293,7 @@ void ElfReader::SeparateTextSections(std::vector &des, des[i].SetSecAddrAndSize(ElfSecName::TEXT, secAddr + secOffset, textSize); secOffset += textSize; if (rodataSizeAfterText != 0) { - secOffset = AlignUp(secOffset, AOTFileInfo::DATA_SEC_ALIGN); + secOffset = AlignUp(secOffset, AOTFileInfo::RODATA_SEC_ALIGN); secOffset += rodataSizeAfterText; } } @@ -365,7 +365,7 @@ void ElfReader::SeparateTextSections(BinaryBufferParser &parser, des[i].SetSecAddrAndSize(ElfSecName::TEXT, secAddr + secOffset, textSize); secOffset += textSize; if (rodataSizeAfterText != 0) { - secOffset = AlignUp(secOffset, AOTFileInfo::DATA_SEC_ALIGN); + secOffset = AlignUp(secOffset, AOTFileInfo::RODATA_SEC_ALIGN); parser.ParseBuffer(reinterpret_cast(secAddr + secOffset), rodataSizeAfterText, curShOffset + secOffset); secOffset += rodataSizeAfterText; diff --git a/ecmascript/compiler/codegen/llvm/llvm_codegen.cpp b/ecmascript/compiler/codegen/llvm/llvm_codegen.cpp index d799a7a822..263eee1ba1 100644 --- a/ecmascript/compiler/codegen/llvm/llvm_codegen.cpp +++ b/ecmascript/compiler/codegen/llvm/llvm_codegen.cpp @@ -221,8 +221,10 @@ uint8_t *CodeInfo::AllocaDataSectionImp(uintptr_t size, const char *sectionName, : (this->*allocaInNotReqSecBuffer)(size, AOTFileInfo::PAGE_ALIGN); alreadyPageAlign_ = true; } else { - addr = curSec.isSequentialAOTSec() ? (this->*allocaInReqSecBuffer)(size, AOTFileInfo::DATA_SEC_ALIGN) - : (this->*allocaInNotReqSecBuffer)(size, AOTFileInfo::DATA_SEC_ALIGN); + uint32_t alignedSize = curSec.InRodataSection() ? AOTFileInfo::RODATA_SEC_ALIGN + : AOTFileInfo::DATA_SEC_ALIGN; + addr = curSec.isSequentialAOTSec() ? (this->*allocaInReqSecBuffer)(size, alignedSize) + : (this->*allocaInNotReqSecBuffer)(size, alignedSize); } } else { addr = curSec.isSequentialAOTSec() ? (this->*allocaInReqSecBuffer)(size, 0) diff --git a/ecmascript/compiler/file_generators.cpp b/ecmascript/compiler/file_generators.cpp index 52a8c4a849..b5262634f3 100644 --- a/ecmascript/compiler/file_generators.cpp +++ b/ecmascript/compiler/file_generators.cpp @@ -203,7 +203,7 @@ void Module::CollectFuncEntryInfo(std::map &addr2name, A } aotInfo.UpdateCurTextSecOffset(textSize); if (rodataSizeAfterText != 0) { - aotInfo.AlignTextSec(AOTFileInfo::DATA_SEC_ALIGN); + aotInfo.AlignTextSec(AOTFileInfo::RODATA_SEC_ALIGN); aotInfo.UpdateCurTextSecOffset(rodataSizeAfterText); } } @@ -267,7 +267,7 @@ void Module::CollectFuncEntryInfoByLiteCG(std::map &addr } aotInfo.UpdateCurTextSecOffset(textSize); if (rodataSizeAfterText != 0) { - aotInfo.AlignTextSec(AOTFileInfo::DATA_SEC_ALIGN); + aotInfo.AlignTextSec(AOTFileInfo::RODATA_SEC_ALIGN); aotInfo.UpdateCurTextSecOffset(rodataSizeAfterText); } } @@ -434,7 +434,7 @@ uint64_t AOTFileGenerator::RollbackTextSize(Module *module) textStart = aotInfo_.GetCurTextSecOffset() - textSize; } else { textStart = aotInfo_.GetCurTextSecOffset() - textSize - rodataSizeAfterText; - textStart = AlignDown(textStart, AOTFileInfo::DATA_SEC_ALIGN); + textStart = AlignDown(textStart, AOTFileInfo::RODATA_SEC_ALIGN); } return textStart; }