Adapt LLVM15

1. Adapt some interface changes
2. Remove libark_jsoptimizer_test dylib to avoid static symbols loaded
repeatedly
3. Align rodata section
Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I73WZA?from=project-issue
Signed-off-by: zhangyukun8 <zhangyukun8@huawei.com>
Change-Id: I41a0fef50a9892150278974b67e22fb65060918d

Change-Id: I7f6cda0759b620bfd5547297bac3955ff29119fa
This commit is contained in:
zhangyukun8 2023-05-22 16:31:17 +08:00
parent 761747e79c
commit 5690aa9aed
9 changed files with 36 additions and 117 deletions

View File

@ -230,6 +230,10 @@ ohos_source_set("libark_jsoptimizer_set") {
"LLVMBitWriter",
]
if (!is_mac && !is_ios) {
libs += [ "LLVMParts" ]
}
# Only support compiling aarch64 target at device-side(arm64 platform).
# So these os-related libs of arm and x86 are not needed on arm64 platform.
if (is_mac || current_cpu != "arm64") {
@ -326,29 +330,6 @@ ohos_shared_library("libark_jsoptimizer") {
subsystem_name = "arkcompiler"
}
ohos_shared_library("libark_jsoptimizer_test") {
stack_protector_ret = false
deps = [
":libark_jsoptimizer_set",
"$ark_root/libpandafile:libarkfile_static",
"$js_root:libark_jsruntime_test_set",
]
ldflags = []
if (enable_coverage) {
ldflags += [ "--coverage" ]
cflags_cc = [ "--coverage" ]
}
if (!ark_standalone_build) {
ldflags += [ "-Wl,--lto-O0" ]
}
install_enable = false
output_extension = "so"
subsystem_name = "test"
}
ohos_executable("ark_stub_compiler") {
sources = [ "stub_compiler.cpp" ]
include_dirs = [ "$target_gen_dir" ]

View File

@ -47,9 +47,9 @@ public:
void TryRemoveAnFile(const char *filename);
void AlignTextSec()
void AlignTextSec(uint32_t alignSize)
{
curTextSecOffset_ = AlignUp(curTextSecOffset_, TEXT_SEC_ALIGN);
curTextSecOffset_ = AlignUp(curTextSecOffset_, alignSize);
}
void UpdateCurTextSecOffset(uint64_t size)

View File

@ -350,6 +350,8 @@ void ElfBuilder::MergeTextSections(std::ofstream &file,
curInfo.textSize = curSecSize;
curSecOffset += curSecSize;
if (rodataSize != 0 && rodataAddr > curSecAddr) {
curSecOffset = AlignUp(curSecOffset, AOTFileInfo::DATA_SEC_ALIGN);
file.seekp(curSecOffset);
file.write(reinterpret_cast<char *>(rodataAddr), rodataSize);
curInfo.rodataSize = rodataSize;
curSecOffset += rodataSize;

View File

@ -267,6 +267,7 @@ void ElfReader::SeparateTextSections(std::vector<ModuleSectionDes> &des,
des[i].SetSecAddrAndSize(ElfSecName::TEXT, secAddr + secOffset, textSize);
secOffset += textSize;
if (rodataSize > 0 && rodataAfterText == 1) {
secOffset = AlignUp(secOffset, DATA_SEC_ALIGN);
des[i].SetSecAddrAndSize(ElfSecName::RODATA_CST8, secAddr + secOffset, rodataSize);
secOffset += rodataSize;
}
@ -312,6 +313,7 @@ void ElfReader::SeparateTextSections(BinaryBufferParser &parser,
des[i].SetSecAddrAndSize(ElfSecName::TEXT, secAddr + secOffset, textSize);
secOffset += textSize;
if (rodataSize > 0 && rodataAfterText == 1) {
secOffset = AlignUp(secOffset, DATA_SEC_ALIGN);
parser.ParseBuffer(reinterpret_cast<void *>(secAddr + secOffset), rodataSize, curShOffset + secOffset);
des[i].SetSecAddrAndSize(ElfSecName::RODATA_CST8, secAddr + secOffset, rodataSize);
secOffset += rodataSize;

View File

@ -54,6 +54,7 @@ private:
}
static constexpr uint32_t TEXT_SEC_ALIGN = 4096;
static constexpr uint32_t DATA_SEC_ALIGN = 8;
static constexpr uint32_t ASMSTUB_MODULE_NUM = 3;
ExecutedMemoryAllocator::ExeMem stubsMem_ {};
MemMap fileMapMem_ {};

View File

@ -124,7 +124,7 @@ void Module::CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, A
uint32_t textSize = GetTextSize();
uintptr_t rodataAddr = GetRODataAddr();
uint32_t rodataSize = GetRODataSize();
aotInfo.AlignTextSec();
aotInfo.AlignTextSec(AOTFileInfo::TEXT_SEC_ALIGN);
if (rodataAddr < textAddr) {
aotInfo.UpdateCurTextSecOffset(rodataSize);
}
@ -153,6 +153,7 @@ void Module::CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, A
}
aotInfo.UpdateCurTextSecOffset(textSize);
if (rodataAddr > textAddr) {
aotInfo.AlignTextSec(AOTFileInfo::DATA_SEC_ALIGN);
aotInfo.UpdateCurTextSecOffset(rodataSize);
}
}
@ -273,8 +274,14 @@ uint64_t AOTFileGenerator::RollbackTextSize(Module *module)
uintptr_t rodataAddr = module->GetSectionAddr(ElfSecName::RODATA_CST8);
uint32_t textSize = module->GetSectionSize(ElfSecName::TEXT);
uint32_t rodataSize = module->GetSectionSize(ElfSecName::RODATA_CST8);
return textAddr > rodataAddr ? (aotInfo_.GetCurTextSecOffset() - textSize) :
(aotInfo_.GetCurTextSecOffset() - textSize - rodataSize);
uint64_t textStart = 0;
if (textAddr > rodataAddr) {
textStart = aotInfo_.GetCurTextSecOffset() - textSize;
} else {
textStart = aotInfo_.GetCurTextSecOffset() - textSize - rodataSize;
textStart = AlignDown(textStart, AOTFileInfo::DATA_SEC_ALIGN);
}
return textStart;
}
void AOTFileGenerator::CollectCodeInfo(Module *module, uint32_t moduleIdx)

View File

@ -39,7 +39,11 @@
#include "llvm-c/DisassemblerTypes.h"
#include "llvm-c/Target.h"
#include "llvm-c/Transforms/PassManagerBuilder.h"
#if defined(PANDA_TARGET_MACOS)
#include "llvm/CodeGen/BuiltinGCs.h"
#else
#include "llvm/IR/BuiltinGCs.h"
#endif
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
@ -170,7 +174,8 @@ uint8_t *CodeInfo::AllocaDataSection(uintptr_t size, const char *sectionName)
: AllocaInNotReqSecBuffer(size, AOTFileInfo::TEXT_SEC_ALIGN);
alreadyPageAlign_ = true;
} else {
addr = curSec.isSequentialAOTSec() ? AllocaInReqSecBuffer(size) : AllocaInNotReqSecBuffer(size);
addr = curSec.isSequentialAOTSec() ? AllocaInReqSecBuffer(size, AOTFileInfo::DATA_SEC_ALIGN)
: AllocaInNotReqSecBuffer(size, AOTFileInfo::DATA_SEC_ALIGN);
}
} else {
addr = curSec.isSequentialAOTSec() ? AllocaInReqSecBuffer(size) : AllocaInNotReqSecBuffer(size);
@ -442,7 +447,11 @@ kungfu::CalleeRegAndOffsetVec LLVMAssembler::GetCalleeReg2Offset(LLVMValueRef fn
{
kungfu::CalleeRegAndOffsetVec info;
llvm::Function* func = llvm::unwrap<llvm::Function>(fn);
#if defined(PANDA_TARGET_MACOS)
for (const auto &Attr : func->getAttributes().getFnAttributes()) {
#else
for (const auto &Attr : func->getAttributes().getFnAttrs()) {
#endif
if (Attr.isStringAttribute()) {
std::string str = std::string(Attr.getKindAsString().data());
std::string expectedKey = "DwarfReg";

View File

@ -14,21 +14,6 @@
import("//arkcompiler/ets_runtime/js_runtime_config.gni")
import("//arkcompiler/ets_runtime/test/test_helper.gni")
config("include_llvm_config") {
if (compile_llvm_online) {
include_dirs = [
"//third_party/third_party_llvm-project/build/include",
"//third_party/third_party_llvm-project/llvm/include/",
]
} else {
include_dirs = [
"//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts/llvm/include",
"//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts/build/include",
]
}
cflags_cc = [ "-DARK_GC_SUPPORT" ]
}
module_output_path = "arkcompiler/ets_runtime"
host_unittest_action("AssemblerTest") {
@ -39,81 +24,11 @@ host_unittest_action("AssemblerTest") {
"../assembler/tests/assembler_aarch64_test.cpp",
"../assembler/tests/assembler_x64_test.cpp",
]
configs = [
":include_llvm_config",
"//arkcompiler/ets_runtime:ecma_test_config",
"//arkcompiler/ets_runtime:ark_jsruntime_compiler_config",
"//arkcompiler/ets_runtime:ark_jsruntime_public_config",
]
if (compile_llvm_online) {
lib_dirs = [ "//third_party/third_party_llvm-project/build/lib" ]
} else {
lib_dirs =
[ "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts/build/lib" ]
}
libs = [
"stdc++",
"z",
"LLVMTarget",
"LLVMObject",
"LLVMMC",
"LLVMSupport",
"LLVMCore",
"LLVMExecutionEngine",
"LLVMInterpreter",
"LLVMMCJIT",
"LLVMExegesis",
"LLVMRuntimeDyld",
"LLVMInstCombine",
"LLVMAnalysis",
"LLVMScalarOpts",
"LLVMBinaryFormat",
"LLVMDebugInfoDWARF",
"LLVMRemarks",
"LLVMTextAPI",
"LLVMScalarOpts",
"LLVMTransformUtils",
"LLVMBitReader",
"LLVMAsmPrinter",
"LLVMProfileData",
"LLVMBitstreamReader",
"LLVMSelectionDAG",
"LLVMGlobalISel",
"LLVMLTO",
"LLVMCFGuard",
"LLVMVectorize",
"LLVMDemangle",
"LLVMipo",
"LLVMInstrumentation",
"LLVMDebugInfoCodeView",
"LLVMAggressiveInstCombine",
"LLVMAsmParser",
"LLVMMCParser",
"LLVMMIRParser",
"LLVMX86Info",
"LLVMAArch64Info",
"LLVMARMDesc",
"LLVMAArch64Desc",
"LLVMX86Desc",
"LLVMX86Disassembler",
"LLVMARMDisassembler",
"LLVMAArch64Disassembler",
"LLVMMCDisassembler",
"LLVMAArch64CodeGen",
"LLVMARMCodeGen",
"LLVMCodeGen",
"LLVMX86CodeGen",
"LLVMX86AsmParser",
"LLVMTransformUtils",
"LLVMAArch64Utils",
"LLVMARMUtils",
"LLVMIRReader",
]
deps = [
"//arkcompiler/ets_runtime/ecmascript/compiler:libark_jsoptimizer_test",
"$ark_root/libpandafile:libarkfile_static",
"$js_root:libark_jsruntime_test_set",
"$js_root/ecmascript/compiler:libark_jsoptimizer_set",
sdk_libc_secshared_dep,
]

View File

@ -55,6 +55,8 @@ template("host_unittest_action") {
rebase_path(_root_out_dir_) + "/test/test:" +
rebase_path(_root_out_dir_) + "/${_icu_path_}:" +
rebase_path(_root_out_dir_) + "/thirdparty/zlib:" +
rebase_path(_root_out_dir_) +
"/thirdparty/bounds_checking_function:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
"--timeout-limit",
"1200",