|
34 | 34 | #include "llvm/Object/Error.h"
|
35 | 35 | #include "llvm/Object/ObjectFile.h"
|
36 | 36 | #include "llvm/Object/StackMapParser.h"
|
| 37 | +#include "llvm/Support/AMDGPUMetadata.h" |
37 | 38 | #include "llvm/Support/ARMAttributeParser.h"
|
38 | 39 | #include "llvm/Support/ARMBuildAttributes.h"
|
39 | 40 | #include "llvm/Support/Casting.h"
|
@@ -156,8 +157,6 @@ class ELFDumper : public ObjDumper {
|
156 | 157 | void printMipsReginfo() override;
|
157 | 158 | void printMipsOptions() override;
|
158 | 159 |
|
159 |
| - void printAMDGPUCodeObjectMetadata() override; |
160 |
| - |
161 | 160 | void printStackMap() const override;
|
162 | 161 |
|
163 | 162 | void printHashHistogram() override;
|
@@ -2353,36 +2352,6 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() {
|
2353 | 2352 | }
|
2354 | 2353 | }
|
2355 | 2354 |
|
2356 |
| -template <class ELFT> void ELFDumper<ELFT>::printAMDGPUCodeObjectMetadata() { |
2357 |
| - const Elf_Shdr *Shdr = findSectionByName(*Obj, ".note"); |
2358 |
| - if (!Shdr) { |
2359 |
| - W.startLine() << "There is no .note section in the file.\n"; |
2360 |
| - return; |
2361 |
| - } |
2362 |
| - ArrayRef<uint8_t> Sec = unwrapOrError(Obj->getSectionContents(Shdr)); |
2363 |
| - |
2364 |
| - const uint32_t CodeObjectMetadataNoteType = 10; |
2365 |
| - for (auto I = reinterpret_cast<const Elf_Word *>(&Sec[0]), |
2366 |
| - E = I + Sec.size()/4; I != E;) { |
2367 |
| - uint32_t NameSZ = I[0]; |
2368 |
| - uint32_t DescSZ = I[1]; |
2369 |
| - uint32_t Type = I[2]; |
2370 |
| - I += 3; |
2371 |
| - |
2372 |
| - StringRef Name; |
2373 |
| - if (NameSZ) { |
2374 |
| - Name = StringRef(reinterpret_cast<const char *>(I), NameSZ - 1); |
2375 |
| - I += alignTo<4>(NameSZ)/4; |
2376 |
| - } |
2377 |
| - |
2378 |
| - if (Name == "AMD" && Type == CodeObjectMetadataNoteType) { |
2379 |
| - StringRef Desc(reinterpret_cast<const char *>(I), DescSZ); |
2380 |
| - W.printString(Desc); |
2381 |
| - } |
2382 |
| - I += alignTo<4>(DescSZ)/4; |
2383 |
| - } |
2384 |
| -} |
2385 |
| - |
2386 | 2355 | template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
|
2387 | 2356 | const Elf_Shdr *StackMapSection = nullptr;
|
2388 | 2357 | for (const auto &Sec : unwrapOrError(Obj->sections())) {
|
@@ -3487,6 +3456,39 @@ static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
|
3487 | 3456 | OS << '\n';
|
3488 | 3457 | }
|
3489 | 3458 |
|
| 3459 | +template <typename ELFT> |
| 3460 | +static void printAMDGPUNote(raw_ostream &OS, uint32_t NoteType, |
| 3461 | + ArrayRef<typename ELFFile<ELFT>::Elf_Word> Words, |
| 3462 | + size_t Size) { |
| 3463 | + switch (NoteType) { |
| 3464 | + default: |
| 3465 | + return; |
| 3466 | + case ELF::NT_AMD_AMDGPU_HSA_METADATA: |
| 3467 | + OS << " HSA Metadata:\n" |
| 3468 | + << StringRef(reinterpret_cast<const char *>(Words.data()), Size); |
| 3469 | + break; |
| 3470 | + case ELF::NT_AMD_AMDGPU_ISA: |
| 3471 | + OS << " ISA Version:\n" |
| 3472 | + << " " |
| 3473 | + << StringRef(reinterpret_cast<const char *>(Words.data()), Size); |
| 3474 | + break; |
| 3475 | + case ELF::NT_AMD_AMDGPU_PAL_METADATA: |
| 3476 | + const uint32_t *PALMetadataBegin = reinterpret_cast<const uint32_t *>(Words.data()); |
| 3477 | + const uint32_t *PALMetadataEnd = PALMetadataBegin + Size; |
| 3478 | + std::vector<uint32_t> PALMetadata(PALMetadataBegin, PALMetadataEnd); |
| 3479 | + std::string PALMetadataString; |
| 3480 | + auto Error = AMDGPU::PALMD::toString(PALMetadata, PALMetadataString); |
| 3481 | + OS << " PAL Metadata:\n"; |
| 3482 | + if (Error) { |
| 3483 | + OS << " Invalid"; |
| 3484 | + return; |
| 3485 | + } |
| 3486 | + OS << PALMetadataString; |
| 3487 | + break; |
| 3488 | + } |
| 3489 | + OS.flush(); |
| 3490 | +} |
| 3491 | + |
3490 | 3492 | template <class ELFT>
|
3491 | 3493 | void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
|
3492 | 3494 | const Elf_Ehdr *e = Obj->getHeader();
|
@@ -3529,6 +3531,7 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
|
3529 | 3531 | OS << getFreeBSDNoteTypeName(Type) << '\n';
|
3530 | 3532 | } else if (Name == "AMD") {
|
3531 | 3533 | OS << getAMDGPUNoteTypeName(Type) << '\n';
|
| 3534 | + printAMDGPUNote<ELFT>(OS, Type, Descriptor, DescriptorSize); |
3532 | 3535 | } else {
|
3533 | 3536 | OS << "Unknown note type: (" << format_hex(Type, 10) << ')';
|
3534 | 3537 | }
|
|
0 commit comments