@@ -242,7 +242,7 @@ class ReflectionContext
242
242
auto Buf =
243
243
this ->getReader ().readBytes (ImageStart, sizeof (typename T::Header));
244
244
if (!Buf)
245
- return false ;
245
+ return {} ;
246
246
auto Header = reinterpret_cast <typename T::Header *>(Buf.get ());
247
247
assert (Header->magic == T::MagicNumber && " invalid MachO file" );
248
248
@@ -262,7 +262,7 @@ class ReflectionContext
262
262
RemoteAddress (CmdStartAddress.getAddressData () + Offset),
263
263
SegmentCmdHdrSize);
264
264
if (!CmdBuf)
265
- return false ;
265
+ return {} ;
266
266
auto CmdHdr = reinterpret_cast <typename T::SegmentCmd *>(CmdBuf.get ());
267
267
if (strncmp (CmdHdr->segname , " __TEXT" , sizeof (CmdHdr->segname )) == 0 ) {
268
268
TextCommand = CmdHdr;
@@ -274,7 +274,7 @@ class ReflectionContext
274
274
275
275
// No __TEXT segment, bail out.
276
276
if (!TextCommand)
277
- return false ;
277
+ return {} ;
278
278
279
279
// Find the load command offset.
280
280
auto loadCmdOffset = ImageStart.getAddressData () + Offset + sizeof (typename T::Header);
@@ -284,7 +284,7 @@ class ReflectionContext
284
284
auto LoadCmdBuf = this ->getReader ().readBytes (
285
285
RemoteAddress (LoadCmdAddress), sizeof (typename T::SegmentCmd));
286
286
if (!LoadCmdBuf)
287
- return false ;
287
+ return {} ;
288
288
auto LoadCmd = reinterpret_cast <typename T::SegmentCmd *>(LoadCmdBuf.get ());
289
289
290
290
// The sections start immediately after the load command.
@@ -294,7 +294,7 @@ class ReflectionContext
294
294
auto Sections = this ->getReader ().readBytes (
295
295
RemoteAddress (SectAddress), NumSect * sizeof (typename T::Section));
296
296
if (!Sections)
297
- return false ;
297
+ return {} ;
298
298
299
299
auto Slide = ImageStart.getAddressData () - TextCommand->vmaddr ;
300
300
auto SectionsBuf = reinterpret_cast <const char *>(Sections.get ());
@@ -346,7 +346,7 @@ class ReflectionContext
346
346
ReflStrMdSec.first == nullptr &&
347
347
ConformMdSec.first == nullptr &&
348
348
MPEnumMdSec.first == nullptr )
349
- return false ;
349
+ return {} ;
350
350
351
351
ReflectionInfo info = {{FieldMdSec.first , FieldMdSec.second },
352
352
{AssocTySec.first , AssocTySec.second },
@@ -371,7 +371,7 @@ class ReflectionContext
371
371
RemoteAddress (CmdStartAddress.getAddressData () + Offset),
372
372
SegmentCmdHdrSize);
373
373
if (!CmdBuf)
374
- return false ;
374
+ return {} ;
375
375
auto CmdHdr = reinterpret_cast <typename T::SegmentCmd *>(CmdBuf.get ());
376
376
// Look for any segment name starting with __DATA or __AUTH.
377
377
if (strncmp (CmdHdr->segname , " __DATA" , 6 ) == 0 ||
@@ -398,7 +398,7 @@ class ReflectionContext
398
398
auto DOSHdrBuf = this ->getReader ().readBytes (
399
399
ImageStart, sizeof (llvm::object::dos_header));
400
400
if (!DOSHdrBuf)
401
- return false ;
401
+ return {} ;
402
402
auto DOSHdr =
403
403
reinterpret_cast <const llvm::object::dos_header *>(DOSHdrBuf.get ());
404
404
auto COFFFileHdrAddr = ImageStart.getAddressData () +
@@ -408,7 +408,7 @@ class ReflectionContext
408
408
auto COFFFileHdrBuf = this ->getReader ().readBytes (
409
409
RemoteAddress (COFFFileHdrAddr), sizeof (llvm::object::coff_file_header));
410
410
if (!COFFFileHdrBuf)
411
- return false ;
411
+ return {} ;
412
412
auto COFFFileHdr = reinterpret_cast <const llvm::object::coff_file_header *>(
413
413
COFFFileHdrBuf.get ());
414
414
@@ -419,7 +419,7 @@ class ReflectionContext
419
419
RemoteAddress (SectionTableAddr),
420
420
sizeof (llvm::object::coff_section) * COFFFileHdr->NumberOfSections );
421
421
if (!SectionTableBuf)
422
- return false ;
422
+ return {} ;
423
423
424
424
auto findCOFFSectionByName =
425
425
[&](llvm::StringRef Name) -> std::pair<RemoteRef<void >, uint64_t > {
@@ -481,7 +481,7 @@ class ReflectionContext
481
481
ReflStrMdSec.first == nullptr &&
482
482
ConformMdSec.first == nullptr &&
483
483
MPEnumMdSec.first == nullptr )
484
- return false ;
484
+ return {} ;
485
485
486
486
ReflectionInfo Info = {{FieldMdSec.first , FieldMdSec.second },
487
487
{AssocTySec.first , AssocTySec.second },
@@ -502,7 +502,7 @@ class ReflectionContext
502
502
auto Buf = this ->getReader ().readBytes (ImageStart,
503
503
sizeof (llvm::object::dos_header));
504
504
if (!Buf)
505
- return false ;
505
+ return {} ;
506
506
507
507
auto DOSHdr = reinterpret_cast <const llvm::object::dos_header *>(Buf.get ());
508
508
@@ -512,10 +512,10 @@ class ReflectionContext
512
512
Buf = this ->getReader ().readBytes (RemoteAddress (PEHeaderAddress),
513
513
sizeof (llvm::COFF::PEMagic));
514
514
if (!Buf)
515
- return false ;
515
+ return {} ;
516
516
517
517
if (memcmp (Buf.get (), llvm::COFF::PEMagic, sizeof (llvm::COFF::PEMagic)))
518
- return false ;
518
+ return {} ;
519
519
520
520
return readPECOFFSections (ImageStart, PotentialModuleNames);
521
521
}
@@ -550,7 +550,7 @@ class ReflectionContext
550
550
551
551
const void *Buf = readData (0 , sizeof (typename T::Header));
552
552
if (!Buf)
553
- return false ;
553
+ return {} ;
554
554
auto Hdr = reinterpret_cast <const typename T::Header *>(Buf);
555
555
assert (Hdr->getFileClass () == T::ELFClass && " invalid ELF file class" );
556
556
@@ -560,9 +560,9 @@ class ReflectionContext
560
560
uint16_t SectionEntrySize = Hdr->e_shentsize ;
561
561
562
562
if (sizeof (typename T::Section) > SectionEntrySize)
563
- return false ;
563
+ return {} ;
564
564
if (SectionHdrNumEntries == 0 )
565
- return false ;
565
+ return {} ;
566
566
567
567
// Collect all the section headers, we need them to look up the
568
568
// reflection sections (by name) and the string table.
@@ -573,7 +573,7 @@ class ReflectionContext
573
573
uint64_t Offset = SectionHdrAddress + (I * SectionEntrySize);
574
574
auto SecBuf = readData (Offset, sizeof (typename T::Section));
575
575
if (!SecBuf)
576
- return false ;
576
+ return {} ;
577
577
const typename T::Section *SecHdr =
578
578
reinterpret_cast <const typename T::Section *>(SecBuf);
579
579
@@ -597,7 +597,7 @@ class ReflectionContext
597
597
598
598
auto StrTabBuf = readData (StrTabOffset, StrTabSize);
599
599
if (!StrTabBuf)
600
- return false ;
600
+ return {} ;
601
601
auto StrTab = reinterpret_cast <const char *>(StrTabBuf);
602
602
bool Error = false ;
603
603
@@ -691,20 +691,15 @@ class ReflectionContext
691
691
ObjectFileFormat.getSectionName (ReflectionSectionKind::mpenum), true );
692
692
693
693
if (Error)
694
- return false ;
694
+ return {} ;
695
695
696
- std::optional<uint32_t > result = false ;
696
+ std::optional<uint32_t > result = {} ;
697
697
698
698
// We succeed if at least one of the sections is present in the
699
699
// ELF executable.
700
- if (FieldMdSec.first != nullptr ||
701
- AssocTySec.first != nullptr ||
702
- BuiltinTySec.first != nullptr ||
703
- CaptureSec.first != nullptr ||
704
- TypeRefMdSec.first != nullptr ||
705
- ReflStrMdSec.first != nullptr ||
706
- ConformMdSec.first != nullptr ||
707
- MPEnumMdSec.first != nullptr ) {
700
+ if (FieldMdSec.first || AssocTySec.first || BuiltinTySec.first ||
701
+ CaptureSec.first || TypeRefMdSec.first || ReflStrMdSec.first ||
702
+ ConformMdSec.first || MPEnumMdSec.first ) {
708
703
ReflectionInfo info = {{FieldMdSec.first , FieldMdSec.second },
709
704
{AssocTySec.first , AssocTySec.second },
710
705
{BuiltinTySec.first , BuiltinTySec.second },
@@ -739,16 +734,11 @@ class ReflectionContext
739
734
ObjectFileFormat.getSectionName (ReflectionSectionKind::mpenum), false );
740
735
741
736
if (Error)
742
- return false ;
737
+ return {} ;
743
738
744
- if (FieldMdSec.first != nullptr ||
745
- AssocTySec.first != nullptr ||
746
- BuiltinTySec.first != nullptr ||
747
- CaptureSec.first != nullptr ||
748
- TypeRefMdSec.first != nullptr ||
749
- ReflStrMdSec.first != nullptr ||
750
- ConformMdSec.first != nullptr ||
751
- MPEnumMdSec.first != nullptr ) {
739
+ if (FieldMdSec.first || AssocTySec.first || BuiltinTySec.first ||
740
+ CaptureSec.first || TypeRefMdSec.first || ReflStrMdSec.first ||
741
+ ConformMdSec.first || MPEnumMdSec.first ) {
752
742
ReflectionInfo info = {{FieldMdSec.first , FieldMdSec.second },
753
743
{AssocTySec.first , AssocTySec.second },
754
744
{BuiltinTySec.first , BuiltinTySec.second },
@@ -819,7 +809,7 @@ class ReflectionContext
819
809
// Read the first few bytes to look for a magic header.
820
810
auto Magic = this ->getReader ().readBytes (ImageStart, sizeof (uint32_t ));
821
811
if (!Magic)
822
- return false ;
812
+ return {} ;
823
813
824
814
uint32_t MagicWord;
825
815
memcpy (&MagicWord, Magic.get (), sizeof (MagicWord));
0 commit comments