24
24
#include " llvm/Object/COFF.h"
25
25
26
26
#include " swift/ABI/Enum.h"
27
+ #include " swift/ABI/ObjectFile.h"
27
28
#include " swift/Remote/MemoryReader.h"
28
29
#include " swift/Remote/MetadataReader.h"
29
30
#include " swift/Reflection/Records.h"
@@ -210,12 +211,12 @@ class ReflectionContext
210
211
auto SectBuf = this ->getReader ().readBytes (RemoteAddress (RangeStart),
211
212
RangeEnd - RangeStart);
212
213
213
- auto findMachOSectionByName = [&](std::string Name)
214
+ auto findMachOSectionByName = [&](llvm::StringRef Name)
214
215
-> std::pair<RemoteRef<void >, uint64_t > {
215
216
for (unsigned I = 0 ; I < NumSect; ++I) {
216
217
auto S = reinterpret_cast <typename T::Section *>(
217
218
SectionsBuf + (I * sizeof (typename T::Section)));
218
- if (strncmp (S->sectname , Name.c_str (), strlen (Name.c_str ())) != 0 )
219
+ if (strncmp (S->sectname , Name.data (), strlen (Name.data ())) != 0 )
219
220
continue ;
220
221
auto RemoteSecStart = S->addr + Slide;
221
222
auto SectBufData = reinterpret_cast <const char *>(SectBuf.get ());
@@ -228,12 +229,19 @@ class ReflectionContext
228
229
return {nullptr , 0 };
229
230
};
230
231
231
- auto FieldMdSec = findMachOSectionByName (" __swift5_fieldmd" );
232
- auto AssocTySec = findMachOSectionByName (" __swift5_assocty" );
233
- auto BuiltinTySec = findMachOSectionByName (" __swift5_builtin" );
234
- auto CaptureSec = findMachOSectionByName (" __swift5_capture" );
235
- auto TypeRefMdSec = findMachOSectionByName (" __swift5_typeref" );
236
- auto ReflStrMdSec = findMachOSectionByName (" __swift5_reflstr" );
232
+ SwiftObjectFileFormatMachO ObjectFileFormat;
233
+ auto FieldMdSec = findMachOSectionByName (
234
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::fieldmd));
235
+ auto AssocTySec = findMachOSectionByName (
236
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::assocty));
237
+ auto BuiltinTySec = findMachOSectionByName (
238
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::builtin));
239
+ auto CaptureSec = findMachOSectionByName (
240
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::capture));
241
+ auto TypeRefMdSec = findMachOSectionByName (
242
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::typeref));
243
+ auto ReflStrMdSec = findMachOSectionByName (
244
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::reflstr));
237
245
238
246
if (FieldMdSec.first == nullptr &&
239
247
AssocTySec.first == nullptr &&
@@ -330,12 +338,19 @@ class ReflectionContext
330
338
return {nullptr , 0 };
331
339
};
332
340
333
- auto CaptureSec = findCOFFSectionByName (" .sw5cptr" );
334
- auto TypeRefMdSec = findCOFFSectionByName (" .sw5tyrf" );
335
- auto FieldMdSec = findCOFFSectionByName (" .sw5flmd" );
336
- auto AssocTySec = findCOFFSectionByName (" .sw5asty" );
337
- auto BuiltinTySec = findCOFFSectionByName (" .sw5bltn" );
338
- auto ReflStrMdSec = findCOFFSectionByName (" .sw5rfst" );
341
+ SwiftObjectFileFormatCOFF ObjectFileFormat;
342
+ auto FieldMdSec = findCOFFSectionByName (
343
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::fieldmd));
344
+ auto AssocTySec = findCOFFSectionByName (
345
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::assocty));
346
+ auto BuiltinTySec = findCOFFSectionByName (
347
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::builtin));
348
+ auto CaptureSec = findCOFFSectionByName (
349
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::capture));
350
+ auto TypeRefMdSec = findCOFFSectionByName (
351
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::typeref));
352
+ auto ReflStrMdSec = findCOFFSectionByName (
353
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::reflstr));
339
354
340
355
if (FieldMdSec.first == nullptr &&
341
356
AssocTySec.first == nullptr &&
@@ -424,7 +439,7 @@ class ReflectionContext
424
439
auto StrTabBuf = this ->getReader ().readBytes (StrTabStart, StrTabSize);
425
440
auto StrTab = reinterpret_cast <const char *>(StrTabBuf.get ());
426
441
427
- auto findELFSectionByName = [&](std::string Name)
442
+ auto findELFSectionByName = [&](llvm::StringRef Name)
428
443
-> std::pair<RemoteRef<void >, uint64_t > {
429
444
// Now for all the sections, find their name.
430
445
for (const typename T::Section *Hdr : SecHdrVec) {
@@ -444,12 +459,19 @@ class ReflectionContext
444
459
return {nullptr , 0 };
445
460
};
446
461
447
- auto FieldMdSec = findELFSectionByName (" swift5_fieldmd" );
448
- auto AssocTySec = findELFSectionByName (" swift5_assocty" );
449
- auto BuiltinTySec = findELFSectionByName (" swift5_builtin" );
450
- auto CaptureSec = findELFSectionByName (" swift5_capture" );
451
- auto TypeRefMdSec = findELFSectionByName (" swift5_typeref" );
452
- auto ReflStrMdSec = findELFSectionByName (" swift5_reflstr" );
462
+ SwiftObjectFileFormatELF ObjectFileFormat;
463
+ auto FieldMdSec = findELFSectionByName (
464
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::fieldmd));
465
+ auto AssocTySec = findELFSectionByName (
466
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::assocty));
467
+ auto BuiltinTySec = findELFSectionByName (
468
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::builtin));
469
+ auto CaptureSec = findELFSectionByName (
470
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::capture));
471
+ auto TypeRefMdSec = findELFSectionByName (
472
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::typeref));
473
+ auto ReflStrMdSec = findELFSectionByName (
474
+ ObjectFileFormat.getSectionName (ReflectionSectionKind::reflstr));
453
475
454
476
// We succeed if at least one of the sections is present in the
455
477
// ELF executable.
0 commit comments