@@ -55,75 +55,6 @@ getELFObjectFileBase(DataObject *DataP) {
55
55
return unique_dyn_cast<ELFObjectFileBase>(std::move (*ObjOrErr));
56
56
}
57
57
58
- // / Process all notes in the given ELF object file, passing them each to @p
59
- // / ProcessNote.
60
- // /
61
- // / @p ProcessNote should return @c true when the desired note is found, which
62
- // / signals to stop searching and return @c AMD_COMGR_STATUS_SUCCESS. It should
63
- // / return @c false otherwise to continue iteration.
64
- // /
65
- // / @returns @c AMD_COMGR_STATUS_ERROR if an error was encountered in parsing
66
- // / the ELF file; @c AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT if all notes are
67
- // / processed without @p ProcessNote returning @c true; otherwise @c
68
- // / AMD_COMGR_STATUS_SUCCESS.
69
- template <class ELFT , typename F>
70
- amd_comgr_status_t processElfNotes (const ELFObjectFile<ELFT> *Obj,
71
- F ProcessNote) {
72
- const ELFFile<ELFT> &ELFFile = Obj->getELFFile ();
73
-
74
- bool Found = false ;
75
-
76
- auto ProgramHeadersOrError = ELFFile.program_headers ();
77
- if (errorToBool (ProgramHeadersOrError.takeError ())) {
78
- return AMD_COMGR_STATUS_ERROR;
79
- }
80
-
81
- for (const auto &Phdr : *ProgramHeadersOrError) {
82
- if (Phdr.p_type != ELF::PT_NOTE) {
83
- continue ;
84
- }
85
- Error Err = Error::success ();
86
- for (const auto &Note : ELFFile.notes (Phdr, Err)) {
87
- if (ProcessNote (Note)) {
88
- Found = true ;
89
- break ;
90
- }
91
- }
92
- if (errorToBool (std::move (Err))) {
93
- return AMD_COMGR_STATUS_ERROR;
94
- }
95
- if (Found) {
96
- return AMD_COMGR_STATUS_SUCCESS;
97
- }
98
- }
99
-
100
- auto SectionsOrError = ELFFile.sections ();
101
- if (errorToBool (SectionsOrError.takeError ())) {
102
- return AMD_COMGR_STATUS_ERROR;
103
- }
104
-
105
- for (const auto &Shdr : *SectionsOrError) {
106
- if (Shdr.sh_type != ELF::SHT_NOTE) {
107
- continue ;
108
- }
109
- Error Err = Error::success ();
110
- for (const auto &Note : ELFFile.notes (Shdr, Err)) {
111
- if (ProcessNote (Note)) {
112
- Found = true ;
113
- break ;
114
- }
115
- }
116
- if (errorToBool (std::move (Err))) {
117
- return AMD_COMGR_STATUS_ERROR;
118
- }
119
- if (Found) {
120
- return AMD_COMGR_STATUS_SUCCESS;
121
- }
122
- }
123
-
124
- return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
125
- }
126
-
127
58
// PAL currently produces MsgPack metadata in a note with this ID.
128
59
// FIXME: Unify with HSA note types?
129
60
#define PAL_METADATA_NOTE_TYPE 13
@@ -393,24 +324,6 @@ typedef struct amdgpu_hsa_note_code_object_version_s {
393
324
} amdgpu_hsa_note_code_object_version_t ;
394
325
395
326
// NOLINTNEXTLINE(readability-identifier-naming)
396
- typedef struct amdgpu_hsa_note_hsail_s {
397
- uint32_t hsail_major_version; // NOLINT(readability-identifier-naming)
398
- uint32_t hsail_minor_version; // NOLINT(readability-identifier-naming)
399
- uint8_t profile; // NOLINT(readability-identifier-naming)
400
- uint8_t machine_model; // NOLINT(readability-identifier-naming)
401
- uint8_t default_float_round; // NOLINT(readability-identifier-naming)
402
- } amdgpu_hsa_note_hsail_t ;
403
-
404
- // NOLINTNEXTLINE(readability-identifier-naming)
405
- typedef struct amdgpu_hsa_note_isa_s {
406
- uint16_t vendor_name_size; // NOLINT(readability-identifier-naming)
407
- uint16_t architecture_name_size; // NOLINT(readability-identifier-naming)
408
- uint32_t major; // NOLINT(readability-identifier-naming)
409
- uint32_t minor; // NOLINT(readability-identifier-naming)
410
- uint32_t stepping; // NOLINT(readability-identifier-naming)
411
- char vendor_and_architecture_name[1 ]; // NOLINT(readability-identifier-naming)
412
- } amdgpu_hsa_note_isa_t ;
413
-
414
327
namespace {
415
328
bool getMachInfo (unsigned Mach, std::string &Processor, bool &SrameccSupported,
416
329
bool &XnackSupported) {
@@ -427,225 +340,6 @@ bool getMachInfo(unsigned Mach, std::string &Processor, bool &SrameccSupported,
427
340
return true ;
428
341
}
429
342
430
- // This function is an exact copy of the ROCr loader function of the same name.
431
- std::string convertOldTargetNameToNew (const std::string &OldName,
432
- bool IsFinalizer, uint32_t EFlags) {
433
- assert (!OldName.empty () && " Expecting non-empty old name" );
434
-
435
- unsigned Mach = 0 ;
436
- if (OldName == " AMD:AMDGPU:6:0:0" ) {
437
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX600;
438
- } else if (OldName == " AMD:AMDGPU:6:0:1" ) {
439
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX601;
440
- } else if (OldName == " AMD:AMDGPU:6:0:2" ) {
441
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX602;
442
- } else if (OldName == " AMD:AMDGPU:7:0:0" ) {
443
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX700;
444
- } else if (OldName == " AMD:AMDGPU:7:0:1" ) {
445
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX701;
446
- } else if (OldName == " AMD:AMDGPU:7:0:2" ) {
447
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX702;
448
- } else if (OldName == " AMD:AMDGPU:7:0:3" ) {
449
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX703;
450
- } else if (OldName == " AMD:AMDGPU:7:0:4" ) {
451
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX704;
452
- } else if (OldName == " AMD:AMDGPU:7:0:5" ) {
453
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX705;
454
- } else if (OldName == " AMD:AMDGPU:8:0:1" ) {
455
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX801;
456
- } else if (OldName == " AMD:AMDGPU:8:0:0" || OldName == " AMD:AMDGPU:8:0:2" ) {
457
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX802;
458
- } else if (OldName == " AMD:AMDGPU:8:0:3" || OldName == " AMD:AMDGPU:8:0:4" ) {
459
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX803;
460
- } else if (OldName == " AMD:AMDGPU:8:0:5" ) {
461
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX805;
462
- } else if (OldName == " AMD:AMDGPU:8:1:0" ) {
463
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX810;
464
- } else if (OldName == " AMD:AMDGPU:9:0:0" || OldName == " AMD:AMDGPU:9:0:1" ) {
465
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX900;
466
- } else if (OldName == " AMD:AMDGPU:9:0:2" || OldName == " AMD:AMDGPU:9:0:3" ) {
467
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX902;
468
- } else if (OldName == " AMD:AMDGPU:9:0:4" || OldName == " AMD:AMDGPU:9:0:5" ) {
469
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX904;
470
- } else if (OldName == " AMD:AMDGPU:9:0:6" || OldName == " AMD:AMDGPU:9:0:7" ) {
471
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX906;
472
- } else if (OldName == " AMD:AMDGPU:9:0:12" ) {
473
- Mach = ELF::EF_AMDGPU_MACH_AMDGCN_GFX90C;
474
- } else {
475
- // Code object v2 only supports asics up to gfx906. Do NOT add handling
476
- // of new asics into this if-else-if* block.
477
- return " " ;
478
- }
479
-
480
- std::string Name;
481
- bool SrameccSupported = false ;
482
- bool XnackSupported = false ;
483
- if (!getMachInfo (Mach, Name, SrameccSupported, XnackSupported)) {
484
- return " " ;
485
- }
486
-
487
- // Only "AMD:AMDGPU:9:0:6" and "AMD:AMDGPU:9:0:7" supports SRAMECC for
488
- // code object V2, and it must be OFF.
489
- if (SrameccSupported) {
490
- Name += " :sramecc-" ;
491
- }
492
-
493
- if (IsFinalizer) {
494
- if (EFlags & ELF::EF_AMDGPU_FEATURE_XNACK_V2) {
495
- Name += " :xnack+" ;
496
- } else if (XnackSupported) {
497
- Name += " :xnack-" ;
498
- }
499
- } else {
500
- if (OldName == " AMD:AMDGPU:8:0:1" ) {
501
- Name += " :xnack+" ;
502
- } else if (OldName == " AMD:AMDGPU:8:1:0" ) {
503
- Name += " :xnack+" ;
504
- } else if (OldName == " AMD:AMDGPU:9:0:1" ) {
505
- Name += " :xnack+" ;
506
- } else if (OldName == " AMD:AMDGPU:9:0:3" ) {
507
- Name += " :xnack+" ;
508
- } else if (OldName == " AMD:AMDGPU:9:0:5" ) {
509
- Name += " :xnack+" ;
510
- } else if (OldName == " AMD:AMDGPU:9:0:7" ) {
511
- Name += " :xnack+" ;
512
- } else if (XnackSupported) {
513
- Name += " :xnack-" ;
514
- }
515
- }
516
-
517
- return Name;
518
- }
519
-
520
- template <class ELFT >
521
- amd_comgr_status_t getElfIsaNameFromElfNotes (const ELFObjectFile<ELFT> *Obj,
522
- std::string &NoteIsaName) {
523
-
524
- auto ElfHeader = Obj->getELFFile ().getHeader ();
525
-
526
- // Only ELFABIVERSION_AMDGPU_HSA_V2 used note records for the isa name.
527
- assert (ElfHeader.e_ident [ELF::EI_ABIVERSION] ==
528
- ELF::ELFABIVERSION_AMDGPU_HSA_V2);
529
-
530
- bool IsError = false ;
531
- bool IsCodeObjectVersion = false ;
532
- bool IsHSAIL = false ;
533
- bool IsIsa = false ;
534
- uint32_t Major = 0 ;
535
- uint32_t Minor = 0 ;
536
- uint32_t Stepping = 0 ;
537
- StringRef VendorName;
538
- StringRef ArchitectureName;
539
-
540
- auto ProcessNote = [&](const Elf_Note<ELFT> &Note) {
541
- if (Note.getName () != " AMD" ) {
542
- return false ;
543
- }
544
-
545
- switch (Note.getType ()) {
546
- case ELF::NT_AMD_HSA_CODE_OBJECT_VERSION: {
547
- if (Note.getDesc (4 ).size () <
548
- sizeof (amdgpu_hsa_note_code_object_version_s)) {
549
- IsError = true ;
550
- return true ;
551
- }
552
-
553
- const auto *NoteCodeObjectVersion =
554
- reinterpret_cast <const amdgpu_hsa_note_code_object_version_s *>(
555
- Note.getDesc (4 ).data ());
556
-
557
- // Only code objects up to version 2 used note records.
558
- if (NoteCodeObjectVersion->major_version > 2 ) {
559
- IsError = true ;
560
- return true ;
561
- }
562
-
563
- IsCodeObjectVersion = true ;
564
- break ;
565
- }
566
-
567
- case ELF::NT_AMD_HSA_HSAIL: {
568
- if (Note.getDesc (4 ).size () < sizeof (amdgpu_hsa_note_hsail_s)) {
569
- IsError = true ;
570
- return true ;
571
- }
572
-
573
- IsHSAIL = true ;
574
- break ;
575
- }
576
-
577
- case ELF::NT_AMD_HSA_ISA_VERSION: {
578
- if (Note.getDesc (4 ).size () <
579
- offsetof (amdgpu_hsa_note_isa_s, vendor_and_architecture_name)) {
580
- IsError = true ;
581
- return true ;
582
- }
583
-
584
- const auto *NoteIsa = reinterpret_cast <const amdgpu_hsa_note_isa_s *>(
585
- Note.getDesc (4 ).data ());
586
-
587
- if (!NoteIsa->vendor_name_size || !NoteIsa->architecture_name_size ) {
588
- IsError = true ;
589
- return true ;
590
- }
591
-
592
- if (Note.getDesc (4 ).size () <
593
- offsetof (amdgpu_hsa_note_isa_s, vendor_and_architecture_name) +
594
- NoteIsa->vendor_name_size + NoteIsa->architecture_name_size ) {
595
- IsError = true ;
596
- return true ;
597
- }
598
-
599
- Major = NoteIsa->major ;
600
- Minor = NoteIsa->minor ;
601
- Stepping = NoteIsa->stepping ;
602
- VendorName = StringRef (NoteIsa->vendor_and_architecture_name ,
603
- NoteIsa->vendor_name_size - 1 );
604
- ArchitectureName = StringRef (NoteIsa->vendor_and_architecture_name +
605
- NoteIsa->vendor_name_size ,
606
- NoteIsa->architecture_name_size - 1 );
607
-
608
- IsIsa = true ;
609
- break ;
610
- }
611
- }
612
-
613
- // Only stop searching when found all the possible note records needed.
614
- return IsCodeObjectVersion && IsHSAIL && IsIsa;
615
- };
616
-
617
- if ((processElfNotes (Obj, ProcessNote) == AMD_COMGR_STATUS_ERROR) ||
618
- IsError) {
619
- return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
620
- }
621
-
622
- // Code objects up to V2 must have both code object version and isa note
623
- // records.
624
- if (!(IsCodeObjectVersion && IsIsa)) {
625
- return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
626
- }
627
-
628
- std::string OldName;
629
- OldName += VendorName;
630
- OldName += " :" ;
631
- OldName += ArchitectureName;
632
- OldName += " :" ;
633
- OldName += std::to_string (Major);
634
- OldName += " :" ;
635
- OldName += std::to_string (Minor);
636
- OldName += " :" ;
637
- OldName += std::to_string (Stepping);
638
-
639
- NoteIsaName = convertOldTargetNameToNew (OldName, IsHSAIL, ElfHeader.e_flags );
640
- if (NoteIsaName.empty ()) {
641
- return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
642
- }
643
-
644
- NoteIsaName = " amdgcn-amd-amdhsa--" + NoteIsaName;
645
-
646
- return AMD_COMGR_STATUS_SUCCESS;
647
- }
648
-
649
343
template <class ELFT >
650
344
amd_comgr_status_t getElfIsaNameFromElfHeader (const ELFObjectFile<ELFT> *Obj,
651
345
std::string &ElfIsaName) {
@@ -675,29 +369,6 @@ amd_comgr_status_t getElfIsaNameFromElfHeader(const ELFObjectFile<ELFT> *Obj,
675
369
ElfIsaName += Processor;
676
370
677
371
switch (ElfHeader.e_ident [ELF::EI_ABIVERSION]) {
678
- case ELF::ELFABIVERSION_AMDGPU_HSA_V2: {
679
- // ELFABIVERSION_AMDGPU_HSA_V2 uses ELF note records and is not supported.
680
- return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
681
- }
682
-
683
- case ELF::ELFABIVERSION_AMDGPU_HSA_V3: {
684
- if (SrameccSupported) {
685
- if (ElfHeader.e_flags & ELF::EF_AMDGPU_FEATURE_SRAMECC_V3) {
686
- ElfIsaName += " :sramecc+" ;
687
- } else {
688
- ElfIsaName += " :sramecc-" ;
689
- }
690
- }
691
- if (XnackSupported) {
692
- if (ElfHeader.e_flags & ELF::EF_AMDGPU_FEATURE_XNACK_V3) {
693
- ElfIsaName += " :xnack+" ;
694
- } else {
695
- ElfIsaName += " :xnack-" ;
696
- }
697
- }
698
- break ;
699
- }
700
-
701
372
case ELF::ELFABIVERSION_AMDGPU_HSA_V4:
702
373
case ELF::ELFABIVERSION_AMDGPU_HSA_V5:
703
374
case ELF::ELFABIVERSION_AMDGPU_HSA_V6: {
@@ -728,19 +399,6 @@ amd_comgr_status_t getElfIsaNameFromElfHeader(const ELFObjectFile<ELFT> *Obj,
728
399
729
400
return AMD_COMGR_STATUS_SUCCESS;
730
401
}
731
-
732
- template <class ELFT >
733
- amd_comgr_status_t getElfIsaNameImpl (const ELFObjectFile<ELFT> *Obj,
734
- std::string &IsaName) {
735
- auto ElfHeader = Obj->getELFFile ().getHeader ();
736
-
737
- if (ElfHeader.e_ident [ELF::EI_ABIVERSION] ==
738
- ELF::ELFABIVERSION_AMDGPU_HSA_V2) {
739
- return getElfIsaNameFromElfNotes (Obj, IsaName);
740
- }
741
-
742
- return getElfIsaNameFromElfHeader (Obj, IsaName);
743
- }
744
402
} // namespace
745
403
746
404
amd_comgr_status_t getElfIsaName (DataObject *DataP, std::string &IsaName) {
@@ -751,7 +409,7 @@ amd_comgr_status_t getElfIsaName(DataObject *DataP, std::string &IsaName) {
751
409
auto *Obj = ObjOrErr->get ();
752
410
753
411
if (auto *ELF64LE = dyn_cast<ELF64LEObjectFile>(Obj))
754
- return getElfIsaNameImpl (ELF64LE, IsaName);
412
+ return getElfIsaNameFromElfHeader (ELF64LE, IsaName);
755
413
else
756
414
return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
757
415
}
0 commit comments