]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Elf64 convert solution\r | |
3 | \r | |
4 | Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | Portions copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>\r | |
6 | \r | |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
8 | \r | |
9 | **/\r | |
10 | \r | |
11 | #include "WinNtInclude.h"\r | |
12 | \r | |
13 | #ifndef __GNUC__\r | |
14 | #include <windows.h>\r | |
15 | #include <io.h>\r | |
16 | #endif\r | |
17 | #include <assert.h>\r | |
18 | #include <stdio.h>\r | |
19 | #include <stdlib.h>\r | |
20 | #include <string.h>\r | |
21 | #include <time.h>\r | |
22 | #include <ctype.h>\r | |
23 | \r | |
24 | #include <Common/UefiBaseTypes.h>\r | |
25 | #include <IndustryStandard/PeImage.h>\r | |
26 | \r | |
27 | #include "PeCoffLib.h"\r | |
28 | #include "EfiUtilityMsgs.h"\r | |
29 | \r | |
30 | #include "GenFw.h"\r | |
31 | #include "ElfConvert.h"\r | |
32 | #include "Elf64Convert.h"\r | |
33 | \r | |
34 | STATIC\r | |
35 | VOID\r | |
36 | ScanSections64 (\r | |
37 | VOID\r | |
38 | );\r | |
39 | \r | |
40 | STATIC\r | |
41 | BOOLEAN\r | |
42 | WriteSections64 (\r | |
43 | SECTION_FILTER_TYPES FilterType\r | |
44 | );\r | |
45 | \r | |
46 | STATIC\r | |
47 | VOID\r | |
48 | WriteRelocations64 (\r | |
49 | VOID\r | |
50 | );\r | |
51 | \r | |
52 | STATIC\r | |
53 | VOID\r | |
54 | WriteDebug64 (\r | |
55 | VOID\r | |
56 | );\r | |
57 | \r | |
58 | STATIC\r | |
59 | VOID\r | |
60 | SetImageSize64 (\r | |
61 | VOID\r | |
62 | );\r | |
63 | \r | |
64 | STATIC\r | |
65 | VOID\r | |
66 | CleanUp64 (\r | |
67 | VOID\r | |
68 | );\r | |
69 | \r | |
70 | //\r | |
71 | // Rename ELF32 structures to common names to help when porting to ELF64.\r | |
72 | //\r | |
73 | typedef Elf64_Shdr Elf_Shdr;\r | |
74 | typedef Elf64_Ehdr Elf_Ehdr;\r | |
75 | typedef Elf64_Rel Elf_Rel;\r | |
76 | typedef Elf64_Rela Elf_Rela;\r | |
77 | typedef Elf64_Sym Elf_Sym;\r | |
78 | typedef Elf64_Phdr Elf_Phdr;\r | |
79 | typedef Elf64_Dyn Elf_Dyn;\r | |
80 | #define ELFCLASS ELFCLASS64\r | |
81 | #define ELF_R_TYPE(r) ELF64_R_TYPE(r)\r | |
82 | #define ELF_R_SYM(r) ELF64_R_SYM(r)\r | |
83 | \r | |
84 | //\r | |
85 | // Well known ELF structures.\r | |
86 | //\r | |
87 | STATIC Elf_Ehdr *mEhdr;\r | |
88 | STATIC Elf_Shdr *mShdrBase;\r | |
89 | STATIC Elf_Phdr *mPhdrBase;\r | |
90 | \r | |
91 | //\r | |
92 | // GOT information\r | |
93 | //\r | |
94 | STATIC Elf_Shdr *mGOTShdr = NULL;\r | |
95 | STATIC UINT32 mGOTShindex = 0;\r | |
96 | STATIC UINT32 *mGOTCoffEntries = NULL;\r | |
97 | STATIC UINT32 mGOTMaxCoffEntries = 0;\r | |
98 | STATIC UINT32 mGOTNumCoffEntries = 0;\r | |
99 | \r | |
100 | //\r | |
101 | // Coff information\r | |
102 | //\r | |
103 | STATIC UINT32 mCoffAlignment = 0x20;\r | |
104 | \r | |
105 | //\r | |
106 | // PE section alignment.\r | |
107 | //\r | |
108 | STATIC const UINT16 mCoffNbrSections = 4;\r | |
109 | \r | |
110 | //\r | |
111 | // ELF sections to offset in Coff file.\r | |
112 | //\r | |
113 | STATIC UINT32 *mCoffSectionsOffset = NULL;\r | |
114 | \r | |
115 | //\r | |
116 | // Offsets in COFF file\r | |
117 | //\r | |
118 | STATIC UINT32 mNtHdrOffset;\r | |
119 | STATIC UINT32 mTextOffset;\r | |
120 | STATIC UINT32 mDataOffset;\r | |
121 | STATIC UINT32 mHiiRsrcOffset;\r | |
122 | STATIC UINT32 mRelocOffset;\r | |
123 | STATIC UINT32 mDebugOffset;\r | |
124 | \r | |
125 | //\r | |
126 | // Initialization Function\r | |
127 | //\r | |
128 | BOOLEAN\r | |
129 | InitializeElf64 (\r | |
130 | UINT8 *FileBuffer,\r | |
131 | ELF_FUNCTION_TABLE *ElfFunctions\r | |
132 | )\r | |
133 | {\r | |
134 | //\r | |
135 | // Initialize data pointer and structures.\r | |
136 | //\r | |
137 | VerboseMsg ("Set EHDR");\r | |
138 | mEhdr = (Elf_Ehdr*) FileBuffer;\r | |
139 | \r | |
140 | //\r | |
141 | // Check the ELF64 specific header information.\r | |
142 | //\r | |
143 | VerboseMsg ("Check ELF64 Header Information");\r | |
144 | if (mEhdr->e_ident[EI_CLASS] != ELFCLASS64) {\r | |
145 | Error (NULL, 0, 3000, "Unsupported", "ELF EI_DATA not ELFCLASS64");\r | |
146 | return FALSE;\r | |
147 | }\r | |
148 | if (mEhdr->e_ident[EI_DATA] != ELFDATA2LSB) {\r | |
149 | Error (NULL, 0, 3000, "Unsupported", "ELF EI_DATA not ELFDATA2LSB");\r | |
150 | return FALSE;\r | |
151 | }\r | |
152 | if ((mEhdr->e_type != ET_EXEC) && (mEhdr->e_type != ET_DYN)) {\r | |
153 | Error (NULL, 0, 3000, "Unsupported", "ELF e_type not ET_EXEC or ET_DYN");\r | |
154 | return FALSE;\r | |
155 | }\r | |
156 | if (!((mEhdr->e_machine == EM_X86_64) || (mEhdr->e_machine == EM_AARCH64))) {\r | |
157 | Error (NULL, 0, 3000, "Unsupported", "ELF e_machine not EM_X86_64 or EM_AARCH64");\r | |
158 | return FALSE;\r | |
159 | }\r | |
160 | if (mEhdr->e_version != EV_CURRENT) {\r | |
161 | Error (NULL, 0, 3000, "Unsupported", "ELF e_version (%u) not EV_CURRENT (%d)", (unsigned) mEhdr->e_version, EV_CURRENT);\r | |
162 | return FALSE;\r | |
163 | }\r | |
164 | \r | |
165 | //\r | |
166 | // Update section header pointers\r | |
167 | //\r | |
168 | VerboseMsg ("Update Header Pointers");\r | |
169 | mShdrBase = (Elf_Shdr *)((UINT8 *)mEhdr + mEhdr->e_shoff);\r | |
170 | mPhdrBase = (Elf_Phdr *)((UINT8 *)mEhdr + mEhdr->e_phoff);\r | |
171 | \r | |
172 | //\r | |
173 | // Create COFF Section offset buffer and zero.\r | |
174 | //\r | |
175 | VerboseMsg ("Create COFF Section Offset Buffer");\r | |
176 | mCoffSectionsOffset = (UINT32 *)malloc(mEhdr->e_shnum * sizeof (UINT32));\r | |
177 | if (mCoffSectionsOffset == NULL) {\r | |
178 | Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r | |
179 | return FALSE;\r | |
180 | }\r | |
181 | memset(mCoffSectionsOffset, 0, mEhdr->e_shnum * sizeof(UINT32));\r | |
182 | \r | |
183 | //\r | |
184 | // Fill in function pointers.\r | |
185 | //\r | |
186 | VerboseMsg ("Fill in Function Pointers");\r | |
187 | ElfFunctions->ScanSections = ScanSections64;\r | |
188 | ElfFunctions->WriteSections = WriteSections64;\r | |
189 | ElfFunctions->WriteRelocations = WriteRelocations64;\r | |
190 | ElfFunctions->WriteDebug = WriteDebug64;\r | |
191 | ElfFunctions->SetImageSize = SetImageSize64;\r | |
192 | ElfFunctions->CleanUp = CleanUp64;\r | |
193 | \r | |
194 | return TRUE;\r | |
195 | }\r | |
196 | \r | |
197 | \r | |
198 | //\r | |
199 | // Header by Index functions\r | |
200 | //\r | |
201 | STATIC\r | |
202 | Elf_Shdr*\r | |
203 | GetShdrByIndex (\r | |
204 | UINT32 Num\r | |
205 | )\r | |
206 | {\r | |
207 | if (Num >= mEhdr->e_shnum) {\r | |
208 | Error (NULL, 0, 3000, "Invalid", "GetShdrByIndex: Index %u is too high.", Num);\r | |
209 | exit(EXIT_FAILURE);\r | |
210 | }\r | |
211 | \r | |
212 | return (Elf_Shdr*)((UINT8*)mShdrBase + Num * mEhdr->e_shentsize);\r | |
213 | }\r | |
214 | \r | |
215 | STATIC\r | |
216 | UINT32\r | |
217 | CoffAlign (\r | |
218 | UINT32 Offset\r | |
219 | )\r | |
220 | {\r | |
221 | return (Offset + mCoffAlignment - 1) & ~(mCoffAlignment - 1);\r | |
222 | }\r | |
223 | \r | |
224 | STATIC\r | |
225 | UINT32\r | |
226 | DebugRvaAlign (\r | |
227 | UINT32 Offset\r | |
228 | )\r | |
229 | {\r | |
230 | return (Offset + 3) & ~3;\r | |
231 | }\r | |
232 | \r | |
233 | //\r | |
234 | // filter functions\r | |
235 | //\r | |
236 | STATIC\r | |
237 | BOOLEAN\r | |
238 | IsTextShdr (\r | |
239 | Elf_Shdr *Shdr\r | |
240 | )\r | |
241 | {\r | |
242 | return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == SHF_ALLOC);\r | |
243 | }\r | |
244 | \r | |
245 | STATIC\r | |
246 | BOOLEAN\r | |
247 | IsHiiRsrcShdr (\r | |
248 | Elf_Shdr *Shdr\r | |
249 | )\r | |
250 | {\r | |
251 | Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);\r | |
252 | \r | |
253 | return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_name, ELF_HII_SECTION_NAME) == 0);\r | |
254 | }\r | |
255 | \r | |
256 | STATIC\r | |
257 | BOOLEAN\r | |
258 | IsDataShdr (\r | |
259 | Elf_Shdr *Shdr\r | |
260 | )\r | |
261 | {\r | |
262 | if (IsHiiRsrcShdr(Shdr)) {\r | |
263 | return FALSE;\r | |
264 | }\r | |
265 | return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE);\r | |
266 | }\r | |
267 | \r | |
268 | STATIC\r | |
269 | BOOLEAN\r | |
270 | IsStrtabShdr (\r | |
271 | Elf_Shdr *Shdr\r | |
272 | )\r | |
273 | {\r | |
274 | Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);\r | |
275 | \r | |
276 | return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_name, ELF_STRTAB_SECTION_NAME) == 0);\r | |
277 | }\r | |
278 | \r | |
279 | STATIC\r | |
280 | Elf_Shdr *\r | |
281 | FindStrtabShdr (\r | |
282 | VOID\r | |
283 | )\r | |
284 | {\r | |
285 | UINT32 i;\r | |
286 | for (i = 0; i < mEhdr->e_shnum; i++) {\r | |
287 | Elf_Shdr *shdr = GetShdrByIndex(i);\r | |
288 | if (IsStrtabShdr(shdr)) {\r | |
289 | return shdr;\r | |
290 | }\r | |
291 | }\r | |
292 | return NULL;\r | |
293 | }\r | |
294 | \r | |
295 | STATIC\r | |
296 | const UINT8 *\r | |
297 | GetSymName (\r | |
298 | Elf_Sym *Sym\r | |
299 | )\r | |
300 | {\r | |
301 | Elf_Shdr *StrtabShdr;\r | |
302 | UINT8 *StrtabContents;\r | |
303 | BOOLEAN foundEnd;\r | |
304 | UINT32 i;\r | |
305 | \r | |
306 | if (Sym->st_name == 0) {\r | |
307 | return NULL;\r | |
308 | }\r | |
309 | \r | |
310 | StrtabShdr = FindStrtabShdr();\r | |
311 | if (StrtabShdr == NULL) {\r | |
312 | return NULL;\r | |
313 | }\r | |
314 | \r | |
315 | assert(Sym->st_name < StrtabShdr->sh_size);\r | |
316 | \r | |
317 | StrtabContents = (UINT8*)mEhdr + StrtabShdr->sh_offset;\r | |
318 | \r | |
319 | foundEnd = FALSE;\r | |
320 | for (i= Sym->st_name; (i < StrtabShdr->sh_size) && !foundEnd; i++) {\r | |
321 | foundEnd = (BOOLEAN)(StrtabContents[i] == 0);\r | |
322 | }\r | |
323 | assert(foundEnd);\r | |
324 | \r | |
325 | return StrtabContents + Sym->st_name;\r | |
326 | }\r | |
327 | \r | |
328 | //\r | |
329 | // Find the ELF section hosting the GOT from an ELF Rva\r | |
330 | // of a single GOT entry. Normally, GOT is placed in\r | |
331 | // ELF .text section, so assume once we find in which\r | |
332 | // section the GOT is, all GOT entries are there, and\r | |
333 | // just verify this.\r | |
334 | //\r | |
335 | STATIC\r | |
336 | VOID\r | |
337 | FindElfGOTSectionFromGOTEntryElfRva (\r | |
338 | Elf64_Addr GOTEntryElfRva\r | |
339 | )\r | |
340 | {\r | |
341 | UINT32 i;\r | |
342 | if (mGOTShdr != NULL) {\r | |
343 | if (GOTEntryElfRva >= mGOTShdr->sh_addr &&\r | |
344 | GOTEntryElfRva < mGOTShdr->sh_addr + mGOTShdr->sh_size) {\r | |
345 | return;\r | |
346 | }\r | |
347 | Error (NULL, 0, 3000, "Unsupported", "FindElfGOTSectionFromGOTEntryElfRva: GOT entries found in multiple sections.");\r | |
348 | exit(EXIT_FAILURE);\r | |
349 | }\r | |
350 | for (i = 0; i < mEhdr->e_shnum; i++) {\r | |
351 | Elf_Shdr *shdr = GetShdrByIndex(i);\r | |
352 | if (GOTEntryElfRva >= shdr->sh_addr &&\r | |
353 | GOTEntryElfRva < shdr->sh_addr + shdr->sh_size) {\r | |
354 | mGOTShdr = shdr;\r | |
355 | mGOTShindex = i;\r | |
356 | return;\r | |
357 | }\r | |
358 | }\r | |
359 | Error (NULL, 0, 3000, "Invalid", "FindElfGOTSectionFromGOTEntryElfRva: ElfRva 0x%016LX for GOT entry not found in any section.", GOTEntryElfRva);\r | |
360 | exit(EXIT_FAILURE);\r | |
361 | }\r | |
362 | \r | |
363 | //\r | |
364 | // Stores locations of GOT entries in COFF image.\r | |
365 | // Returns TRUE if GOT entry is new.\r | |
366 | // Simple implementation as number of GOT\r | |
367 | // entries is expected to be low.\r | |
368 | //\r | |
369 | \r | |
370 | STATIC\r | |
371 | BOOLEAN\r | |
372 | AccumulateCoffGOTEntries (\r | |
373 | UINT32 GOTCoffEntry\r | |
374 | )\r | |
375 | {\r | |
376 | UINT32 i;\r | |
377 | if (mGOTCoffEntries != NULL) {\r | |
378 | for (i = 0; i < mGOTNumCoffEntries; i++) {\r | |
379 | if (mGOTCoffEntries[i] == GOTCoffEntry) {\r | |
380 | return FALSE;\r | |
381 | }\r | |
382 | }\r | |
383 | }\r | |
384 | if (mGOTCoffEntries == NULL) {\r | |
385 | mGOTCoffEntries = (UINT32*)malloc(5 * sizeof *mGOTCoffEntries);\r | |
386 | if (mGOTCoffEntries == NULL) {\r | |
387 | Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r | |
388 | }\r | |
389 | assert (mGOTCoffEntries != NULL);\r | |
390 | mGOTMaxCoffEntries = 5;\r | |
391 | mGOTNumCoffEntries = 0;\r | |
392 | } else if (mGOTNumCoffEntries == mGOTMaxCoffEntries) {\r | |
393 | mGOTCoffEntries = (UINT32*)realloc(mGOTCoffEntries, 2 * mGOTMaxCoffEntries * sizeof *mGOTCoffEntries);\r | |
394 | if (mGOTCoffEntries == NULL) {\r | |
395 | Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r | |
396 | }\r | |
397 | assert (mGOTCoffEntries != NULL);\r | |
398 | mGOTMaxCoffEntries += mGOTMaxCoffEntries;\r | |
399 | }\r | |
400 | mGOTCoffEntries[mGOTNumCoffEntries++] = GOTCoffEntry;\r | |
401 | return TRUE;\r | |
402 | }\r | |
403 | \r | |
404 | //\r | |
405 | // 32-bit Unsigned integer comparator for qsort.\r | |
406 | //\r | |
407 | STATIC\r | |
408 | int\r | |
409 | UINT32Comparator (\r | |
410 | const void* lhs,\r | |
411 | const void* rhs\r | |
412 | )\r | |
413 | {\r | |
414 | if (*(const UINT32*)lhs < *(const UINT32*)rhs) {\r | |
415 | return -1;\r | |
416 | }\r | |
417 | return *(const UINT32*)lhs > *(const UINT32*)rhs;\r | |
418 | }\r | |
419 | \r | |
420 | //\r | |
421 | // Emit accumulated Coff GOT entry relocations into\r | |
422 | // Coff image. This function performs its job\r | |
423 | // once and then releases the entry list, so\r | |
424 | // it can safely be called multiple times.\r | |
425 | //\r | |
426 | STATIC\r | |
427 | VOID\r | |
428 | EmitGOTRelocations (\r | |
429 | VOID\r | |
430 | )\r | |
431 | {\r | |
432 | UINT32 i;\r | |
433 | if (mGOTCoffEntries == NULL) {\r | |
434 | return;\r | |
435 | }\r | |
436 | //\r | |
437 | // Emit Coff relocations with Rvas ordered.\r | |
438 | //\r | |
439 | qsort(\r | |
440 | mGOTCoffEntries,\r | |
441 | mGOTNumCoffEntries,\r | |
442 | sizeof *mGOTCoffEntries,\r | |
443 | UINT32Comparator);\r | |
444 | for (i = 0; i < mGOTNumCoffEntries; i++) {\r | |
445 | VerboseMsg ("EFI_IMAGE_REL_BASED_DIR64 Offset: 0x%08X", mGOTCoffEntries[i]);\r | |
446 | CoffAddFixup(\r | |
447 | mGOTCoffEntries[i],\r | |
448 | EFI_IMAGE_REL_BASED_DIR64);\r | |
449 | }\r | |
450 | free(mGOTCoffEntries);\r | |
451 | mGOTCoffEntries = NULL;\r | |
452 | mGOTMaxCoffEntries = 0;\r | |
453 | mGOTNumCoffEntries = 0;\r | |
454 | }\r | |
455 | \r | |
456 | //\r | |
457 | // Elf functions interface implementation\r | |
458 | //\r | |
459 | \r | |
460 | STATIC\r | |
461 | VOID\r | |
462 | ScanSections64 (\r | |
463 | VOID\r | |
464 | )\r | |
465 | {\r | |
466 | UINT32 i;\r | |
467 | EFI_IMAGE_DOS_HEADER *DosHdr;\r | |
468 | EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;\r | |
469 | UINT32 CoffEntry;\r | |
470 | UINT32 SectionCount;\r | |
471 | BOOLEAN FoundSection;\r | |
472 | \r | |
473 | CoffEntry = 0;\r | |
474 | mCoffOffset = 0;\r | |
475 | \r | |
476 | //\r | |
477 | // Coff file start with a DOS header.\r | |
478 | //\r | |
479 | mCoffOffset = sizeof(EFI_IMAGE_DOS_HEADER) + 0x40;\r | |
480 | mNtHdrOffset = mCoffOffset;\r | |
481 | switch (mEhdr->e_machine) {\r | |
482 | case EM_X86_64:\r | |
483 | case EM_AARCH64:\r | |
484 | mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64);\r | |
485 | break;\r | |
486 | default:\r | |
487 | VerboseMsg ("%s unknown e_machine type %hu. Assume X64", mInImageName, mEhdr->e_machine);\r | |
488 | mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64);\r | |
489 | break;\r | |
490 | }\r | |
491 | \r | |
492 | mTableOffset = mCoffOffset;\r | |
493 | mCoffOffset += mCoffNbrSections * sizeof(EFI_IMAGE_SECTION_HEADER);\r | |
494 | \r | |
495 | //\r | |
496 | // Set mCoffAlignment to the maximum alignment of the input sections\r | |
497 | // we care about\r | |
498 | //\r | |
499 | for (i = 0; i < mEhdr->e_shnum; i++) {\r | |
500 | Elf_Shdr *shdr = GetShdrByIndex(i);\r | |
501 | if (shdr->sh_addralign <= mCoffAlignment) {\r | |
502 | continue;\r | |
503 | }\r | |
504 | if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {\r | |
505 | mCoffAlignment = (UINT32)shdr->sh_addralign;\r | |
506 | }\r | |
507 | }\r | |
508 | \r | |
509 | //\r | |
510 | // Check if mCoffAlignment is larger than MAX_COFF_ALIGNMENT\r | |
511 | //\r | |
512 | if (mCoffAlignment > MAX_COFF_ALIGNMENT) {\r | |
513 | Error (NULL, 0, 3000, "Invalid", "Section alignment is larger than MAX_COFF_ALIGNMENT.");\r | |
514 | assert (FALSE);\r | |
515 | }\r | |
516 | \r | |
517 | \r | |
518 | //\r | |
519 | // Move the PE/COFF header right before the first section. This will help us\r | |
520 | // save space when converting to TE.\r | |
521 | //\r | |
522 | if (mCoffAlignment > mCoffOffset) {\r | |
523 | mNtHdrOffset += mCoffAlignment - mCoffOffset;\r | |
524 | mTableOffset += mCoffAlignment - mCoffOffset;\r | |
525 | mCoffOffset = mCoffAlignment;\r | |
526 | }\r | |
527 | \r | |
528 | //\r | |
529 | // First text sections.\r | |
530 | //\r | |
531 | mCoffOffset = CoffAlign(mCoffOffset);\r | |
532 | mTextOffset = mCoffOffset;\r | |
533 | FoundSection = FALSE;\r | |
534 | SectionCount = 0;\r | |
535 | for (i = 0; i < mEhdr->e_shnum; i++) {\r | |
536 | Elf_Shdr *shdr = GetShdrByIndex(i);\r | |
537 | if (IsTextShdr(shdr)) {\r | |
538 | if ((shdr->sh_addralign != 0) && (shdr->sh_addralign != 1)) {\r | |
539 | // the alignment field is valid\r | |
540 | if ((shdr->sh_addr & (shdr->sh_addralign - 1)) == 0) {\r | |
541 | // if the section address is aligned we must align PE/COFF\r | |
542 | mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));\r | |
543 | } else {\r | |
544 | Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");\r | |
545 | }\r | |
546 | }\r | |
547 | \r | |
548 | /* Relocate entry. */\r | |
549 | if ((mEhdr->e_entry >= shdr->sh_addr) &&\r | |
550 | (mEhdr->e_entry < shdr->sh_addr + shdr->sh_size)) {\r | |
551 | CoffEntry = (UINT32) (mCoffOffset + mEhdr->e_entry - shdr->sh_addr);\r | |
552 | }\r | |
553 | \r | |
554 | //\r | |
555 | // Set mTextOffset with the offset of the first '.text' section\r | |
556 | //\r | |
557 | if (!FoundSection) {\r | |
558 | mTextOffset = mCoffOffset;\r | |
559 | FoundSection = TRUE;\r | |
560 | }\r | |
561 | \r | |
562 | mCoffSectionsOffset[i] = mCoffOffset;\r | |
563 | mCoffOffset += (UINT32) shdr->sh_size;\r | |
564 | SectionCount ++;\r | |
565 | }\r | |
566 | }\r | |
567 | \r | |
568 | if (!FoundSection) {\r | |
569 | Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");\r | |
570 | assert (FALSE);\r | |
571 | }\r | |
572 | \r | |
573 | mDebugOffset = DebugRvaAlign(mCoffOffset);\r | |
574 | mCoffOffset = CoffAlign(mCoffOffset);\r | |
575 | \r | |
576 | if (SectionCount > 1 && mOutImageType == FW_EFI_IMAGE) {\r | |
577 | Warning (NULL, 0, 0, NULL, "Multiple sections in %s are merged into 1 text section. Source level debug might not work correctly.", mInImageName);\r | |
578 | }\r | |
579 | \r | |
580 | //\r | |
581 | // Then data sections.\r | |
582 | //\r | |
583 | mDataOffset = mCoffOffset;\r | |
584 | FoundSection = FALSE;\r | |
585 | SectionCount = 0;\r | |
586 | for (i = 0; i < mEhdr->e_shnum; i++) {\r | |
587 | Elf_Shdr *shdr = GetShdrByIndex(i);\r | |
588 | if (IsDataShdr(shdr)) {\r | |
589 | if ((shdr->sh_addralign != 0) && (shdr->sh_addralign != 1)) {\r | |
590 | // the alignment field is valid\r | |
591 | if ((shdr->sh_addr & (shdr->sh_addralign - 1)) == 0) {\r | |
592 | // if the section address is aligned we must align PE/COFF\r | |
593 | mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));\r | |
594 | } else {\r | |
595 | Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");\r | |
596 | }\r | |
597 | }\r | |
598 | \r | |
599 | //\r | |
600 | // Set mDataOffset with the offset of the first '.data' section\r | |
601 | //\r | |
602 | if (!FoundSection) {\r | |
603 | mDataOffset = mCoffOffset;\r | |
604 | FoundSection = TRUE;\r | |
605 | }\r | |
606 | mCoffSectionsOffset[i] = mCoffOffset;\r | |
607 | mCoffOffset += (UINT32) shdr->sh_size;\r | |
608 | SectionCount ++;\r | |
609 | }\r | |
610 | }\r | |
611 | \r | |
612 | //\r | |
613 | // Make room for .debug data in .data (or .text if .data is empty) instead of\r | |
614 | // putting it in a section of its own. This is explicitly allowed by the\r | |
615 | // PE/COFF spec, and prevents bloat in the binary when using large values for\r | |
616 | // section alignment.\r | |
617 | //\r | |
618 | if (SectionCount > 0) {\r | |
619 | mDebugOffset = DebugRvaAlign(mCoffOffset);\r | |
620 | }\r | |
621 | mCoffOffset = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY) +\r | |
622 | sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) +\r | |
623 | strlen(mInImageName) + 1;\r | |
624 | \r | |
625 | mCoffOffset = CoffAlign(mCoffOffset);\r | |
626 | if (SectionCount == 0) {\r | |
627 | mDataOffset = mCoffOffset;\r | |
628 | }\r | |
629 | \r | |
630 | if (SectionCount > 1 && mOutImageType == FW_EFI_IMAGE) {\r | |
631 | Warning (NULL, 0, 0, NULL, "Multiple sections in %s are merged into 1 data section. Source level debug might not work correctly.", mInImageName);\r | |
632 | }\r | |
633 | \r | |
634 | //\r | |
635 | // The HII resource sections.\r | |
636 | //\r | |
637 | mHiiRsrcOffset = mCoffOffset;\r | |
638 | for (i = 0; i < mEhdr->e_shnum; i++) {\r | |
639 | Elf_Shdr *shdr = GetShdrByIndex(i);\r | |
640 | if (IsHiiRsrcShdr(shdr)) {\r | |
641 | if ((shdr->sh_addralign != 0) && (shdr->sh_addralign != 1)) {\r | |
642 | // the alignment field is valid\r | |
643 | if ((shdr->sh_addr & (shdr->sh_addralign - 1)) == 0) {\r | |
644 | // if the section address is aligned we must align PE/COFF\r | |
645 | mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));\r | |
646 | } else {\r | |
647 | Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");\r | |
648 | }\r | |
649 | }\r | |
650 | if (shdr->sh_size != 0) {\r | |
651 | mHiiRsrcOffset = mCoffOffset;\r | |
652 | mCoffSectionsOffset[i] = mCoffOffset;\r | |
653 | mCoffOffset += (UINT32) shdr->sh_size;\r | |
654 | mCoffOffset = CoffAlign(mCoffOffset);\r | |
655 | SetHiiResourceHeader ((UINT8*) mEhdr + shdr->sh_offset, mHiiRsrcOffset);\r | |
656 | }\r | |
657 | break;\r | |
658 | }\r | |
659 | }\r | |
660 | \r | |
661 | mRelocOffset = mCoffOffset;\r | |
662 | \r | |
663 | //\r | |
664 | // Allocate base Coff file. Will be expanded later for relocations.\r | |
665 | //\r | |
666 | mCoffFile = (UINT8 *)malloc(mCoffOffset);\r | |
667 | if (mCoffFile == NULL) {\r | |
668 | Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r | |
669 | }\r | |
670 | assert (mCoffFile != NULL);\r | |
671 | memset(mCoffFile, 0, mCoffOffset);\r | |
672 | \r | |
673 | //\r | |
674 | // Fill headers.\r | |
675 | //\r | |
676 | DosHdr = (EFI_IMAGE_DOS_HEADER *)mCoffFile;\r | |
677 | DosHdr->e_magic = EFI_IMAGE_DOS_SIGNATURE;\r | |
678 | DosHdr->e_lfanew = mNtHdrOffset;\r | |
679 | \r | |
680 | NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION*)(mCoffFile + mNtHdrOffset);\r | |
681 | \r | |
682 | NtHdr->Pe32Plus.Signature = EFI_IMAGE_NT_SIGNATURE;\r | |
683 | \r | |
684 | switch (mEhdr->e_machine) {\r | |
685 | case EM_X86_64:\r | |
686 | NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_X64;\r | |
687 | NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r | |
688 | break;\r | |
689 | case EM_AARCH64:\r | |
690 | NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_AARCH64;\r | |
691 | NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r | |
692 | break;\r | |
693 | default:\r | |
694 | VerboseMsg ("%s unknown e_machine type. Assume X64", (UINTN)mEhdr->e_machine);\r | |
695 | NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_X64;\r | |
696 | NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r | |
697 | }\r | |
698 | \r | |
699 | NtHdr->Pe32Plus.FileHeader.NumberOfSections = mCoffNbrSections;\r | |
700 | NtHdr->Pe32Plus.FileHeader.TimeDateStamp = (UINT32) time(NULL);\r | |
701 | mImageTimeStamp = NtHdr->Pe32Plus.FileHeader.TimeDateStamp;\r | |
702 | NtHdr->Pe32Plus.FileHeader.PointerToSymbolTable = 0;\r | |
703 | NtHdr->Pe32Plus.FileHeader.NumberOfSymbols = 0;\r | |
704 | NtHdr->Pe32Plus.FileHeader.SizeOfOptionalHeader = sizeof(NtHdr->Pe32Plus.OptionalHeader);\r | |
705 | NtHdr->Pe32Plus.FileHeader.Characteristics = EFI_IMAGE_FILE_EXECUTABLE_IMAGE\r | |
706 | | EFI_IMAGE_FILE_LINE_NUMS_STRIPPED\r | |
707 | | EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED\r | |
708 | | EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE;\r | |
709 | \r | |
710 | NtHdr->Pe32Plus.OptionalHeader.SizeOfCode = mDataOffset - mTextOffset;\r | |
711 | NtHdr->Pe32Plus.OptionalHeader.SizeOfInitializedData = mRelocOffset - mDataOffset;\r | |
712 | NtHdr->Pe32Plus.OptionalHeader.SizeOfUninitializedData = 0;\r | |
713 | NtHdr->Pe32Plus.OptionalHeader.AddressOfEntryPoint = CoffEntry;\r | |
714 | \r | |
715 | NtHdr->Pe32Plus.OptionalHeader.BaseOfCode = mTextOffset;\r | |
716 | \r | |
717 | NtHdr->Pe32Plus.OptionalHeader.ImageBase = 0;\r | |
718 | NtHdr->Pe32Plus.OptionalHeader.SectionAlignment = mCoffAlignment;\r | |
719 | NtHdr->Pe32Plus.OptionalHeader.FileAlignment = mCoffAlignment;\r | |
720 | NtHdr->Pe32Plus.OptionalHeader.SizeOfImage = 0;\r | |
721 | \r | |
722 | NtHdr->Pe32Plus.OptionalHeader.SizeOfHeaders = mTextOffset;\r | |
723 | NtHdr->Pe32Plus.OptionalHeader.NumberOfRvaAndSizes = EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES;\r | |
724 | \r | |
725 | //\r | |
726 | // Section headers.\r | |
727 | //\r | |
728 | if ((mDataOffset - mTextOffset) > 0) {\r | |
729 | CreateSectionHeader (".text", mTextOffset, mDataOffset - mTextOffset,\r | |
730 | EFI_IMAGE_SCN_CNT_CODE\r | |
731 | | EFI_IMAGE_SCN_MEM_EXECUTE\r | |
732 | | EFI_IMAGE_SCN_MEM_READ);\r | |
733 | } else {\r | |
734 | // Don't make a section of size 0.\r | |
735 | NtHdr->Pe32Plus.FileHeader.NumberOfSections--;\r | |
736 | }\r | |
737 | \r | |
738 | if ((mHiiRsrcOffset - mDataOffset) > 0) {\r | |
739 | CreateSectionHeader (".data", mDataOffset, mHiiRsrcOffset - mDataOffset,\r | |
740 | EFI_IMAGE_SCN_CNT_INITIALIZED_DATA\r | |
741 | | EFI_IMAGE_SCN_MEM_WRITE\r | |
742 | | EFI_IMAGE_SCN_MEM_READ);\r | |
743 | } else {\r | |
744 | // Don't make a section of size 0.\r | |
745 | NtHdr->Pe32Plus.FileHeader.NumberOfSections--;\r | |
746 | }\r | |
747 | \r | |
748 | if ((mRelocOffset - mHiiRsrcOffset) > 0) {\r | |
749 | CreateSectionHeader (".rsrc", mHiiRsrcOffset, mRelocOffset - mHiiRsrcOffset,\r | |
750 | EFI_IMAGE_SCN_CNT_INITIALIZED_DATA\r | |
751 | | EFI_IMAGE_SCN_MEM_READ);\r | |
752 | \r | |
753 | NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = mRelocOffset - mHiiRsrcOffset;\r | |
754 | NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = mHiiRsrcOffset;\r | |
755 | } else {\r | |
756 | // Don't make a section of size 0.\r | |
757 | NtHdr->Pe32Plus.FileHeader.NumberOfSections--;\r | |
758 | }\r | |
759 | \r | |
760 | }\r | |
761 | \r | |
762 | STATIC\r | |
763 | BOOLEAN\r | |
764 | WriteSections64 (\r | |
765 | SECTION_FILTER_TYPES FilterType\r | |
766 | )\r | |
767 | {\r | |
768 | UINT32 Idx;\r | |
769 | Elf_Shdr *SecShdr;\r | |
770 | UINT32 SecOffset;\r | |
771 | BOOLEAN (*Filter)(Elf_Shdr *);\r | |
772 | Elf64_Addr GOTEntryRva;\r | |
773 | \r | |
774 | //\r | |
775 | // Initialize filter pointer\r | |
776 | //\r | |
777 | switch (FilterType) {\r | |
778 | case SECTION_TEXT:\r | |
779 | Filter = IsTextShdr;\r | |
780 | break;\r | |
781 | case SECTION_HII:\r | |
782 | Filter = IsHiiRsrcShdr;\r | |
783 | break;\r | |
784 | case SECTION_DATA:\r | |
785 | Filter = IsDataShdr;\r | |
786 | break;\r | |
787 | default:\r | |
788 | return FALSE;\r | |
789 | }\r | |
790 | \r | |
791 | //\r | |
792 | // First: copy sections.\r | |
793 | //\r | |
794 | for (Idx = 0; Idx < mEhdr->e_shnum; Idx++) {\r | |
795 | Elf_Shdr *Shdr = GetShdrByIndex(Idx);\r | |
796 | if ((*Filter)(Shdr)) {\r | |
797 | switch (Shdr->sh_type) {\r | |
798 | case SHT_PROGBITS:\r | |
799 | /* Copy. */\r | |
800 | if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {\r | |
801 | return FALSE;\r | |
802 | }\r | |
803 | memcpy(mCoffFile + mCoffSectionsOffset[Idx],\r | |
804 | (UINT8*)mEhdr + Shdr->sh_offset,\r | |
805 | (size_t) Shdr->sh_size);\r | |
806 | break;\r | |
807 | \r | |
808 | case SHT_NOBITS:\r | |
809 | memset(mCoffFile + mCoffSectionsOffset[Idx], 0, (size_t) Shdr->sh_size);\r | |
810 | break;\r | |
811 | \r | |
812 | default:\r | |
813 | //\r | |
814 | // Ignore for unknown section type.\r | |
815 | //\r | |
816 | VerboseMsg ("%s unknown section type %x. We ignore this unknown section type.", mInImageName, (unsigned)Shdr->sh_type);\r | |
817 | break;\r | |
818 | }\r | |
819 | }\r | |
820 | }\r | |
821 | \r | |
822 | //\r | |
823 | // Second: apply relocations.\r | |
824 | //\r | |
825 | VerboseMsg ("Applying Relocations...");\r | |
826 | for (Idx = 0; Idx < mEhdr->e_shnum; Idx++) {\r | |
827 | //\r | |
828 | // Determine if this is a relocation section.\r | |
829 | //\r | |
830 | Elf_Shdr *RelShdr = GetShdrByIndex(Idx);\r | |
831 | if ((RelShdr->sh_type != SHT_REL) && (RelShdr->sh_type != SHT_RELA)) {\r | |
832 | continue;\r | |
833 | }\r | |
834 | \r | |
835 | //\r | |
836 | // If this is a ET_DYN (PIE) executable, we will encounter a dynamic SHT_RELA\r | |
837 | // section that applies to the entire binary, and which will have its section\r | |
838 | // index set to #0 (which is a NULL section with the SHF_ALLOC bit cleared).\r | |
839 | //\r | |
840 | // In the absence of GOT based relocations,\r | |
841 | // this RELA section will contain redundant R_xxx_RELATIVE relocations, one\r | |
842 | // for every R_xxx_xx64 relocation appearing in the per-section RELA sections.\r | |
843 | // (i.e., .rela.text and .rela.data)\r | |
844 | //\r | |
845 | if (RelShdr->sh_info == 0) {\r | |
846 | continue;\r | |
847 | }\r | |
848 | \r | |
849 | //\r | |
850 | // Relocation section found. Now extract section information that the relocations\r | |
851 | // apply to in the ELF data and the new COFF data.\r | |
852 | //\r | |
853 | SecShdr = GetShdrByIndex(RelShdr->sh_info);\r | |
854 | SecOffset = mCoffSectionsOffset[RelShdr->sh_info];\r | |
855 | \r | |
856 | //\r | |
857 | // Only process relocations for the current filter type.\r | |
858 | //\r | |
859 | if (RelShdr->sh_type == SHT_RELA && (*Filter)(SecShdr)) {\r | |
860 | UINT64 RelIdx;\r | |
861 | \r | |
862 | //\r | |
863 | // Determine the symbol table referenced by the relocation data.\r | |
864 | //\r | |
865 | Elf_Shdr *SymtabShdr = GetShdrByIndex(RelShdr->sh_link);\r | |
866 | UINT8 *Symtab = (UINT8*)mEhdr + SymtabShdr->sh_offset;\r | |
867 | \r | |
868 | //\r | |
869 | // Process all relocation entries for this section.\r | |
870 | //\r | |
871 | for (RelIdx = 0; RelIdx < RelShdr->sh_size; RelIdx += (UINT32) RelShdr->sh_entsize) {\r | |
872 | \r | |
873 | //\r | |
874 | // Set pointer to relocation entry\r | |
875 | //\r | |
876 | Elf_Rela *Rel = (Elf_Rela *)((UINT8*)mEhdr + RelShdr->sh_offset + RelIdx);\r | |
877 | \r | |
878 | //\r | |
879 | // Set pointer to symbol table entry associated with the relocation entry.\r | |
880 | //\r | |
881 | Elf_Sym *Sym = (Elf_Sym *)(Symtab + ELF_R_SYM(Rel->r_info) * SymtabShdr->sh_entsize);\r | |
882 | \r | |
883 | Elf_Shdr *SymShdr;\r | |
884 | UINT8 *Targ;\r | |
885 | \r | |
886 | //\r | |
887 | // Check section header index found in symbol table and get the section\r | |
888 | // header location.\r | |
889 | //\r | |
890 | if (Sym->st_shndx == SHN_UNDEF\r | |
891 | || Sym->st_shndx >= mEhdr->e_shnum) {\r | |
892 | const UINT8 *SymName = GetSymName(Sym);\r | |
893 | if (SymName == NULL) {\r | |
894 | SymName = (const UINT8 *)"<unknown>";\r | |
895 | }\r | |
896 | \r | |
897 | Error (NULL, 0, 3000, "Invalid",\r | |
898 | "%s: Bad definition for symbol '%s'@%#llx or unsupported symbol type. "\r | |
899 | "For example, absolute and undefined symbols are not supported.",\r | |
900 | mInImageName, SymName, Sym->st_value);\r | |
901 | \r | |
902 | exit(EXIT_FAILURE);\r | |
903 | }\r | |
904 | SymShdr = GetShdrByIndex(Sym->st_shndx);\r | |
905 | \r | |
906 | //\r | |
907 | // Convert the relocation data to a pointer into the coff file.\r | |
908 | //\r | |
909 | // Note:\r | |
910 | // r_offset is the virtual address of the storage unit to be relocated.\r | |
911 | // sh_addr is the virtual address for the base of the section.\r | |
912 | //\r | |
913 | // r_offset in a memory address.\r | |
914 | // Convert it to a pointer in the coff file.\r | |
915 | //\r | |
916 | Targ = mCoffFile + SecOffset + (Rel->r_offset - SecShdr->sh_addr);\r | |
917 | \r | |
918 | //\r | |
919 | // Determine how to handle each relocation type based on the machine type.\r | |
920 | //\r | |
921 | if (mEhdr->e_machine == EM_X86_64) {\r | |
922 | switch (ELF_R_TYPE(Rel->r_info)) {\r | |
923 | case R_X86_64_NONE:\r | |
924 | break;\r | |
925 | case R_X86_64_64:\r | |
926 | //\r | |
927 | // Absolute relocation.\r | |
928 | //\r | |
929 | VerboseMsg ("R_X86_64_64");\r | |
930 | VerboseMsg ("Offset: 0x%08X, Addend: 0x%016LX",\r | |
931 | (UINT32)(SecOffset + (Rel->r_offset - SecShdr->sh_addr)),\r | |
932 | *(UINT64 *)Targ);\r | |
933 | *(UINT64 *)Targ = *(UINT64 *)Targ - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx];\r | |
934 | VerboseMsg ("Relocation: 0x%016LX", *(UINT64*)Targ);\r | |
935 | break;\r | |
936 | case R_X86_64_32:\r | |
937 | VerboseMsg ("R_X86_64_32");\r | |
938 | VerboseMsg ("Offset: 0x%08X, Addend: 0x%08X",\r | |
939 | (UINT32)(SecOffset + (Rel->r_offset - SecShdr->sh_addr)),\r | |
940 | *(UINT32 *)Targ);\r | |
941 | *(UINT32 *)Targ = (UINT32)((UINT64)(*(UINT32 *)Targ) - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx]);\r | |
942 | VerboseMsg ("Relocation: 0x%08X", *(UINT32*)Targ);\r | |
943 | break;\r | |
944 | case R_X86_64_32S:\r | |
945 | VerboseMsg ("R_X86_64_32S");\r | |
946 | VerboseMsg ("Offset: 0x%08X, Addend: 0x%08X",\r | |
947 | (UINT32)(SecOffset + (Rel->r_offset - SecShdr->sh_addr)),\r | |
948 | *(UINT32 *)Targ);\r | |
949 | *(INT32 *)Targ = (INT32)((INT64)(*(INT32 *)Targ) - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx]);\r | |
950 | VerboseMsg ("Relocation: 0x%08X", *(UINT32*)Targ);\r | |
951 | break;\r | |
952 | \r | |
953 | case R_X86_64_PLT32:\r | |
954 | //\r | |
955 | // Treat R_X86_64_PLT32 relocations as R_X86_64_PC32: this is\r | |
956 | // possible since we know all code symbol references resolve to\r | |
957 | // definitions in the same module (UEFI has no shared libraries),\r | |
958 | // and so there is never a reason to jump via a PLT entry,\r | |
959 | // allowing us to resolve the reference using the symbol directly.\r | |
960 | //\r | |
961 | VerboseMsg ("Treating R_X86_64_PLT32 as R_X86_64_PC32 ...");\r | |
962 | /* fall through */\r | |
963 | case R_X86_64_PC32:\r | |
964 | //\r | |
965 | // Relative relocation: Symbol - Ip + Addend\r | |
966 | //\r | |
967 | VerboseMsg ("R_X86_64_PC32");\r | |
968 | VerboseMsg ("Offset: 0x%08X, Addend: 0x%08X",\r | |
969 | (UINT32)(SecOffset + (Rel->r_offset - SecShdr->sh_addr)),\r | |
970 | *(UINT32 *)Targ);\r | |
971 | *(UINT32 *)Targ = (UINT32) (*(UINT32 *)Targ\r | |
972 | + (mCoffSectionsOffset[Sym->st_shndx] - SymShdr->sh_addr)\r | |
973 | - (SecOffset - SecShdr->sh_addr));\r | |
974 | VerboseMsg ("Relocation: 0x%08X", *(UINT32 *)Targ);\r | |
975 | break;\r | |
976 | case R_X86_64_GOTPCREL:\r | |
977 | case R_X86_64_GOTPCRELX:\r | |
978 | case R_X86_64_REX_GOTPCRELX:\r | |
979 | VerboseMsg ("R_X86_64_GOTPCREL family");\r | |
980 | VerboseMsg ("Offset: 0x%08X, Addend: 0x%08X",\r | |
981 | (UINT32)(SecOffset + (Rel->r_offset - SecShdr->sh_addr)),\r | |
982 | *(UINT32 *)Targ);\r | |
983 | GOTEntryRva = Rel->r_offset - Rel->r_addend + *(INT32 *)Targ;\r | |
984 | FindElfGOTSectionFromGOTEntryElfRva(GOTEntryRva);\r | |
985 | *(UINT32 *)Targ = (UINT32) (*(UINT32 *)Targ\r | |
986 | + (mCoffSectionsOffset[mGOTShindex] - mGOTShdr->sh_addr)\r | |
987 | - (SecOffset - SecShdr->sh_addr));\r | |
988 | VerboseMsg ("Relocation: 0x%08X", *(UINT32 *)Targ);\r | |
989 | GOTEntryRva += (mCoffSectionsOffset[mGOTShindex] - mGOTShdr->sh_addr); // ELF Rva -> COFF Rva\r | |
990 | if (AccumulateCoffGOTEntries((UINT32)GOTEntryRva)) {\r | |
991 | //\r | |
992 | // Relocate GOT entry if it's the first time we run into it\r | |
993 | //\r | |
994 | Targ = mCoffFile + GOTEntryRva;\r | |
995 | //\r | |
996 | // Limitation: The following three statements assume memory\r | |
997 | // at *Targ is valid because the section containing the GOT\r | |
998 | // has already been copied from the ELF image to the Coff image.\r | |
999 | // This pre-condition presently holds because the GOT is placed\r | |
1000 | // in section .text, and the ELF text sections are all copied\r | |
1001 | // prior to reaching this point.\r | |
1002 | // If the pre-condition is violated in the future, this fixup\r | |
1003 | // either needs to be deferred after the GOT section is copied\r | |
1004 | // to the Coff image, or the fixup should be performed on the\r | |
1005 | // source Elf image instead of the destination Coff image.\r | |
1006 | //\r | |
1007 | VerboseMsg ("Offset: 0x%08X, Addend: 0x%016LX",\r | |
1008 | (UINT32)GOTEntryRva,\r | |
1009 | *(UINT64 *)Targ);\r | |
1010 | *(UINT64 *)Targ = *(UINT64 *)Targ - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx];\r | |
1011 | VerboseMsg ("Relocation: 0x%016LX", *(UINT64*)Targ);\r | |
1012 | }\r | |
1013 | break;\r | |
1014 | default:\r | |
1015 | Error (NULL, 0, 3000, "Invalid", "%s unsupported ELF EM_X86_64 relocation 0x%x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r | |
1016 | }\r | |
1017 | } else if (mEhdr->e_machine == EM_AARCH64) {\r | |
1018 | \r | |
1019 | switch (ELF_R_TYPE(Rel->r_info)) {\r | |
1020 | \r | |
1021 | case R_AARCH64_ADR_PREL_PG_HI21:\r | |
1022 | //\r | |
1023 | // AArch64 PG_H21 relocations are typically paired with ABS_LO12\r | |
1024 | // relocations, where a PC-relative reference with +/- 4 GB range is\r | |
1025 | // split into a relative high part and an absolute low part. Since\r | |
1026 | // the absolute low part represents the offset into a 4 KB page, we\r | |
1027 | // either have to convert the ADRP into an ADR instruction, or we\r | |
1028 | // need to use a section alignment of at least 4 KB, so that the\r | |
1029 | // binary appears at a correct offset at runtime. In any case, we\r | |
1030 | // have to make sure that the 4 KB relative offsets of both the\r | |
1031 | // section containing the reference as well as the section to which\r | |
1032 | // it refers have not been changed during PE/COFF conversion (i.e.,\r | |
1033 | // in ScanSections64() above).\r | |
1034 | //\r | |
1035 | if (mCoffAlignment < 0x1000) {\r | |
1036 | //\r | |
1037 | // Attempt to convert the ADRP into an ADR instruction.\r | |
1038 | // This is only possible if the symbol is within +/- 1 MB.\r | |
1039 | //\r | |
1040 | INT64 Offset;\r | |
1041 | \r | |
1042 | // Decode the ADRP instruction\r | |
1043 | Offset = (INT32)((*(UINT32 *)Targ & 0xffffe0) << 8);\r | |
1044 | Offset = (Offset << (6 - 5)) | ((*(UINT32 *)Targ & 0x60000000) >> (29 - 12));\r | |
1045 | \r | |
1046 | //\r | |
1047 | // ADRP offset is relative to the previous page boundary,\r | |
1048 | // whereas ADR offset is relative to the instruction itself.\r | |
1049 | // So fix up the offset so it points to the page containing\r | |
1050 | // the symbol.\r | |
1051 | //\r | |
1052 | Offset -= (UINTN)(Targ - mCoffFile) & 0xfff;\r | |
1053 | \r | |
1054 | if (Offset < -0x100000 || Offset > 0xfffff) {\r | |
1055 | Error (NULL, 0, 3000, "Invalid", "WriteSections64(): %s due to its size (> 1 MB), this module requires 4 KB section alignment.",\r | |
1056 | mInImageName);\r | |
1057 | break;\r | |
1058 | }\r | |
1059 | \r | |
1060 | // Re-encode the offset as an ADR instruction\r | |
1061 | *(UINT32 *)Targ &= 0x1000001f;\r | |
1062 | *(UINT32 *)Targ |= ((Offset & 0x1ffffc) << (5 - 2)) | ((Offset & 0x3) << 29);\r | |
1063 | }\r | |
1064 | /* fall through */\r | |
1065 | \r | |
1066 | case R_AARCH64_ADD_ABS_LO12_NC:\r | |
1067 | case R_AARCH64_LDST8_ABS_LO12_NC:\r | |
1068 | case R_AARCH64_LDST16_ABS_LO12_NC:\r | |
1069 | case R_AARCH64_LDST32_ABS_LO12_NC:\r | |
1070 | case R_AARCH64_LDST64_ABS_LO12_NC:\r | |
1071 | case R_AARCH64_LDST128_ABS_LO12_NC:\r | |
1072 | if (((SecShdr->sh_addr ^ SecOffset) & 0xfff) != 0 ||\r | |
1073 | ((SymShdr->sh_addr ^ mCoffSectionsOffset[Sym->st_shndx]) & 0xfff) != 0) {\r | |
1074 | Error (NULL, 0, 3000, "Invalid", "WriteSections64(): %s AARCH64 small code model requires identical ELF and PE/COFF section offsets modulo 4 KB.",\r | |
1075 | mInImageName);\r | |
1076 | break;\r | |
1077 | }\r | |
1078 | /* fall through */\r | |
1079 | \r | |
1080 | case R_AARCH64_ADR_PREL_LO21:\r | |
1081 | case R_AARCH64_CONDBR19:\r | |
1082 | case R_AARCH64_LD_PREL_LO19:\r | |
1083 | case R_AARCH64_CALL26:\r | |
1084 | case R_AARCH64_JUMP26:\r | |
1085 | case R_AARCH64_PREL64:\r | |
1086 | case R_AARCH64_PREL32:\r | |
1087 | case R_AARCH64_PREL16:\r | |
1088 | //\r | |
1089 | // The GCC toolchains (i.e., binutils) may corrupt section relative\r | |
1090 | // relocations when emitting relocation sections into fully linked\r | |
1091 | // binaries. More specifically, they tend to fail to take into\r | |
1092 | // account the fact that a '.rodata + XXX' relocation needs to have\r | |
1093 | // its addend recalculated once .rodata is merged into the .text\r | |
1094 | // section, and the relocation emitted into the .rela.text section.\r | |
1095 | //\r | |
1096 | // We cannot really recover from this loss of information, so the\r | |
1097 | // only workaround is to prevent having to recalculate any relative\r | |
1098 | // relocations at all, by using a linker script that ensures that\r | |
1099 | // the offset between the Place and the Symbol is the same in both\r | |
1100 | // the ELF and the PE/COFF versions of the binary.\r | |
1101 | //\r | |
1102 | if ((SymShdr->sh_addr - SecShdr->sh_addr) !=\r | |
1103 | (mCoffSectionsOffset[Sym->st_shndx] - SecOffset)) {\r | |
1104 | Error (NULL, 0, 3000, "Invalid", "WriteSections64(): %s AARCH64 relative relocations require identical ELF and PE/COFF section offsets",\r | |
1105 | mInImageName);\r | |
1106 | }\r | |
1107 | break;\r | |
1108 | \r | |
1109 | // Absolute relocations.\r | |
1110 | case R_AARCH64_ABS64:\r | |
1111 | *(UINT64 *)Targ = *(UINT64 *)Targ - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx];\r | |
1112 | break;\r | |
1113 | \r | |
1114 | default:\r | |
1115 | Error (NULL, 0, 3000, "Invalid", "WriteSections64(): %s unsupported ELF EM_AARCH64 relocation 0x%x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r | |
1116 | }\r | |
1117 | } else {\r | |
1118 | Error (NULL, 0, 3000, "Invalid", "Not a supported machine type");\r | |
1119 | }\r | |
1120 | }\r | |
1121 | }\r | |
1122 | }\r | |
1123 | \r | |
1124 | return TRUE;\r | |
1125 | }\r | |
1126 | \r | |
1127 | STATIC\r | |
1128 | VOID\r | |
1129 | WriteRelocations64 (\r | |
1130 | VOID\r | |
1131 | )\r | |
1132 | {\r | |
1133 | UINT32 Index;\r | |
1134 | EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;\r | |
1135 | EFI_IMAGE_DATA_DIRECTORY *Dir;\r | |
1136 | \r | |
1137 | for (Index = 0; Index < mEhdr->e_shnum; Index++) {\r | |
1138 | Elf_Shdr *RelShdr = GetShdrByIndex(Index);\r | |
1139 | if ((RelShdr->sh_type == SHT_REL) || (RelShdr->sh_type == SHT_RELA)) {\r | |
1140 | Elf_Shdr *SecShdr = GetShdrByIndex (RelShdr->sh_info);\r | |
1141 | if (IsTextShdr(SecShdr) || IsDataShdr(SecShdr)) {\r | |
1142 | UINT64 RelIdx;\r | |
1143 | \r | |
1144 | for (RelIdx = 0; RelIdx < RelShdr->sh_size; RelIdx += RelShdr->sh_entsize) {\r | |
1145 | Elf_Rela *Rel = (Elf_Rela *)((UINT8*)mEhdr + RelShdr->sh_offset + RelIdx);\r | |
1146 | \r | |
1147 | if (mEhdr->e_machine == EM_X86_64) {\r | |
1148 | switch (ELF_R_TYPE(Rel->r_info)) {\r | |
1149 | case R_X86_64_NONE:\r | |
1150 | case R_X86_64_PC32:\r | |
1151 | case R_X86_64_PLT32:\r | |
1152 | case R_X86_64_GOTPCREL:\r | |
1153 | case R_X86_64_GOTPCRELX:\r | |
1154 | case R_X86_64_REX_GOTPCRELX:\r | |
1155 | break;\r | |
1156 | case R_X86_64_64:\r | |
1157 | VerboseMsg ("EFI_IMAGE_REL_BASED_DIR64 Offset: 0x%08X",\r | |
1158 | mCoffSectionsOffset[RelShdr->sh_info] + (Rel->r_offset - SecShdr->sh_addr));\r | |
1159 | CoffAddFixup(\r | |
1160 | (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_info]\r | |
1161 | + (Rel->r_offset - SecShdr->sh_addr)),\r | |
1162 | EFI_IMAGE_REL_BASED_DIR64);\r | |
1163 | break;\r | |
1164 | //\r | |
1165 | // R_X86_64_32 and R_X86_64_32S are ELF64 relocations emitted when using\r | |
1166 | // the SYSV X64 ABI small non-position-independent code model.\r | |
1167 | // R_X86_64_32 is used for unsigned 32-bit immediates with a 32-bit operand\r | |
1168 | // size. The value is either not extended, or zero-extended to 64 bits.\r | |
1169 | // R_X86_64_32S is used for either signed 32-bit non-rip-relative displacements\r | |
1170 | // or signed 32-bit immediates with a 64-bit operand size. The value is\r | |
1171 | // sign-extended to 64 bits.\r | |
1172 | // EFI_IMAGE_REL_BASED_HIGHLOW is a PE relocation that uses 32-bit arithmetic\r | |
1173 | // for rebasing an image.\r | |
1174 | // EFI PE binaries declare themselves EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE and\r | |
1175 | // may load above 2GB. If an EFI PE binary with a converted R_X86_64_32S\r | |
1176 | // relocation is loaded above 2GB, the value will get sign-extended to the\r | |
1177 | // negative part of the 64-bit address space. The negative part of the 64-bit\r | |
1178 | // address space is unmapped, so accessing such an address page-faults.\r | |
1179 | // In order to support R_X86_64_32S, it is necessary to unset\r | |
1180 | // EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE, and the EFI PE loader must implement\r | |
1181 | // this flag and abstain from loading such a PE binary above 2GB.\r | |
1182 | // Since this feature is not supported, support for R_X86_64_32S (and hence\r | |
1183 | // the small non-position-independent code model) is disabled.\r | |
1184 | //\r | |
1185 | // case R_X86_64_32S:\r | |
1186 | case R_X86_64_32:\r | |
1187 | VerboseMsg ("EFI_IMAGE_REL_BASED_HIGHLOW Offset: 0x%08X",\r | |
1188 | mCoffSectionsOffset[RelShdr->sh_info] + (Rel->r_offset - SecShdr->sh_addr));\r | |
1189 | CoffAddFixup(\r | |
1190 | (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_info]\r | |
1191 | + (Rel->r_offset - SecShdr->sh_addr)),\r | |
1192 | EFI_IMAGE_REL_BASED_HIGHLOW);\r | |
1193 | break;\r | |
1194 | default:\r | |
1195 | Error (NULL, 0, 3000, "Invalid", "%s unsupported ELF EM_X86_64 relocation 0x%x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r | |
1196 | }\r | |
1197 | } else if (mEhdr->e_machine == EM_AARCH64) {\r | |
1198 | \r | |
1199 | switch (ELF_R_TYPE(Rel->r_info)) {\r | |
1200 | case R_AARCH64_ADR_PREL_LO21:\r | |
1201 | case R_AARCH64_CONDBR19:\r | |
1202 | case R_AARCH64_LD_PREL_LO19:\r | |
1203 | case R_AARCH64_CALL26:\r | |
1204 | case R_AARCH64_JUMP26:\r | |
1205 | case R_AARCH64_PREL64:\r | |
1206 | case R_AARCH64_PREL32:\r | |
1207 | case R_AARCH64_PREL16:\r | |
1208 | case R_AARCH64_ADR_PREL_PG_HI21:\r | |
1209 | case R_AARCH64_ADD_ABS_LO12_NC:\r | |
1210 | case R_AARCH64_LDST8_ABS_LO12_NC:\r | |
1211 | case R_AARCH64_LDST16_ABS_LO12_NC:\r | |
1212 | case R_AARCH64_LDST32_ABS_LO12_NC:\r | |
1213 | case R_AARCH64_LDST64_ABS_LO12_NC:\r | |
1214 | case R_AARCH64_LDST128_ABS_LO12_NC:\r | |
1215 | //\r | |
1216 | // No fixups are required for relative relocations, provided that\r | |
1217 | // the relative offsets between sections have been preserved in\r | |
1218 | // the ELF to PE/COFF conversion. We have already asserted that\r | |
1219 | // this is the case in WriteSections64 ().\r | |
1220 | //\r | |
1221 | break;\r | |
1222 | \r | |
1223 | case R_AARCH64_ABS64:\r | |
1224 | CoffAddFixup(\r | |
1225 | (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_info]\r | |
1226 | + (Rel->r_offset - SecShdr->sh_addr)),\r | |
1227 | EFI_IMAGE_REL_BASED_DIR64);\r | |
1228 | break;\r | |
1229 | \r | |
1230 | case R_AARCH64_ABS32:\r | |
1231 | CoffAddFixup(\r | |
1232 | (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_info]\r | |
1233 | + (Rel->r_offset - SecShdr->sh_addr)),\r | |
1234 | EFI_IMAGE_REL_BASED_HIGHLOW);\r | |
1235 | break;\r | |
1236 | \r | |
1237 | default:\r | |
1238 | Error (NULL, 0, 3000, "Invalid", "WriteRelocations64(): %s unsupported ELF EM_AARCH64 relocation 0x%x.", mInImageName, (unsigned) ELF_R_TYPE(Rel->r_info));\r | |
1239 | }\r | |
1240 | } else {\r | |
1241 | Error (NULL, 0, 3000, "Not Supported", "This tool does not support relocations for ELF with e_machine %u (processor type).", (unsigned) mEhdr->e_machine);\r | |
1242 | }\r | |
1243 | }\r | |
1244 | if (mEhdr->e_machine == EM_X86_64 && RelShdr->sh_info == mGOTShindex) {\r | |
1245 | //\r | |
1246 | // Tack relocations for GOT entries after other relocations for\r | |
1247 | // the section the GOT is in, as it's usually found at the end\r | |
1248 | // of the section. This is done in order to maintain Rva order\r | |
1249 | // of Coff relocations.\r | |
1250 | //\r | |
1251 | EmitGOTRelocations();\r | |
1252 | }\r | |
1253 | }\r | |
1254 | }\r | |
1255 | }\r | |
1256 | \r | |
1257 | if (mEhdr->e_machine == EM_X86_64) {\r | |
1258 | //\r | |
1259 | // This is a safety net just in case the GOT is in a section\r | |
1260 | // with no other relocations and the first invocation of\r | |
1261 | // EmitGOTRelocations() above was skipped. This invocation\r | |
1262 | // does not maintain Rva order of Coff relocations.\r | |
1263 | // At present, with a single text section, all references to\r | |
1264 | // the GOT and the GOT itself reside in section .text, so\r | |
1265 | // if there's a GOT at all, the first invocation above\r | |
1266 | // is executed.\r | |
1267 | //\r | |
1268 | EmitGOTRelocations();\r | |
1269 | }\r | |
1270 | //\r | |
1271 | // Pad by adding empty entries.\r | |
1272 | //\r | |
1273 | while (mCoffOffset & (mCoffAlignment - 1)) {\r | |
1274 | CoffAddFixupEntry(0);\r | |
1275 | }\r | |
1276 | \r | |
1277 | NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset);\r | |
1278 | Dir = &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r | |
1279 | Dir->Size = mCoffOffset - mRelocOffset;\r | |
1280 | if (Dir->Size == 0) {\r | |
1281 | // If no relocations, null out the directory entry and don't add the .reloc section\r | |
1282 | Dir->VirtualAddress = 0;\r | |
1283 | NtHdr->Pe32Plus.FileHeader.NumberOfSections--;\r | |
1284 | } else {\r | |
1285 | Dir->VirtualAddress = mRelocOffset;\r | |
1286 | CreateSectionHeader (".reloc", mRelocOffset, mCoffOffset - mRelocOffset,\r | |
1287 | EFI_IMAGE_SCN_CNT_INITIALIZED_DATA\r | |
1288 | | EFI_IMAGE_SCN_MEM_DISCARDABLE\r | |
1289 | | EFI_IMAGE_SCN_MEM_READ);\r | |
1290 | }\r | |
1291 | }\r | |
1292 | \r | |
1293 | STATIC\r | |
1294 | VOID\r | |
1295 | WriteDebug64 (\r | |
1296 | VOID\r | |
1297 | )\r | |
1298 | {\r | |
1299 | UINT32 Len;\r | |
1300 | EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;\r | |
1301 | EFI_IMAGE_DATA_DIRECTORY *DataDir;\r | |
1302 | EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *Dir;\r | |
1303 | EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *Nb10;\r | |
1304 | \r | |
1305 | Len = strlen(mInImageName) + 1;\r | |
1306 | \r | |
1307 | Dir = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY*)(mCoffFile + mDebugOffset);\r | |
1308 | Dir->Type = EFI_IMAGE_DEBUG_TYPE_CODEVIEW;\r | |
1309 | Dir->SizeOfData = sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + Len;\r | |
1310 | Dir->RVA = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r | |
1311 | Dir->FileOffset = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r | |
1312 | \r | |
1313 | Nb10 = (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY*)(Dir + 1);\r | |
1314 | Nb10->Signature = CODEVIEW_SIGNATURE_NB10;\r | |
1315 | strcpy ((char *)(Nb10 + 1), mInImageName);\r | |
1316 | \r | |
1317 | \r | |
1318 | NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset);\r | |
1319 | DataDir = &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG];\r | |
1320 | DataDir->VirtualAddress = mDebugOffset;\r | |
1321 | DataDir->Size = sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r | |
1322 | }\r | |
1323 | \r | |
1324 | STATIC\r | |
1325 | VOID\r | |
1326 | SetImageSize64 (\r | |
1327 | VOID\r | |
1328 | )\r | |
1329 | {\r | |
1330 | EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;\r | |
1331 | \r | |
1332 | //\r | |
1333 | // Set image size\r | |
1334 | //\r | |
1335 | NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset);\r | |
1336 | NtHdr->Pe32Plus.OptionalHeader.SizeOfImage = mCoffOffset;\r | |
1337 | }\r | |
1338 | \r | |
1339 | STATIC\r | |
1340 | VOID\r | |
1341 | CleanUp64 (\r | |
1342 | VOID\r | |
1343 | )\r | |
1344 | {\r | |
1345 | if (mCoffSectionsOffset != NULL) {\r | |
1346 | free (mCoffSectionsOffset);\r | |
1347 | }\r | |
1348 | }\r | |
1349 | \r | |
1350 | \r |