1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NAMEMANGLER_H 17 #define NAMEMANGLER_H 18 #include <string> 19 #include <vector> 20 21 // This is a general name mangler which is shared between maple compiler and runtime. 22 // maple-compiler-specific data structure may NOT be used here. 23 namespace namemangler { 24 #define TO_STR(s) TO_STR2(s) 25 #define TO_STR2(s) #s 26 27 #define VTAB_PREFIX __vtb_ 28 #define ITAB_PREFIX __itb_ 29 #define VTAB_AND_ITAB_PREFIX __vtb_and_itb_ 30 #define ITAB_CONFLICT_PREFIX __itbC_ 31 #define CLASSINFO_PREFIX __cinf_ 32 #define CLASSINFO_RO_PREFIX __classinforo__ 33 #define SUPERCLASSINFO_PREFIX __superclasses__ 34 #define PRIMITIVECLASSINFO_PREFIX __pinf_ 35 #define CLASS_INIT_BRIDGE_PREFIX __ClassInitBridge__ 36 #define GCTIB_PREFIX MCC_GCTIB__ 37 #define REF_PREFIX REF_ 38 #define JARRAY_PREFIX A 39 40 #define VTAB_PREFIX_STR TO_STR(VTAB_PREFIX) 41 #define ITAB_PREFIX_STR TO_STR(ITAB_PREFIX) 42 #define VTAB_AND_ITAB_PREFIX_STR TO_STR(VTAB_AND_ITAB_PREFIX) 43 #define ITAB_CONFLICT_PREFIX_STR TO_STR(ITAB_CONFLICT_PREFIX) 44 #define CLASSINFO_PREFIX_STR TO_STR(CLASSINFO_PREFIX) 45 #define CLASSINFO_RO_PREFIX_STR TO_STR(CLASSINFO_RO_PREFIX) 46 #define SUPERCLASSINFO_PREFIX_STR TO_STR(SUPERCLASSINFO_PREFIX) 47 #define PRIMITIVECLASSINFO_PREFIX_STR TO_STR(PRIMITIVECLASSINFO_PREFIX) 48 #define CLASS_INIT_BRIDGE_PREFIX_STR TO_STR(CLASS_INIT_BRIDGE_PREFIX) 49 #define GCTIB_PREFIX_STR TO_STR(GCTIB_PREFIX) 50 #define REF_PREFIX_STR TO_STR(REF_PREFIX) 51 #define JARRAY_PREFIX_STR TO_STR(JARRAY_PREFIX) 52 53 // Names of all compiler-generated tables and accessed by runtime 54 static constexpr const char kMuidPrefixStr[] = "__muid_"; 55 static constexpr const char kMuidRoPrefixStr[] = "__muid_ro"; 56 static constexpr const char kMuidFuncDefTabPrefixStr[] = "__muid_func_def_tab"; 57 static constexpr const char kMuidFuncDefOrigTabPrefixStr[] = "__muid_ro_func_def_orig_tab"; 58 static constexpr const char kMuidFuncInfTabPrefixStr[] = "__muid_ro_func_inf_tab"; 59 static constexpr const char kMuidFuncMuidIdxTabPrefixStr[] = "__muid_ro_func_muid_idx_tab"; 60 static constexpr const char kMuidDataDefTabPrefixStr[] = "__muid_data_def_tab"; 61 static constexpr const char kMuidDataDefOrigTabPrefixStr[] = "__muid_ro_data_def_orig_tab"; 62 static constexpr const char kMuidFuncUndefTabPrefixStr[] = "__muid_func_undef_tab"; 63 static constexpr const char kMuidDataUndefTabPrefixStr[] = "__muid_data_undef_tab"; 64 static constexpr const char kMuidFuncDefMuidTabPrefixStr[] = "__muid_ro_func_def_muid_tab"; 65 static constexpr const char kMuidDataDefMuidTabPrefixStr[] = "__muid_ro_data_def_muid_tab"; 66 static constexpr const char kMuidFuncUndefMuidTabPrefixStr[] = "__muid_ro_func_undef_muid_tab"; 67 static constexpr const char kMuidDataUndefMuidTabPrefixStr[] = "__muid_ro_data_undef_muid_tab"; 68 static constexpr const char kMuidVtabAndItabPrefixStr[] = "__muid_vtab_and_itab"; 69 static constexpr const char kMuidItabConflictPrefixStr[] = "__muid_itab_conflict"; 70 static constexpr const char kMuidColdVtabAndItabPrefixStr[] = "__muid_cold_vtab_and_itab"; 71 static constexpr const char kMuidColdItabConflictPrefixStr[] = "__muid_cold_itab_conflict"; 72 static constexpr const char kMuidVtabOffsetPrefixStr[] = "__muid_vtab_offset_tab"; 73 static constexpr const char kMuidFieldOffsetPrefixStr[] = "__muid_field_offset_tab"; 74 static constexpr const char kMuidVtabOffsetKeyPrefixStr[] = "__muid_vtable_offset_key_tab"; 75 static constexpr const char kMuidFieldOffsetKeyPrefixStr[] = "__muid_field_offset_key_tab"; 76 static constexpr const char kMuidValueOffsetPrefixStr[] = "__muid_offset_value_table"; 77 static constexpr const char kMuidLocalClassInfoStr[] = "__muid_local_classinfo_tab"; 78 static constexpr const char kMuidSuperclassPrefixStr[] = "__muid_superclass"; 79 static constexpr const char kMuidGlobalRootlistPrefixStr[] = "__muid_globalrootlist"; 80 static constexpr const char kMuidClassMetadataPrefixStr[] = "__muid_classmetadata"; 81 static constexpr const char kMuidClassMetadataBucketPrefixStr[] = "__muid_classmetadata_bucket"; 82 static constexpr const char kMuidDataSectionStr[] = "__data_section"; 83 static constexpr const char kMuidRangeTabPrefixStr[] = "__muid_range_tab"; 84 static constexpr const char kMuidConststrPrefixStr[] = "__muid_conststr"; 85 static constexpr const char kVtabOffsetTabStr[] = "__vtable_offset_table"; 86 static constexpr const char kFieldOffsetTabKeyStr[] = "__field_offset_key_table"; 87 static constexpr const char kFieldOffsetTabStr[] = "__field_offset_table"; 88 static constexpr const char kVtableKeyOffsetTabStr[] = "__vtable_offset_key_table"; 89 static constexpr const char kVtableOffsetTabKeyStr[] = "__vtable_offset_key_table"; 90 static constexpr const char kFieldKeyOffsetTabStr[] = "__field_offset_table"; 91 static constexpr const char kOffsetTabStr[] = "__offset_value_table"; 92 static constexpr const char kInlineCacheTabStr[] = "__inline_cache_table"; 93 static constexpr const char kLocalClassInfoStr[] = "__local_classinfo_table"; 94 static constexpr const char kMethodsInfoPrefixStr[] = "__methods_info__"; 95 static constexpr const char kMethodsInfoCompactPrefixStr[] = "__methods_infocompact__"; 96 static constexpr const char kFieldsInfoPrefixStr[] = "__fields_info__"; 97 static constexpr const char kFieldsInfoCompactPrefixStr[] = "__fields_infocompact__"; 98 static constexpr const char kFieldOffsetDataPrefixStr[] = "__fieldOffsetData__"; 99 static constexpr const char kMethodAddrDataPrefixStr[] = "__methodAddrData__"; 100 static constexpr const char kMethodSignaturePrefixStr[] = "__methodSignature__"; 101 static constexpr const char kParameterTypesPrefixStr[] = "__parameterTypes__"; 102 static constexpr const char kRegJNITabPrefixStr[] = "__reg_jni_tab"; 103 static constexpr const char kRegJNIFuncTabPrefixStr[] = "__reg_jni_func_tab"; 104 static constexpr const char kReflectionStrtabPrefixStr[] = "__reflection_strtab"; 105 static constexpr const char kReflectionStartHotStrtabPrefixStr[] = "__reflection_start_hot_strtab"; 106 static constexpr const char kReflectionBothHotStrTabPrefixStr[] = "__reflection_both_hot_strtab"; 107 static constexpr const char kReflectionRunHotStrtabPrefixStr[] = "__reflection_run_hot_strtab"; 108 static constexpr const char kReflectionNoEmitStrtabPrefixStr[] = "__reflection_no_emit_strtab"; 109 static constexpr const char kMarkMuidFuncDefStr[] = "muid_func_def:"; 110 static constexpr const char kMarkMuidFuncUndefStr[] = "muid_func_undef:"; 111 static constexpr const char kGcRootList[] = "gcRootNewList"; 112 static constexpr const char kDecoupleOption[] = "__decouple_option"; 113 static constexpr const char kDecoupleStr[] = "__decouple"; 114 static constexpr const char kCompilerVersionNum[] = "__compilerVersionNum"; 115 static constexpr const char kCompilerVersionNumStr[] = "__compilerVersionNumTab"; 116 static constexpr const char kCompilerMfileStatus[] = "__compiler_mfile_status"; 117 static constexpr const char kMapleGlobalVariable[] = "maple_global_variable"; 118 static constexpr const char kMapleLiteralString[] = "maple_literal_string"; 119 120 static constexpr const char kSourceMuid[] = "__sourceMuid"; 121 static constexpr const char kSourceMuidSectionStr[] = "__sourceMuidTab"; 122 static constexpr const char kDecoupleStaticKeyStr[] = "__staticDecoupleKeyOffset"; 123 static constexpr const char kDecoupleStaticValueStr[] = "__staticDecoupleValueOffset"; 124 static constexpr const char kMarkDecoupleStaticStr[] = "decouple_static:"; 125 static constexpr const char kClassInfoPrefix[] = "__cinf"; 126 static constexpr const char kBssSectionStr[] = "__bss_section"; 127 static constexpr const char kLinkerHashSoStr[] = "__linkerHashSo"; 128 129 static constexpr const char kStaticFieldNamePrefixStr[] = "__static_field_name"; 130 static constexpr const char kMplSuffix[] = ".mpl"; 131 static constexpr const char kClinvocation[] = ".clinvocation"; 132 static constexpr const char kPackageNameSplitterStr[] = "_2F"; 133 static constexpr const char kFileNameSplitterStr[] = "$$"; 134 static constexpr const char kNameSplitterStr[] = "_7C"; // 7C is the ascii code for | 135 static constexpr const char kRightBracketStr[] = "_29"; // 29 is the ascii code for ) 136 static constexpr const char kClassNameSplitterStr[] = "_3B_7C"; 137 static constexpr const char kClassMetadataTypeName[] = "__class_meta__"; 138 static constexpr const char kPtrPrefixStr[] = "_PTR"; 139 static constexpr const char kClassINfoPtrPrefixStr[] = "_PTR__cinf_"; 140 static constexpr const char kArrayClassInfoPrefixStr[] = "__cinf_A"; 141 static constexpr const char kShadowClassName[] = "shadow_24__klass__"; 142 static constexpr const char kClinitSuffix[] = "_7C_3Cclinit_3E_7C_28_29V"; 143 static constexpr const char kCinitStr[] = "_7C_3Cinit_3E_7C_28"; 144 static constexpr const char kClinitSubStr[] = "7C_3Cinit_3E_7C"; 145 146 static constexpr const char kPreNativeFunc[] = "MCC_PreNativeCall"; 147 static constexpr const char kPostNativeFunc[] = "MCC_PostNativeCall"; 148 static constexpr const char kDecodeRefFunc[] = "MCC_DecodeReference"; 149 static constexpr const char kFindNativeFunc[] = "MCC_FindNativeMethodPtr"; 150 static constexpr const char kFindNativeFuncNoeh[] = "MCC_FindNativeMethodPtrWithoutException"; 151 static constexpr const char kDummyNativeFunc[] = "MCC_DummyNativeMethodPtr"; 152 static constexpr const char kCheckThrowPendingExceptionFunc[] = "MCC_CheckThrowPendingException"; 153 static constexpr const char kCallFastNative[] = "MCC_CallFastNative"; 154 static constexpr const char kCallFastNativeExt[] = "MCC_CallFastNativeExt"; 155 static constexpr const char kCallSlowNativeExt[] = "MCC_CallSlowNativeExt"; 156 static constexpr const char kSetReliableUnwindContextFunc[] = "MCC_SetReliableUnwindContext"; 157 158 static constexpr const char kArrayClassCacheTable[] = "__arrayClassCacheTable"; 159 static constexpr const char kArrayClassCacheNameTable[] = "__muid_ro_arrayClassCacheNameTable"; 160 static constexpr const char kFunctionLayoutStr[] = "__func_layout__"; 161 162 static constexpr const char kFunctionProfileTabPrefixStr[] = "__muid_profile_func_tab"; 163 164 static constexpr const char kBBProfileTabPrefixStr[] = "__muid_prof_counter_tab"; 165 static constexpr const char kFuncIRProfInfTabPrefixStr[] = "__muid_prof_ir_desc_tab"; 166 167 static constexpr const char kprefixProfModDesc[] = "__mpl_prof_moddesc_"; 168 static constexpr const char kprefixProfCtrTbl[] = "__mpl_prof_ctrtbl_"; 169 static constexpr const char kprefixProfFuncDesc[] = "__mpl_prof_funcdesc_"; 170 static constexpr const char kprefixProfFuncDescTbl[] = "__mpl_func_prof_desc_tbl_"; 171 static constexpr const char kprefixProfInit[] = "__mpl_prof_init_"; 172 static constexpr const char kprefixProfExit[] = "__mpl_prof_exit_"; 173 static constexpr const char kGCCProfInit[] = "__gcov_init"; 174 static constexpr const char kGCCProfExit[] = "__gcov_exit"; 175 static constexpr const char kMplMergeFuncAdd[] = "__gcov_merge_add"; 176 static constexpr const char kProfFileNameExt[] = ".gcda"; 177 178 static constexpr const char kBindingProtectedRegionStr[] = "__BindingProtectRegion__"; 179 180 static constexpr const char kClassNamePrefixStr[] = "L"; 181 static constexpr const char kClassMethodSplitterStr[] = "_3B"; 182 static constexpr const char kFuncGetCurrentCl[] = "MCC_GetCurrentClassLoader"; 183 184 #ifdef ARK_LITECG_DEBUG 185 std::string DecodeName(const std::string &name); 186 void DecodeMapleNameToJDescriptor(const std::string &nameIn, std::string &nameOut); 187 188 __attribute__((visibility("default"))) unsigned UTF16ToUTF8(std::string &str, const std::u16string &str16, 189 unsigned short num = 0, bool isBigEndian = false); 190 size_t GetUleb128Size(uint64_t val); 191 size_t GetSleb128Size(int32_t val); 192 #endif 193 } // namespace namemangler 194 195 #endif 196