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 #include "ecmascript/compiler/aot_file/elf_reader.h"
17
18 #include "ecmascript/base/file_header.h"
19 #include "ecmascript/ecma_macros.h"
20 #include "securec.h"
21
22 namespace panda::ecmascript {
VerifyELFHeader(uint32_t version,bool strictMatch)23 bool ElfReader::VerifyELFHeader(uint32_t version, bool strictMatch)
24 {
25 llvm::ELF::Elf64_Ehdr header = *(reinterpret_cast<llvm::ELF::Elf64_Ehdr *>(fileMapMem_.GetOriginAddr()));
26 if (header.e_ident[llvm::ELF::EI_MAG0] != llvm::ELF::ElfMagic[llvm::ELF::EI_MAG0]
27 || header.e_ident[llvm::ELF::EI_MAG1] != llvm::ELF::ElfMagic[llvm::ELF::EI_MAG1]
28 || header.e_ident[llvm::ELF::EI_MAG2] != llvm::ELF::ElfMagic[llvm::ELF::EI_MAG2]
29 || header.e_ident[llvm::ELF::EI_MAG3] != llvm::ELF::ElfMagic[llvm::ELF::EI_MAG3]) {
30 LOG_ECMA(ERROR) << "ELF format error, expected magic is " << llvm::ELF::ElfMagic
31 << ", but got " << header.e_ident[llvm::ELF::EI_MAG0] << header.e_ident[llvm::ELF::EI_MAG1]
32 << header.e_ident[llvm::ELF::EI_MAG2] << header.e_ident[llvm::ELF::EI_MAG3];
33 return false;
34 }
35 if (!base::FileHeaderBase::VerifyVersion("Elf ", header.e_version, version, strictMatch)) {
36 return false;
37 }
38 if (ElfChecker(fileMapMem_).CheckValidElf() == false) {
39 LOG_ECMA(ERROR) << "ELF file content is not valid";
40 return false;
41 }
42 return true;
43 }
44
GetCurModuleInfo(uint32_t i,llvm::ELF::Elf64_Off offset)45 ModuleSectionDes::ModuleRegionInfo *ElfReader::GetCurModuleInfo(uint32_t i, llvm::ELF::Elf64_Off offset)
46 {
47 uint64_t codeAddress = reinterpret_cast<uint64_t>(fileMapMem_.GetOriginAddr());
48 uint64_t info = codeAddress + offset + i * sizeof(ModuleSectionDes::ModuleRegionInfo);
49 return reinterpret_cast<ModuleSectionDes::ModuleRegionInfo *>(info);
50 }
51
ParseELFSections(ModuleSectionDes & des,std::vector<ElfSecName> & secs)52 void ElfReader::ParseELFSections(ModuleSectionDes &des, std::vector<ElfSecName> &secs)
53 {
54 llvm::ELF::Elf64_Ehdr *ehdr = reinterpret_cast<llvm::ELF::Elf64_Ehdr *>(fileMapMem_.GetOriginAddr());
55 char *addr = reinterpret_cast<char *>(ehdr);
56 llvm::ELF::Elf64_Shdr *shdr = reinterpret_cast<llvm::ELF::Elf64_Shdr *>(addr + ehdr->e_shoff);
57 ASSERT(ehdr->e_shstrndx != static_cast<llvm::ELF::Elf64_Half>(-1));
58 llvm::ELF::Elf64_Shdr strdr = shdr[ehdr->e_shstrndx];
59 for (size_t j = 0; j < secs.size(); ++j) {
60 int secId = -1;
61 ElfSecName sec = secs[j];
62 std::string sectionName = ModuleSectionDes::GetSecName(sec);
63 for (size_t i = 0; i < ehdr->e_shnum; ++i) {
64 llvm::ELF::Elf64_Word shName = shdr[i].sh_name;
65 char *curShName = reinterpret_cast<char *>(addr) + shName + strdr.sh_offset;
66 if (sectionName.compare(curShName) == 0) {
67 secId = static_cast<int>(i);
68 break;
69 }
70 }
71 if (secId == -1) {
72 LOG_COMPILER(DEBUG) << "sectionName: " << sectionName << " not found in strtab";
73 continue;
74 }
75 ASSERT(secId > 0 && secId < ehdr->e_shnum);
76 llvm::ELF::Elf64_Shdr secShdr = shdr[secId];
77 uintptr_t secAddr = reinterpret_cast<uintptr_t>(addr + secShdr.sh_offset);
78 uint32_t secSize = secShdr.sh_size;
79 if (sec == ElfSecName::ARK_FUNCENTRY) {
80 ASSERT((secSize > 0) && (secSize % sizeof(AOTFileInfo::FuncEntryDes) == 0));
81 }
82 if (sec == ElfSecName::ARK_STACKMAP) {
83 des.SetArkStackMapPtr(reinterpret_cast<uint8_t *>(secAddr));
84 des.SetArkStackMapSize(secSize);
85 } else {
86 des.SetSecAddrAndSize(sec, secAddr, secSize);
87 }
88 }
89 }
90
ParseELFSections(std::vector<ModuleSectionDes> & des,std::vector<ElfSecName> & secs)91 void ElfReader::ParseELFSections(std::vector<ModuleSectionDes> &des, std::vector<ElfSecName> &secs)
92 {
93 llvm::ELF::Elf64_Ehdr *ehdr = reinterpret_cast<llvm::ELF::Elf64_Ehdr *>(fileMapMem_.GetOriginAddr());
94 char *addr = reinterpret_cast<char *>(ehdr);
95 llvm::ELF::Elf64_Shdr *shdrs = reinterpret_cast<llvm::ELF::Elf64_Shdr *>(addr + ehdr->e_shoff);
96 ASSERT(ehdr->e_shstrndx != static_cast<llvm::ELF::Elf64_Half>(-1));
97 llvm::ELF::Elf64_Shdr strdr = shdrs[ehdr->e_shstrndx];
98 ASSERT(ehdr->e_flags != static_cast<llvm::ELF::Elf64_Word>(-1));
99 llvm::ELF::Elf64_Shdr moduledr = shdrs[ehdr->e_flags];
100 size_t moduleInfoSize = moduledr.sh_size;
101 uint32_t moduleNum = GetModuleNum(moduleInfoSize);
102 des.resize(moduleNum);
103 std::set<ElfSecName> secSet(secs.begin(), secs.end());
104 for (ElfSecName sec : secSet) {
105 int secId = -1;
106 std::string sectionName = ModuleSectionDes::GetSecName(sec);
107 for (size_t i = 0; i < ehdr->e_shnum; ++i) {
108 llvm::ELF::Elf64_Word shName = shdrs[i].sh_name;
109 char *curShName = reinterpret_cast<char *>(addr) + shName + strdr.sh_offset;
110 if (sectionName.compare(curShName) == 0) {
111 secId = static_cast<int>(i);
112 break;
113 }
114 }
115 if (secId == -1) {
116 LOG_COMPILER(DEBUG) << "sectionName: " << sectionName << " not found in strtab";
117 continue;
118 }
119 ASSERT(secId > 0 && secId < ehdr->e_shnum);
120 llvm::ELF::Elf64_Shdr secShdr = shdrs[secId];
121 uintptr_t secAddr = reinterpret_cast<uintptr_t>(addr + secShdr.sh_offset);
122 uint32_t secSize = secShdr.sh_size;
123 switch (sec) {
124 case ElfSecName::TEXT: {
125 llvm::ELF::Elf64_Off secOffset = 0;
126 SeparateTextSections(des, secAddr, secOffset, moduledr.sh_offset);
127 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
128 break;
129 }
130 case ElfSecName::ARK_STACKMAP: {
131 llvm::ELF::Elf64_Off secOffset = 0;
132 SeparateArkStackMapSections(des, secAddr, secOffset, moduledr.sh_offset);
133 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
134 break;
135 }
136 case ElfSecName::STRTAB: {
137 llvm::ELF::Elf64_Off secOffset = 0;
138 SeparateStrtabSections(des, secAddr, secOffset, moduledr.sh_offset);
139 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
140 break;
141 }
142 case ElfSecName::SYMTAB: {
143 llvm::ELF::Elf64_Off secOffset = 0;
144 SeparateSymtabSections(des, secAddr, secOffset, moduledr.sh_offset);
145 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
146 break;
147 }
148 case ElfSecName::SHSTRTAB:
149 case ElfSecName::ARK_FUNCENTRY:
150 case ElfSecName::ARK_ASMSTUB:
151 case ElfSecName::ARK_MODULEINFO: {
152 if (sec == ElfSecName::ARK_FUNCENTRY) {
153 ASSERT((secSize > 0) && (secSize % sizeof(AOTFileInfo::FuncEntryDes) == 0));
154 }
155 des[0].SetSecAddrAndSize(sec, secAddr, secSize);
156 break;
157 }
158 default: {
159 LOG_ECMA(FATAL) << "this section should not dump to stub file";
160 break;
161 }
162 }
163 }
164 }
165
ParseELFSections(BinaryBufferParser & parser,std::vector<ModuleSectionDes> & des,std::vector<ElfSecName> & secs)166 void ElfReader::ParseELFSections(BinaryBufferParser &parser,
167 std::vector<ModuleSectionDes> &des,
168 std::vector<ElfSecName> &secs)
169 {
170 ASSERT(des.size() == ASMSTUB_MODULE_NUM);
171 uint64_t codeAddress = reinterpret_cast<uint64_t>(stubsMem_.addr_);
172 llvm::ELF::Elf64_Ehdr ehdr;
173 parser.ParseBuffer(&ehdr, sizeof(ehdr), 0);
174 std::vector<llvm::ELF::Elf64_Shdr> shdrs(ehdr.e_shnum);
175 parser.ParseBuffer(shdrs.data(), sizeof(llvm::ELF::Elf64_Shdr) * ehdr.e_shnum, ehdr.e_shoff);
176
177 ASSERT(ehdr.e_shstrndx != static_cast<llvm::ELF::Elf64_Half>(-1));
178 llvm::ELF::Elf64_Shdr strdr = shdrs[ehdr.e_shstrndx];
179 ASSERT(ehdr.e_flags != static_cast<llvm::ELF::Elf64_Word>(-1));
180 llvm::ELF::Elf64_Shdr moduledr = shdrs[ehdr.e_flags];
181 [[maybe_unused]] size_t moduleInfoSize = moduledr.sh_size;
182 uint32_t moduleNum = GetModuleNum(moduleInfoSize);
183 ASSERT(moduleNum == ASMSTUB_MODULE_NUM);
184 moduleInfo_.resize(moduleNum);
185 parser.ParseBuffer(moduleInfo_.data(), moduleInfoSize, moduledr.sh_offset);
186 std::set<ElfSecName> secSet(secs.begin(), secs.end());
187 for (ElfSecName sec : secSet) {
188 int secId = -1;
189 std::string sectionName = ModuleSectionDes::GetSecName(sec);
190 for (size_t i = 0; i < ehdr.e_shnum; ++i) {
191 llvm::ELF::Elf64_Word shName = shdrs[i].sh_name;
192 char *curShName = reinterpret_cast<char *>(parser.GetAddr()) + shName + strdr.sh_offset;
193 if (sectionName.compare(curShName) == 0) {
194 secId = static_cast<int>(i);
195 break;
196 }
197 }
198 if (secId == -1) {
199 LOG_COMPILER(DEBUG) << "sectionName: " << sectionName << " not found in strtab";
200 continue;
201 }
202 ASSERT(secId > 0 && secId < ehdr.e_shnum);
203 llvm::ELF::Elf64_Shdr secShdr = shdrs[secId];
204 uint64_t secAddr = static_cast<uint64_t>(codeAddress + secShdr.sh_offset);
205 uint32_t secSize = secShdr.sh_size;
206 switch (sec) {
207 case ElfSecName::TEXT: {
208 llvm::ELF::Elf64_Off secOffset = 0;
209 SeparateTextSections(parser, des, secAddr, secOffset, secShdr.sh_offset);
210 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
211 break;
212 }
213 case ElfSecName::ARK_STACKMAP: {
214 llvm::ELF::Elf64_Off secOffset = 0;
215 SeparateArkStackMapSections(parser, des, secAddr, secOffset, secShdr.sh_offset);
216 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
217 break;
218 }
219 case ElfSecName::STRTAB: {
220 llvm::ELF::Elf64_Off secOffset = 0;
221 SeparateStrtabSections(parser, des, secAddr, secOffset, secShdr.sh_offset);
222 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
223 break;
224 }
225 case ElfSecName::SYMTAB: {
226 llvm::ELF::Elf64_Off secOffset = 0;
227 SeparateSymtabSections(parser, des, secAddr, secOffset, secShdr.sh_offset);
228 ASSERT(static_cast<uint32_t>(secOffset) == secSize);
229 break;
230 }
231 case ElfSecName::SHSTRTAB:
232 case ElfSecName::ARK_FUNCENTRY:
233 case ElfSecName::ARK_ASMSTUB:
234 case ElfSecName::ARK_MODULEINFO: {
235 if (sec == ElfSecName::ARK_FUNCENTRY) {
236 ASSERT((secSize > 0) && (secSize % sizeof(AOTFileInfo::FuncEntryDes) == 0));
237 }
238 parser.ParseBuffer(reinterpret_cast<void *>(secAddr), secSize, secShdr.sh_offset);
239 des[0].SetSecAddrAndSize(sec, secAddr, secSize);
240 break;
241 }
242 default: {
243 LOG_ECMA(FATAL) << "this section should not dump to stub file";
244 break;
245 }
246 }
247 }
248 }
249
ParseELFSegment()250 bool ElfReader::ParseELFSegment()
251 {
252 if (fileMapMem_.GetOriginAddr() == nullptr) {
253 return false;
254 }
255 char *addr = reinterpret_cast<char *>(fileMapMem_.GetOriginAddr());
256 llvm::ELF::Elf64_Ehdr *ehdr = reinterpret_cast<llvm::ELF::Elf64_Ehdr *>(fileMapMem_.GetOriginAddr());
257 llvm::ELF::Elf64_Phdr *phdr = reinterpret_cast<llvm::ELF::Elf64_Phdr *>(addr + ehdr->e_phoff);
258 for (int i = 0; i < ehdr->e_phnum; ++i) {
259 if (phdr[i].p_type != llvm::ELF::PT_LOAD) {
260 continue;
261 }
262 if (phdr[i].p_filesz > phdr[i].p_memsz) {
263 LOG_COMPILER(ERROR) << " p_filesz:0x" << std::hex << phdr[i].p_filesz << " > p_memsz:0x"
264 << phdr[i].p_memsz;
265 return false;
266 }
267 if (!phdr[i].p_filesz) {
268 continue;
269 }
270 unsigned char *virtualAddr = reinterpret_cast<unsigned char *>(addr + phdr[i].p_vaddr);
271 ASSERT(phdr[i].p_offset % PageSize() == 0);
272 if ((phdr[i].p_flags & llvm::ELF::PF_X) != 0) {
273 ASSERT(reinterpret_cast<uintptr_t>(virtualAddr) % PageSize() == 0);
274 PageProtect(virtualAddr, phdr[i].p_memsz, PAGE_PROT_EXEC_READ);
275 }
276 }
277 return true;
278 }
279
SeparateTextSections(std::vector<ModuleSectionDes> & des,const uintptr_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & moduleInfoOffset)280 void ElfReader::SeparateTextSections(std::vector<ModuleSectionDes> &des,
281 const uintptr_t &secAddr,
282 llvm::ELF::Elf64_Off &secOffset,
283 const llvm::ELF::Elf64_Off &moduleInfoOffset)
284 {
285 for (size_t i = 0; i < des.size(); ++i) {
286 auto moduleInfo = GetCurModuleInfo(i, moduleInfoOffset);
287 secOffset = AlignUp(secOffset, AOTFileInfo::PAGE_ALIGN);
288 uint32_t rodataSizeBeforeText = moduleInfo->rodataSizeBeforeText;
289 uint32_t rodataSizeAfterText = moduleInfo->rodataSizeAfterText;
290 if (rodataSizeBeforeText != 0) {
291 secOffset += rodataSizeBeforeText;
292 secOffset = AlignUp(secOffset, AOTFileInfo::TEXT_SEC_ALIGN);
293 }
294 uint32_t textSize = moduleInfo->textSize;
295 des[i].SetSecAddrAndSize(ElfSecName::TEXT, secAddr + secOffset, textSize);
296 secOffset += textSize;
297 if (rodataSizeAfterText != 0) {
298 secOffset = AlignUp(secOffset, AOTFileInfo::DATA_SEC_ALIGN);
299 secOffset += rodataSizeAfterText;
300 }
301 }
302 }
303
SeparateArkStackMapSections(std::vector<ModuleSectionDes> & des,const uintptr_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & moduleInfoOffset)304 void ElfReader::SeparateArkStackMapSections(std::vector<ModuleSectionDes> &des,
305 const uintptr_t &secAddr,
306 llvm::ELF::Elf64_Off &secOffset,
307 const llvm::ELF::Elf64_Off &moduleInfoOffset)
308 {
309 for (size_t i = 0; i < des.size(); ++i) {
310 auto moduleInfo = GetCurModuleInfo(i, moduleInfoOffset);
311 uint32_t stackMapSize = moduleInfo->stackMapSize;
312 des[i].SetArkStackMapPtr(reinterpret_cast<uint8_t *>(secAddr + secOffset));
313 des[i].SetArkStackMapSize(stackMapSize);
314 uint32_t index = moduleInfo->startIndex;
315 uint32_t cnt = moduleInfo->funcCount;
316 des[i].SetStartIndex(index);
317 des[i].SetFuncCount(cnt);
318 secOffset += stackMapSize;
319 }
320 }
321
SeparateStrtabSections(std::vector<ModuleSectionDes> & des,const uintptr_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & moduleInfoOffset)322 void ElfReader::SeparateStrtabSections(std::vector<ModuleSectionDes> &des,
323 const uintptr_t &secAddr,
324 llvm::ELF::Elf64_Off &secOffset,
325 const llvm::ELF::Elf64_Off &moduleInfoOffset)
326 {
327 for (size_t i = 0; i < des.size(); ++i) {
328 auto moduleInfo = GetCurModuleInfo(i, moduleInfoOffset);
329 uint32_t strtabSize = moduleInfo->strtabSize;
330 des[i].SetSecAddrAndSize(ElfSecName::STRTAB, secAddr + secOffset, strtabSize);
331 secOffset += strtabSize;
332 }
333 }
334
SeparateSymtabSections(std::vector<ModuleSectionDes> & des,const uintptr_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & moduleInfoOffset)335 void ElfReader::SeparateSymtabSections(std::vector<ModuleSectionDes> &des,
336 const uintptr_t &secAddr,
337 llvm::ELF::Elf64_Off &secOffset,
338 const llvm::ELF::Elf64_Off &moduleInfoOffset)
339 {
340 for (size_t i = 0; i < des.size(); ++i) {
341 auto moduleInfo = GetCurModuleInfo(i, moduleInfoOffset);
342 uint32_t symtabSize = moduleInfo->symtabSize;
343 des[i].SetSecAddrAndSize(ElfSecName::SYMTAB, secAddr + secOffset, symtabSize);
344 secOffset += symtabSize;
345 }
346 }
347
SeparateTextSections(BinaryBufferParser & parser,std::vector<ModuleSectionDes> & des,const uint64_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & curShOffset)348 void ElfReader::SeparateTextSections(BinaryBufferParser &parser,
349 std::vector<ModuleSectionDes> &des,
350 const uint64_t &secAddr,
351 llvm::ELF::Elf64_Off &secOffset,
352 const llvm::ELF::Elf64_Off &curShOffset)
353 {
354 for (size_t i = 0; i < des.size(); ++i) {
355 auto moduleInfo = moduleInfo_[i];
356 secOffset = AlignUp(secOffset, AOTFileInfo::PAGE_ALIGN);
357 uint32_t rodataSizeBeforeText = moduleInfo.rodataSizeBeforeText;
358 uint32_t rodataSizeAfterText = moduleInfo.rodataSizeAfterText;
359 if (rodataSizeBeforeText != 0) {
360 parser.ParseBuffer(reinterpret_cast<void *>(secAddr + secOffset), rodataSizeBeforeText,
361 curShOffset + secOffset);
362 secOffset += rodataSizeBeforeText;
363 secOffset = AlignUp(secOffset, AOTFileInfo::TEXT_SEC_ALIGN);
364 }
365 uint32_t textSize = moduleInfo.textSize;
366 parser.ParseBuffer(reinterpret_cast<void *>(secAddr + secOffset), textSize, curShOffset + secOffset);
367 des[i].SetSecAddrAndSize(ElfSecName::TEXT, secAddr + secOffset, textSize);
368 secOffset += textSize;
369 if (rodataSizeAfterText != 0) {
370 secOffset = AlignUp(secOffset, AOTFileInfo::DATA_SEC_ALIGN);
371 parser.ParseBuffer(reinterpret_cast<void *>(secAddr + secOffset), rodataSizeAfterText,
372 curShOffset + secOffset);
373 secOffset += rodataSizeAfterText;
374 }
375 }
376 }
377
SeparateArkStackMapSections(BinaryBufferParser & parser,std::vector<ModuleSectionDes> & des,const uint64_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & curShOffset)378 void ElfReader::SeparateArkStackMapSections(BinaryBufferParser &parser,
379 std::vector<ModuleSectionDes> &des,
380 const uint64_t &secAddr,
381 llvm::ELF::Elf64_Off &secOffset,
382 const llvm::ELF::Elf64_Off &curShOffset)
383 {
384 for (size_t i = 0; i < des.size(); ++i) {
385 auto moduleInfo = moduleInfo_[i];
386 uint32_t stackMapSize = moduleInfo.stackMapSize;
387 parser.ParseBuffer(reinterpret_cast<void *>(secAddr + secOffset), stackMapSize, curShOffset + secOffset);
388 des[i].SetArkStackMapPtr(reinterpret_cast<uint8_t *>(secAddr + secOffset));
389 des[i].SetArkStackMapSize(stackMapSize);
390 uint32_t index = moduleInfo.startIndex;
391 uint32_t cnt = moduleInfo.funcCount;
392 des[i].SetStartIndex(index);
393 des[i].SetFuncCount(cnt);
394 secOffset += stackMapSize;
395 }
396 }
397
SeparateStrtabSections(BinaryBufferParser & parser,std::vector<ModuleSectionDes> & des,const uintptr_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & curShOffset)398 void ElfReader::SeparateStrtabSections(BinaryBufferParser &parser,
399 std::vector<ModuleSectionDes> &des,
400 const uintptr_t &secAddr,
401 llvm::ELF::Elf64_Off &secOffset,
402 const llvm::ELF::Elf64_Off &curShOffset)
403 {
404 for (size_t i = 0; i < des.size(); ++i) {
405 auto moduleInfo = moduleInfo_[i];
406 uint32_t strtabSize = moduleInfo.strtabSize;
407 parser.ParseBuffer(reinterpret_cast<void *>(secAddr + secOffset), strtabSize, curShOffset + secOffset);
408 des[i].SetSecAddrAndSize(ElfSecName::STRTAB, secAddr + secOffset, strtabSize);
409 secOffset += strtabSize;
410 }
411 }
412
SeparateSymtabSections(BinaryBufferParser & parser,std::vector<ModuleSectionDes> & des,const uintptr_t & secAddr,llvm::ELF::Elf64_Off & secOffset,const llvm::ELF::Elf64_Off & curShOffset)413 void ElfReader::SeparateSymtabSections(BinaryBufferParser &parser,
414 std::vector<ModuleSectionDes> &des,
415 const uintptr_t &secAddr,
416 llvm::ELF::Elf64_Off &secOffset,
417 const llvm::ELF::Elf64_Off &curShOffset)
418 {
419 for (size_t i = 0; i < des.size(); ++i) {
420 auto moduleInfo = moduleInfo_[i];
421 uint32_t symtabSize = moduleInfo.symtabSize;
422 parser.ParseBuffer(reinterpret_cast<void *>(secAddr + secOffset), symtabSize, curShOffset + secOffset);
423 des[i].SetSecAddrAndSize(ElfSecName::SYMTAB, secAddr + secOffset, symtabSize);
424 secOffset += symtabSize;
425 }
426 }
427 } // namespace panda::ecmascript
428