diff --git a/ecmascript/compiler/aot_file/elf_builder.cpp b/ecmascript/compiler/aot_file/elf_builder.cpp index 73ee2f3c07510464e45b91def33c9343982abc75..e6492c30243c79ffccb13fdecad5d7871414f335 100644 --- a/ecmascript/compiler/aot_file/elf_builder.cpp +++ b/ecmascript/compiler/aot_file/elf_builder.cpp @@ -101,7 +101,7 @@ void ElfBuilder::DumpSection() const } ElfBuilder::ElfBuilder(const std::vector &des, - const std::vector §ions): des_(des), sections_(sections) + const std::vector §ions): des_(des), sections_(sections) { Initialize(); AddShStrTabSection(); diff --git a/ecmascript/compiler/aot_file/elf_builder.h b/ecmascript/compiler/aot_file/elf_builder.h index 6a74f995ad628a17ae3c5369881df09ff091b3d4..5c44de1484de99a6e1939b5e16af5b003411bdf1 100644 --- a/ecmascript/compiler/aot_file/elf_builder.h +++ b/ecmascript/compiler/aot_file/elf_builder.h @@ -30,7 +30,8 @@ class ModuleSectionDes; class ElfBuilder { public: - ElfBuilder(const std::vector &des, const std::vector §ions); + ElfBuilder(const std::vector &des, + const std::vector §ions); ~ElfBuilder(); static constexpr uint32_t FuncEntryModuleDesIndex = 0; void PackELFHeader(llvm::ELF::Elf64_Ehdr &header, uint32_t version, Triple triple); diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h index 9071c4b050d86cf3e56e913502b06c9d2aa0834a..4e72e9e8cbb94e5ae32b45577bbb955544248550 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h @@ -793,6 +793,21 @@ public: doCGSSA = true; } + static void EnableSupportFuncSymbol() + { + supportFuncSymbol = true; + } + + static void DisableSupportFuncSymbol() + { + supportFuncSymbol = false; + } + + static bool addFuncSymbol() + { + return supportFuncSymbol; + } + static bool DoCGSSA() { return doCGSSA; @@ -1711,6 +1726,7 @@ private: static uint32 funcAlignPow; static bool doOptimizedFrameLayout; static bool doCgirVerify; + static bool supportFuncSymbol; }; } /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h index 2b971372db42eab647946cf9204386601d43345f..6e38b7ad0f57b18db4629a4c53dcfb77a7448ad2 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h @@ -131,6 +131,7 @@ extern maplecl::Option loopAlignPow; extern maplecl::Option jumpAlignPow; extern maplecl::Option funcAlignPow; extern maplecl::Option optimizedFrameLayout; +extern maplecl::Option supportFuncSymbol; } // namespace opts::cg diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/ifile.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/ifile.h index c8c9b9929ba5b152391b6ca33866e8755d6e905f..338e25662db8ff1cca31cceb065099985e8f3b5f 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/ifile.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/ifile.h @@ -400,6 +400,10 @@ public: return symbolIdxMap.count(symIdx) != 0; } + const char *GetAddr() + { + return reinterpret_cast(symbols.data()); + } private: MapleAllocator alloc; MapleVector symbols; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_assembler.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_assembler.h index 9b2753c78e6cc62fb81a30b45231fed8f96b85d0..20dfc5c8cf502629bcdad63404c8fed2438870b3 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_assembler.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_assembler.h @@ -593,6 +593,7 @@ private: void WriteElfFile(); void AppendSecSymsToSymTabSec(); void AppendSymsToSymTabSec(); + void AppendGlobalSymsToSymTabSec(); private: std::vector codeBuff; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_file.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_file.h index bc7a9e2e28966f77690578edb7e162767676b14e..937ffda1c89bf242765e7f3bf30c6035335f0952 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_file.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/elf_file.h @@ -289,6 +289,16 @@ public: return symbolIdxMap.count(symIdx) != 0; } + uint32 GetDataSize() const + { + return symbols.size() * sizeof(Symbol); + } + + const char *GetAddr() + { + return reinterpret_cast(symbols.data()); + } + private: std::vector symbols; std::unordered_map symbolIdxMap; diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_obj_emitter.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_obj_emitter.cpp index 423da6ae96bed144941ed5487843361c3ad0a73b..c8a5904010cdc7f4ca3ca88f8dd291e7990ad554 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_obj_emitter.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_obj_emitter.cpp @@ -284,13 +284,6 @@ void AArch64ObjEmitter::AppendGlobalLabel() void AArch64ObjEmitter::AppendSymsToSymTabSec() { - // section symbol - AddSymbol(".text", textSection->GetDataSize(), *textSection, 0); - /* Indexed by the inverse of the section index. */ - symbolTabSection->AppendIdxInSymbols(~textSection->GetIndex() + 1); - AddSymbol(".data", dataSection->GetDataSize(), *dataSection, 0); - symbolTabSection->AppendIdxInSymbols(~dataSection->GetIndex() + 1); - Address offset = 0; auto &contents = GetContents(); for (auto *content : contents) { diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp index 59e50eaacda1416ae388290382284c578ec4a57e..96490552af828d69f1a9c2b906e8718bb8c353ab 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp @@ -63,6 +63,7 @@ uint32 CGOptions::loopAlignPow = 4; uint32 CGOptions::jumpAlignPow = 5; uint32 CGOptions::funcAlignPow = 5; bool CGOptions::doOptimizedFrameLayout = true; +bool CGOptions::supportFuncSymbol = false; #if TARGAARCH64 || TARGRISCV64 bool CGOptions::useBarriersForVolatile = false; #else @@ -178,6 +179,10 @@ bool CGOptions::SolveOptions(bool isDebug) } } + if (opts::cg::supportFuncSymbol.IsEnabledByUser()) { + opts::cg::supportFuncSymbol ? EnableSupportFuncSymbol() : DisableSupportFuncSymbol(); + } + if (opts::cg::quiet.IsEnabledByUser()) { SetQuiet(true); } @@ -796,7 +801,8 @@ void CGOptions::EnableLiteCG() doWriteRefFieldOpt = false; doAlignAnalysis = false; doCondBrAlign = false; - + supportFuncSymbol = false; + ClearOption(kUseStackProtectorStrong); ClearOption(kUseStackProtectorAll); ClearOption(kConstFold); diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp index 97330fe14801f524504abac660f2b0eab7eefef6..a390fc1936f8b25cf76465869af9e4a45f7a5ca2 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp @@ -60,6 +60,11 @@ maplecl::Option replaceAsm({"--replaceasm"}, " --no-replaceasm\n", {cgCategory}, maplecl::DisableWith("--no-replaceasm")); +maplecl::Option supportFuncSymbol({"--enable-func-symbol"}, + " --enable-func-symbol \tenable function symbols in symbol table\n" + " --disable-func-symbol\n", + {cgCategory}, maplecl::DisableWith("--disable-func-symbol")); + maplecl::Option generalRegOnly( {"--general-reg-only"}, " --general-reg-only \tdisable floating-point or Advanced SIMD registers\n" diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/obj_emit.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/obj_emit.cpp index 11d2a849c09caa1d1ac97804b44d10741440ca12..67b271dda255402ca60da4cc0c06ef62170386ea 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/obj_emit.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/obj_emit.cpp @@ -115,9 +115,20 @@ void ObjEmitter::WriteObjFile() const auto &emitMemorymanager = CGOptions::GetInstance().GetEmitMemoryManager(); if (emitMemorymanager.codeSpace != nullptr) { DEBUG_ASSERT(textSection != nullptr, "textSection has not been initialized"); - uint8 *memSpace = emitMemorymanager.allocateDataSection(emitMemorymanager.codeSpace, + uint8 *codeSpace = emitMemorymanager.allocateDataSection(emitMemorymanager.codeSpace, textSection->GetDataSize(), textSection->GetAlign(), textSection->GetName().c_str()); - memcpy_s(memSpace, textSection->GetDataSize(), textSection->GetData().data(), textSection->GetDataSize()); + memcpy_s(codeSpace, textSection->GetDataSize(), textSection->GetData().data(), textSection->GetDataSize()); + if (CGOptions::addFuncSymbol()) { + uint8 *symtabSpace = emitMemorymanager.allocateDataSection(emitMemorymanager.codeSpace, + symbolTabSection->GetDataSize(), symbolTabSection->GetAlign(), symbolTabSection->GetName().c_str()); + memcpy_s(symtabSpace, symbolTabSection->GetDataSize(), + symbolTabSection->GetAddr(), symbolTabSection->GetDataSize()); + uint8 *stringTabSpace = emitMemorymanager.allocateDataSection(emitMemorymanager.codeSpace, + strTabSection->GetDataSize(), strTabSection->GetAlign(), strTabSection->GetName().c_str()); + memcpy_s(stringTabSpace, strTabSection->GetDataSize(), + strTabSection->GetData().data(), strTabSection->GetDataSize()); + } + return; } /* write header */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/elf_assembler.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/elf_assembler.cpp index 72ef07ebfdc007ad3d417834a1474026cb63665e..37296e65efaf44f5b8102c9ff9dde4e67b5eee73 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/elf_assembler.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/elf_assembler.cpp @@ -309,7 +309,7 @@ void ElfAssembler::PostEmitVariable(int64 symIdx, SymbolAttr symAttr, uint64 siz void ElfAssembler::FinalizeFileInfo() { - AppendSymsToSymTabSec(); + AppendGlobalSymsToSymTabSec(); HandleTextSectionFixup(); HandleDataSectionFixup(); HandleRodataSectionFixup(); @@ -782,9 +782,6 @@ void ElfAssembler::AppendRela(const Label &label, const std::pairExistSymInSymbols(labelIdx)) { - symbolTabSection->AppendSymbol({static_cast(strTabSection->AddString(GetNameFromSymMap(labelIdx))), - static_cast((STB_GLOBAL << kLeftShift4Bits) + (STT_NOTYPE & 0xf)), 0, - 0, 0, 0}); symbolTabSection->AppendIdxInSymbols(labelIdx); } relaSection->AppendRela({offsetPair.first, @@ -950,9 +947,19 @@ void ElfAssembler::WriteElfFile() const auto &emitMemoryManager = maplebe::CGOptions::GetInstance().GetEmitMemoryManager(); if (emitMemoryManager.codeSpace != nullptr) { DEBUG_ASSERT(textSection != nullptr, "textSection has not been initialized"); - uint8 *memSpace = emitMemoryManager.allocateDataSection(emitMemoryManager.codeSpace, + uint8 *codeSpace = emitMemoryManager.allocateDataSection(emitMemoryManager.codeSpace, textSection->GetSectionSize(), textSection->GetAlign(), textSection->GetName()); - memcpy_s(memSpace, textSection->GetSectionSize(), textSection->GetData().data(), textSection->GetDataSize()); + memcpy_s(codeSpace, textSection->GetSectionSize(), textSection->GetData().data(), textSection->GetDataSize()); + if (CGOptions::addFuncSymbol()) { + uint8 *symtabSpace = emitMemoryManager.allocateDataSection(emitMemoryManager.codeSpace, + symbolTabSection->GetDataSize(), symbolTabSection->GetAlign(), symbolTabSection->GetName().c_str()); + memcpy_s(symtabSpace, symbolTabSection->GetDataSize(), + symbolTabSection->GetAddr(), symbolTabSection->GetDataSize()); + uint8 *stringTabSpace = emitMemoryManager.allocateDataSection(emitMemoryManager.codeSpace, + strTabSection->GetDataSize(), strTabSection->GetAlign(), strTabSection->GetName().c_str()); + memcpy_s(stringTabSpace, strTabSection->GetDataSize(), + strTabSection->GetData().data(), strTabSection->GetDataSize()); + } return; } @@ -996,6 +1003,16 @@ void ElfAssembler::AppendSecSymsToSymTabSec() } } +void ElfAssembler::AppendGlobalSymsToSymTabSec() +{ + for (auto elem : symTab) { + const Symbol &symbol = elem.first; + int64 symIdx = elem.second; + symbolTabSection->AppendSymbol(symbol); + symbolTabSection->AppendIdxInSymbols(symIdx); + } +} + void ElfAssembler::AppendSymsToSymTabSec() { /* emit local symbol */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp index 30bc1b0906b2f53a142db5042ce1612957160bf0..7ae5308768e1be1536c42e93eb5ed6cc7c314387 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp @@ -1593,14 +1593,7 @@ void X64Emitter::EmitFunctionFoot(CGFunc &cgFunc) { const MIRSymbol *funcSymbol = cgFunc.GetFunction().GetFuncSymbol(); uint32 symIdx = funcSymbol->GetNameStrIdx().get(); - SymbolAttr funcAttr = kSALocal; - if (funcSymbol->GetFunction()->GetAttr(FUNCATTR_weak)) { - funcAttr = kSAWeak; - } else if (funcSymbol->GetFunction()->GetAttr(FUNCATTR_local)) { - funcAttr = kSALocal; - } else if (!funcSymbol->GetFunction()->GetAttr(FUNCATTR_static)) { - funcAttr = kSAGlobal; - } + SymbolAttr funcAttr = kSAGlobal; assmbler.EmitFunctionFoot(symIdx, funcAttr); }