llvm.org GIT mirror llvm / 8e90617
[llvm-readobj] Implement LLVM style printer for --notes Summary: Port the GNU style printNotes method to the LLVMStyle subclass. This is basically just a heavy refactor so that the note parsing/formatting logic from the GNUStyle::printNotes can be shared with LLVMStyle::printNotes. Reviewers: MaskRay Reviewed By: MaskRay Subscribers: dschuff, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D54220 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346371 91177308-0d34-0410-b5e6-96231b3b80d8 Jordan Rupprecht 10 months ago
4 changed file(s) with 344 addition(s) and 124 deletion(s). Raw diff Collapse all Expand all
0 # RUN: yaml2obj %s > %t.so
1 # RUN: llvm-readobj -elf-output-style GNU --notes %t.so | FileCheck %s
1 # RUN: llvm-readobj -elf-output-style GNU --notes %t.so | FileCheck %s --check-prefix=GNU
2 # RUN: llvm-readobj -elf-output-style LLVM --notes %t.so | FileCheck %s --check-prefix=LLVM
23
3 # CHECK: Displaying notes found at file offset 0x00000300 with length 0x00000020:
4 # CHECK: Owner Data size Description
5 # CHECK: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
6 # CHECK: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
4 # GNU: Displaying notes found at file offset 0x00000340 with length 0x00000020:
5 # GNU-NEXT: Owner Data size Description
6 # GNU-NEXT: GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
7 # GNU-NEXT: OS: Linux, ABI: 2.6.32
78
8 # CHECK: Displaying notes found at file offset 0x0000036c with length 0x0000001c:
9 # CHECK: Owner Data size Description
10 # CHECK: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
11 # CHECK: Version: gold 1.11
9 # GNU: Displaying notes found at file offset 0x00000360 with length 0x00000020:
10 # GNU-NEXT: Owner Data size Description
11 # GNU-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
12 # GNU-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
13
14 # GNU: Displaying notes found at file offset 0x000003cc with length 0x0000001c:
15 # GNU-NEXT: Owner Data size Description
16 # GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
17 # GNU-NEXT: Version: gold 1.11
18
19 # LLVM: Notes [
20 # LLVM-NEXT: NoteSection {
21 # LLVM-NEXT: Offset: 0x340
22 # LLVM-NEXT: Size: 0x20
23 # LLVM-NEXT: Note {
24 # LLVM-NEXT: Owner: GNU
25 # LLVM-NEXT: Data size: 0x10
26 # LLVM-NEXT: Type: NT_GNU_ABI_TAG (ABI version tag)
27 # LLVM-NEXT: OS: Linux
28 # LLVM-NEXT: ABI: 2.6.32
29 # LLVM-NEXT: }
30 # LLVM-NEXT: }
31 # LLVM-NEXT: NoteSection {
32 # LLVM-NEXT: Offset: 0x360
33 # LLVM-NEXT: Size: 0x20
34 # LLVM-NEXT: Note {
35 # LLVM-NEXT: Owner: GNU
36 # LLVM-NEXT: Data size: 0x10
37 # LLVM-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)
38 # LLVM-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
39 # LLVM-NEXT: }
40 # LLVM-NEXT: }
41 # LLVM-NEXT: NoteSection {
42 # LLVM-NEXT: Offset: 0x3CC
43 # LLVM-NEXT: Size: 0x1C
44 # LLVM-NEXT: Note {
45 # LLVM-NEXT: Owner: GNU
46 # LLVM-NEXT: Data size: 0x9
47 # LLVM-NEXT: Type: NT_GNU_GOLD_VERSION (gold version)
48 # LLVM-NEXT: Version: gold 1.11
49 # LLVM-NEXT: }
50 # LLVM-NEXT: }
51 # LLVM-NEXT: ]
1252
1353 --- !ELF
1454 FileHeader:
1757 Type: ET_EXEC
1858 Machine: EM_X86_64
1959 Sections:
60 - Name: .note.ABI-tag
61 Type: SHT_NOTE
62 AddressAlign: 0x0000000000000004
63 Content: 040000001000000001000000474E550000000000020000000600000020000000
2064 - Name: .note.gnu.build-id
2165 Type: SHT_NOTE
2266 Flags: [ SHF_ALLOC ]
0 // REQUIRES: x86-registered-target
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
2 // RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
2 // RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s --check-prefix=GNU
3 // RUN: llvm-readobj -elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM
34
4 // CHECK: Displaying notes found at file offset 0x00000040 with length 0x000000b8:
5 // CHECK-NEXT: Owner Data size Description
6 // CHECK-NEXT: GNU 0x000000a8 NT_GNU_PROPERTY_TYPE_0 (property note)
7 // CHECK-NEXT: Properties: stack size: 0x100
8 // CHECK-NEXT: stack size: 0x100
9 // CHECK-NEXT: no copy on protected
10 // CHECK-NEXT: X86 features: SHSTK
11 // CHECK-NEXT: X86 features: IBT, SHSTK
12 // CHECK-NEXT: X86 features: none
13 // CHECK-NEXT:
14 // CHECK-NEXT: stack size:
15 // CHECK-NEXT: stack size:
16 // CHECK-NEXT: no copy on protected
17 // CHECK-NEXT: X86 features:
18 // CHECK-NEXT: X86 features: IBT,
19 // CHECK-NEXT:
5 // GNU: Displaying notes found at file offset 0x00000040 with length 0x000000b8:
6 // GNU-NEXT: Owner Data size Description
7 // GNU-NEXT: GNU 0x000000a8 NT_GNU_PROPERTY_TYPE_0 (property note)
8 // GNU-NEXT: Properties: stack size: 0x100
9 // GNU-NEXT: stack size: 0x100
10 // GNU-NEXT: no copy on protected
11 // GNU-NEXT: X86 features: SHSTK
12 // GNU-NEXT: X86 features: IBT, SHSTK
13 // GNU-NEXT: X86 features: none
14 // GNU-NEXT:
15 // GNU-NEXT: stack size:
16 // GNU-NEXT: stack size:
17 // GNU-NEXT: no copy on protected
18 // GNU-NEXT: X86 features:
19 // GNU-NEXT: X86 features: IBT,
20 // GNU-NEXT:
21
22 // LLVM: Notes [
23 // LLVM-NEXT: NoteSection {
24 // LLVM-NEXT: Offset: 0x40
25 // LLVM-NEXT: Size: 0xB8
26 // LLVM-NEXT: Note {
27 // LLVM-NEXT: Owner: GNU
28 // LLVM-NEXT: Data size: 0xA8
29 // LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
30 // LLVM-NEXT: Property [
31 // LLVM-NEXT: stack size: 0x100
32 // LLVM-NEXT: stack size: 0x100
33 // LLVM-NEXT: no copy on protected
34 // LLVM-NEXT: X86 features: SHSTK
35 // LLVM-NEXT: X86 features: IBT, SHSTK
36 // LLVM-NEXT: X86 features: none
37 // LLVM-NEXT:
38 // LLVM-NEXT: stack size:
39 // LLVM-NEXT: stack size:
40 // LLVM-NEXT: no copy on protected
41 // LLVM-NEXT: X86 features:
42 // LLVM-NEXT: X86 features: IBT,
43 // LLVM-NEXT:
44 // LLVM-NEXT: ]
45 // LLVM-NEXT: }
46 // LLVM-NEXT: }
47 // LLVM-NEXT: ]
2048
2149 .section ".note.gnu.property", "a"
2250 .align 4
0 // REQUIRES: x86-registered-target
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
2 // RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
2 // RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s --check-prefix=GNU
3 // RUN: llvm-readobj -elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM
34
4 // CHECK: Displaying notes found at file offset 0x00000040 with length 0x00000014:
5 // CHECK-NEXT: Owner Data size Description
6 // CHECK-NEXT: GNU 0x00000004 NT_GNU_PROPERTY_TYPE_0 (property note)
7 // CHECK-NEXT: Properties:
5 // GNU: Displaying notes found at file offset 0x00000040 with length 0x00000014:
6 // GNU-NEXT: Owner Data size Description
7 // GNU-NEXT: GNU 0x00000004 NT_GNU_PROPERTY_TYPE_0 (property note)
8 // GNU-NEXT: Properties:
9
10 // LLVM: Notes [
11 // LLVM-NEXT: NoteSection {
12 // LLVM-NEXT: Offset: 0x40
13 // LLVM-NEXT: Size: 0x14
14 // LLVM-NEXT: Note {
15 // LLVM-NEXT: Owner: GNU
16 // LLVM-NEXT: Data size: 0x4
17 // LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
18 // LLVM-NEXT: Property [
19 // LLVM-NEXT:
20 // LLVM-NEXT: ]
21 // LLVM-NEXT: }
22 // LLVM-NEXT: }
23 // LLVM-NEXT: ]
824
925 // Section below is broken, check we report that.
1026
2121 #include "llvm/ADT/DenseMap.h"
2222 #include "llvm/ADT/Optional.h"
2323 #include "llvm/ADT/PointerIntPair.h"
24 #include "llvm/ADT/STLExtras.h"
2425 #include "llvm/ADT/SmallString.h"
2526 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/STLExtras.h"
2727 #include "llvm/ADT/StringExtras.h"
2828 #include "llvm/ADT/StringRef.h"
2929 #include "llvm/ADT/Twine.h"
4242 #include "llvm/Support/Endian.h"
4343 #include "llvm/Support/ErrorHandling.h"
4444 #include "llvm/Support/Format.h"
45 #include "llvm/Support/FormatVariadic.h"
4546 #include "llvm/Support/FormattedStream.h"
4647 #include "llvm/Support/LEB128.h"
4748 #include "llvm/Support/MathExtras.h"
36533654 }
36543655
36553656 template
3656 static void printGNUProperty(raw_ostream &OS, uint32_t Type, uint32_t DataSize,
3657 ArrayRef Data) {
3657 static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
3658 ArrayRef Data) {
3659 std::string str;
3660 raw_string_ostream OS(str);
36583661 switch (Type) {
36593662 default:
3660 OS << format(" \n", Type);
3661 return;
3663 OS << format("", Type);
3664 return OS.str();
36623665 case GNU_PROPERTY_STACK_SIZE: {
3663 OS << " stack size: ";
3666 OS << "stack size: ";
36643667 if (DataSize == sizeof(typename ELFT::uint))
3665 OS << format("0x%llx\n",
3666 (uint64_t)(*(const typename ELFT::Addr *)Data.data()));
3668 OS << formatv("{0:x}",
3669 (uint64_t)(*(const typename ELFT::Addr *)Data.data()));
36673670 else
3668 OS << format("\n", DataSize);
3669 break;
3671 OS << format("", DataSize);
3672 return OS.str();
36703673 }
36713674 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
3672 OS << " no copy on protected";
3675 OS << "no copy on protected";
36733676 if (DataSize)
36743677 OS << format(" ", DataSize);
3675 OS << "\n";
3676 break;
3678 return OS.str();
36773679 case GNU_PROPERTY_X86_FEATURE_1_AND:
3678 OS << " X86 features: ";
3680 OS << "X86 features: ";
36793681 if (DataSize != 4 && DataSize != 8) {
3680 OS << format("\n", DataSize);
3681 break;
3682 OS << format("", DataSize);
3683 return OS.str();
36823684 }
36833685 uint64_t CFProtection =
36843686 (DataSize == 4)
36853687 ? support::endian::read32(Data.data())
36863688 : support::endian::read64(Data.data());
36873689 if (CFProtection == 0) {
3688 OS << "none\n";
3689 break;
3690 OS << "none";
3691 return OS.str();
36903692 }
36913693 if (CFProtection & GNU_PROPERTY_X86_FEATURE_1_IBT) {
36923694 OS << "IBT";
37023704 }
37033705 if (CFProtection)
37043706 OS << format("", CFProtection);
3705 OS << "\n";
3706 break;
3707 }
3707 return OS.str();
3708 }
3709 }
3710
3711 template
3712 static SmallVector
3713 getGNUPropertyList(ArrayRef Words) {
3714 using Elf_Word = typename ELFT::Word;
3715
3716 SmallVector Properties;
3717 ArrayRef Arr(reinterpret_cast(Words.data()),
3718 Words.size());
3719 while (Arr.size() >= 8) {
3720 uint32_t Type = *reinterpret_cast(Arr.data());
3721 uint32_t DataSize = *reinterpret_cast(Arr.data() + 4);
3722 Arr = Arr.drop_front(8);
3723
3724 // Take padding size into account if present.
3725 uint64_t PaddedSize = alignTo(DataSize, sizeof(typename ELFT::uint));
3726 std::string str;
3727 raw_string_ostream OS(str);
3728 if (Arr.size() < PaddedSize) {
3729 OS << format("", Type, DataSize);
3730 Properties.push_back(OS.str());
3731 break;
3732 }
3733 Properties.push_back(
3734 getGNUProperty(Type, DataSize, Arr.take_front(PaddedSize)));
3735 Arr = Arr.drop_front(PaddedSize);
3736 }
3737
3738 if (!Arr.empty())
3739 Properties.push_back("");
3740
3741 return Properties;
3742 }
3743
3744 struct GNUAbiTag {
3745 std::string OSName;
3746 std::string ABI;
3747 bool IsValid;
3748 };
3749
3750 template
3751 static GNUAbiTag getGNUAbiTag(ArrayRef Words) {
3752 if (Words.size() < 4)
3753 return {"", "", /*IsValid=*/false};
3754
3755 static const char *OSNames[] = {
3756 "Linux", "Hurd", "Solaris", "FreeBSD", "NetBSD", "Syllable", "NaCl",
3757 };
3758 StringRef OSName = "Unknown";
3759 if (Words[0] < array_lengthof(OSNames))
3760 OSName = OSNames[Words[0]];
3761 uint32_t Major = Words[1], Minor = Words[2], Patch = Words[3];
3762 std::string str;
3763 raw_string_ostream ABI(str);
3764 ABI << Major << "." << Minor << "." << Patch;
3765 return {OSName, ABI.str(), /*IsValid=*/true};
3766 }
3767
3768 template
3769 static std::string getGNUBuildId(ArrayRef Words) {
3770 std::string str;
3771 raw_string_ostream OS(str);
3772 ArrayRef ID(reinterpret_cast(Words.data()),
3773 Words.size());
3774 for (const auto &B : ID)
3775 OS << format_hex_no_prefix(B, 2);
3776 return OS.str();
3777 }
3778
3779 template
3780 static StringRef getGNUGoldVersion(ArrayRef Words) {
3781 return StringRef(reinterpret_cast(Words.data()), Words.size());
37083782 }
37093783
37103784 template
37113785 static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
3712 ArrayRef Words, size_t Size) {
3713 using Elf_Word = typename ELFT::Word;
3714
3786 ArrayRef Words) {
37153787 switch (NoteType) {
37163788 default:
37173789 return;
37183790 case ELF::NT_GNU_ABI_TAG: {
3719 static const char *OSNames[] = {
3720 "Linux", "Hurd", "Solaris", "FreeBSD", "NetBSD", "Syllable", "NaCl",
3721 };
3722
3723 StringRef OSName = "Unknown";
3724 if (Words[0] < array_lengthof(OSNames))
3725 OSName = OSNames[Words[0]];
3726 uint32_t Major = Words[1], Minor = Words[2], Patch = Words[3];
3727
3728 if (Words.size() < 4)
3791 const GNUAbiTag &AbiTag = getGNUAbiTag(Words);
3792 if (!AbiTag.IsValid)
37293793 OS << " ";
37303794 else
3731 OS << " OS: " << OSName << ", ABI: " << Major << "." << Minor << "."
3732 << Patch;
3795 OS << " OS: " << AbiTag.OSName << ", ABI: " << AbiTag.ABI;
37333796 break;
37343797 }
37353798 case ELF::NT_GNU_BUILD_ID: {
3736 OS << " Build ID: ";
3737 ArrayRef ID(reinterpret_cast(Words.data()), Size);
3738 for (const auto &B : ID)
3739 OS << format_hex_no_prefix(B, 2);
3799 OS << " Build ID: " << getGNUBuildId(Words);
37403800 break;
37413801 }
37423802 case ELF::NT_GNU_GOLD_VERSION:
3743 OS << " Version: "
3744 << StringRef(reinterpret_cast(Words.data()), Size);
3803 OS << " Version: " << getGNUGoldVersion(Words);
37453804 break;
37463805 case ELF::NT_GNU_PROPERTY_TYPE_0:
37473806 OS << " Properties:";
3748
3749 ArrayRef Arr(reinterpret_cast(Words.data()),
3750 Size);
3751 while (Arr.size() >= 8) {
3752 uint32_t Type = *reinterpret_cast(Arr.data());
3753 uint32_t DataSize = *reinterpret_cast(Arr.data() + 4);
3754 Arr = Arr.drop_front(8);
3755
3756 // Take padding size into account if present.
3757 uint64_t PaddedSize = alignTo(DataSize, sizeof(typename ELFT::uint));
3758 if (Arr.size() < PaddedSize) {
3759 OS << format(" \n", Type,
3760 DataSize);
3761 break;
3762 }
3763 printGNUProperty(OS, Type, DataSize, Arr.take_front(PaddedSize));
3764 Arr = Arr.drop_front(PaddedSize);
3765 }
3766
3767 if (!Arr.empty())
3768 OS << " ";
3807 for (const auto &Property : getGNUPropertyList(Words))
3808 OS << " " << Property << "\n";
37693809 break;
37703810 }
37713811 OS << '\n';
37723812 }
37733813
3814 struct AMDGPUNote {
3815 std::string type;
3816 std::string value;
3817 };
3818
37743819 template
3775 static void printAMDGPUNote(raw_ostream &OS, uint32_t NoteType,
3776 ArrayRef Words, size_t Size) {
3820 static AMDGPUNote getAMDGPUNote(uint32_t NoteType,
3821 ArrayRef Words) {
37773822 switch (NoteType) {
37783823 default:
3779 return;
3780 case ELF::NT_AMD_AMDGPU_HSA_METADATA:
3781 OS << " HSA Metadata:\n"
3782 << StringRef(reinterpret_cast(Words.data()), Size);
3783 break;
3784 case ELF::NT_AMD_AMDGPU_ISA:
3785 OS << " ISA Version:\n"
3786 << " "
3787 << StringRef(reinterpret_cast(Words.data()), Size);
3788 break;
3789 case ELF::NT_AMD_AMDGPU_PAL_METADATA:
3790 const uint32_t *PALMetadataBegin = reinterpret_cast(Words.data());
3791 const uint32_t *PALMetadataEnd = PALMetadataBegin + Size;
3792 std::vector PALMetadata(PALMetadataBegin, PALMetadataEnd);
3793 std::string PALMetadataString;
3794 auto Error = AMDGPU::PALMD::toString(PALMetadata, PALMetadataString);
3795 OS << " PAL Metadata:\n";
3796 if (Error) {
3797 OS << " Invalid";
3798 return;
3799 }
3800 OS << PALMetadataString;
3801 break;
3802 }
3803 OS.flush();
3824 return {"", ""};
3825 case ELF::NT_AMD_AMDGPU_HSA_METADATA:
3826 return {"HSA Metadata",
3827 std::string(reinterpret_cast(Words.data()),
3828 Words.size())};
3829 case ELF::NT_AMD_AMDGPU_ISA:
3830 return {"ISA Version",
3831 std::string(reinterpret_cast(Words.data()),
3832 Words.size())};
3833 case ELF::NT_AMD_AMDGPU_PAL_METADATA:
3834 const uint32_t *PALMetadataBegin =
3835 reinterpret_cast(Words.data());
3836 const uint32_t *PALMetadataEnd = PALMetadataBegin + Words.size();
3837 std::vector PALMetadata(PALMetadataBegin, PALMetadataEnd);
3838 std::string PALMetadataString;
3839 auto Error = AMDGPU::PALMD::toString(PALMetadata, PALMetadataString);
3840 if (Error) {
3841 return {"PAL Metadata", "Invalid"};
3842 }
3843 return {"PAL Metadata", PALMetadataString};
3844 }
38043845 }
38053846
38063847 template
38253866
38263867 if (Name == "GNU") {
38273868 OS << getGNUNoteTypeName(Type) << '\n';
3828 printGNUNote(OS, Type, Descriptor, Descriptor.size());
3869 printGNUNote(OS, Type, Descriptor);
38293870 } else if (Name == "FreeBSD") {
38303871 OS << getFreeBSDNoteTypeName(Type) << '\n';
38313872 } else if (Name == "AMD") {
38323873 OS << getAMDGPUNoteTypeName(Type) << '\n';
3833 printAMDGPUNote(OS, Type, Descriptor, Descriptor.size());
3874 const AMDGPUNote N = getAMDGPUNote(Type, Descriptor);
3875 if (!N.type.empty())
3876 OS << " " << N.type << ":\n " << N.value << '\n';
38343877 } else {
38353878 OS << "Unknown note type: (" << format_hex(Type, 10) << ')';
38363879 }
44344477 }
44354478 }
44364479
4480 template
4481 static void printGNUNoteLLVMStyle(uint32_t NoteType,
4482 ArrayRef Words,
4483 ScopedPrinter &W) {
4484 switch (NoteType) {
4485 default:
4486 return;
4487 case ELF::NT_GNU_ABI_TAG: {
4488 const GNUAbiTag &AbiTag = getGNUAbiTag(Words);
4489 if (!AbiTag.IsValid) {
4490 W.printString("ABI", "");
4491 } else {
4492 W.printString("OS", AbiTag.OSName);
4493 W.printString("ABI", AbiTag.ABI);
4494 }
4495 break;
4496 }
4497 case ELF::NT_GNU_BUILD_ID: {
4498 W.printString("Build ID", getGNUBuildId(Words));
4499 break;
4500 }
4501 case ELF::NT_GNU_GOLD_VERSION:
4502 W.printString("Version", getGNUGoldVersion(Words));
4503 break;
4504 case ELF::NT_GNU_PROPERTY_TYPE_0:
4505 ListScope D(W, "Property");
4506 for (const auto &Property : getGNUPropertyList(Words))
4507 W.printString(Property);
4508 break;
4509 }
4510 }
4511
44374512 template
44384513 void LLVMStyle::printNotes(const ELFFile *Obj) {
4439 W.startLine() << "printNotes not implemented!\n";
4514 ListScope L(W, "Notes");
4515 const Elf_Ehdr *e = Obj->getHeader();
4516 bool IsCore = e->e_type == ELF::ET_CORE;
4517
4518 auto PrintHeader = [&](const typename ELFT::Off Offset,
4519 const typename ELFT::Addr Size) {
4520 W.printHex("Offset", Offset);
4521 W.printHex("Size", Size);
4522 };
4523
4524 auto ProcessNote = [&](const Elf_Note &Note) {
4525 DictScope D2(W, "Note");
4526 StringRef Name = Note.getName();
4527 ArrayRef Descriptor = Note.getDesc();
4528 Elf_Word Type = Note.getType();
4529
4530 W.printString("Owner", Name);
4531 W.printHex("Data size", Descriptor.size());
4532 if (Name == "GNU") {
4533 W.printString("Type", getGNUNoteTypeName(Type));
4534 printGNUNoteLLVMStyle(Type, Descriptor, W);
4535 } else if (Name == "FreeBSD") {
4536 W.printString("Type", getFreeBSDNoteTypeName(Type));
4537 } else if (Name == "AMD") {
4538 W.printString("Type", getAMDGPUNoteTypeName(Type));
4539 const AMDGPUNote N = getAMDGPUNote(Type, Descriptor);
4540 if (!N.type.empty())
4541 W.printString(N.type, N.value);
4542 } else {
4543 W.getOStream() << "Unknown note type: (" << format_hex(Type, 10) << ')';
4544 }
4545 };
4546
4547 if (IsCore) {
4548 for (const auto &P : unwrapOrError(Obj->program_headers())) {
4549 if (P.p_type != PT_NOTE)
4550 continue;
4551 DictScope D(W, "NoteSection");
4552 PrintHeader(P.p_offset, P.p_filesz);
4553 Error Err = Error::success();
4554 for (const auto &Note : Obj->notes(P, Err))
4555 ProcessNote(Note);
4556 if (Err)
4557 error(std::move(Err));
4558 }
4559 } else {
4560 for (const auto &S : unwrapOrError(Obj->sections())) {
4561 if (S.sh_type != SHT_NOTE)
4562 continue;
4563 DictScope D(W, "NoteSection");
4564 PrintHeader(S.sh_offset, S.sh_size);
4565 Error Err = Error::success();
4566 for (const auto &Note : Obj->notes(S, Err))
4567 ProcessNote(Note);
4568 if (Err)
4569 error(std::move(Err));
4570 }
4571 }
44404572 }
44414573
44424574 template