forked from OSchip/llvm-project
[llvm-readobj] Add some generic notes (e.g. NT_VERSION)
Summary: Support reading notes that don't have a standard note name. Reviewers: MaskRay Reviewed By: MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59969 llvm-svn: 357271
This commit is contained in:
parent
342aaa14b1
commit
871baa2551
|
@ -1339,6 +1339,14 @@ enum {
|
||||||
NT_FREEBSD_PROCSTAT_AUXV = 16,
|
NT_FREEBSD_PROCSTAT_AUXV = 16,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Generic note types
|
||||||
|
enum : unsigned {
|
||||||
|
NT_VERSION = 1,
|
||||||
|
NT_ARCH = 2,
|
||||||
|
NT_GNU_BUILD_ATTRIBUTE_OPEN = 0x100,
|
||||||
|
NT_GNU_BUILD_ATTRIBUTE_FUNC = 0x101,
|
||||||
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NT_GNU_ABI_TAG = 1,
|
NT_GNU_ABI_TAG = 1,
|
||||||
NT_GNU_HWCAP = 2,
|
NT_GNU_HWCAP = 2,
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
// REQUIRES: x86-registered-target
|
||||||
|
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t.o
|
||||||
|
|
||||||
|
// RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
|
||||||
|
// RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
|
||||||
|
|
||||||
|
// GNU: Displaying notes found at file offset 0x00000040 with length 0x00000010:
|
||||||
|
// GNU-NEXT: Owner Data size Description
|
||||||
|
// GNU-NEXT: XYZ 0x00000000 NT_VERSION (version)
|
||||||
|
|
||||||
|
// GNU: Displaying notes found at file offset 0x00000050 with length 0x00000010:
|
||||||
|
// GNU-NEXT: Owner Data size Description
|
||||||
|
// GNU-NEXT: XYZ 0x00000000 NT_ARCH (architecture)
|
||||||
|
|
||||||
|
// GNU: Displaying notes found at file offset 0x00000060 with length 0x00000010:
|
||||||
|
// GNU-NEXT: Owner Data size Description
|
||||||
|
// GNU-NEXT: XYZ 0x00000000 OPEN
|
||||||
|
|
||||||
|
// GNU: Displaying notes found at file offset 0x00000070 with length 0x00000010:
|
||||||
|
// GNU-NEXT: Owner Data size Description
|
||||||
|
// GNU-NEXT: XYZ 0x00000000 func
|
||||||
|
|
||||||
|
// LLVM: Notes [
|
||||||
|
// LLVM-NEXT: NoteSection {
|
||||||
|
// LLVM-NEXT: Offset: 0x40
|
||||||
|
// LLVM-NEXT: Size: 0x10
|
||||||
|
// LLVM-NEXT: Note {
|
||||||
|
// LLVM-NEXT: Owner: XYZ
|
||||||
|
// LLVM-NEXT: Data size: 0x0
|
||||||
|
// LLVM-NEXT: Type: NT_VERSION (version)
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: NoteSection {
|
||||||
|
// LLVM-NEXT: Offset: 0x50
|
||||||
|
// LLVM-NEXT: Size: 0x10
|
||||||
|
// LLVM-NEXT: Note {
|
||||||
|
// LLVM-NEXT: Owner: XYZ
|
||||||
|
// LLVM-NEXT: Data size: 0x0
|
||||||
|
// LLVM-NEXT: Type: NT_ARCH (architecture)
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: NoteSection {
|
||||||
|
// LLVM-NEXT: Offset: 0x60
|
||||||
|
// LLVM-NEXT: Size: 0x10
|
||||||
|
// LLVM-NEXT: Note {
|
||||||
|
// LLVM-NEXT: Owner: XYZ
|
||||||
|
// LLVM-NEXT: Data size: 0x0
|
||||||
|
// LLVM-NEXT: Type: OPEN
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: NoteSection {
|
||||||
|
// LLVM-NEXT: Offset: 0x70
|
||||||
|
// LLVM-NEXT: Size: 0x10
|
||||||
|
// LLVM-NEXT: Note {
|
||||||
|
// LLVM-NEXT: Owner: XYZ
|
||||||
|
// LLVM-NEXT: Data size: 0x0
|
||||||
|
// LLVM-NEXT: Type: func
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: }
|
||||||
|
// LLVM-NEXT: ]
|
||||||
|
|
||||||
|
.section ".note.version", "a"
|
||||||
|
.align 4
|
||||||
|
.long 4 /* namesz */
|
||||||
|
.long 0 /* descsz */
|
||||||
|
.long 1 /* type = NT_VERSION */
|
||||||
|
.asciz "XYZ"
|
||||||
|
.section ".note.arch", "a"
|
||||||
|
.align 4
|
||||||
|
.long 4 /* namesz */
|
||||||
|
.long 0 /* descsz */
|
||||||
|
.long 2 /* type = NT_ARCH*/
|
||||||
|
.asciz "XYZ"
|
||||||
|
.section ".note.open", "a"
|
||||||
|
.align 4
|
||||||
|
.long 4 /* namesz */
|
||||||
|
.long 0 /* descsz */
|
||||||
|
.long 0x100 /* type = NT_GNU_BUILD_ATTRIBUTE_OPEN*/
|
||||||
|
.asciz "XYZ"
|
||||||
|
.section ".note.func", "a"
|
||||||
|
.align 4
|
||||||
|
.long 4 /* namesz */
|
||||||
|
.long 0 /* descsz */
|
||||||
|
.long 0x101 /* type = NT_GNU_BUILD_ATTRIBUTE_FUNC*/
|
||||||
|
.asciz "XYZ"
|
|
@ -3489,6 +3489,24 @@ void GNUStyle<ELFT>::printAddrsig(const ELFFile<ELFT> *Obj) {
|
||||||
OS << "GNUStyle::printAddrsig not implemented\n";
|
OS << "GNUStyle::printAddrsig not implemented\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static StringRef getGenericNoteTypeName(const uint32_t NT) {
|
||||||
|
static const struct {
|
||||||
|
uint32_t ID;
|
||||||
|
const char *Name;
|
||||||
|
} Notes[] = {
|
||||||
|
{ELF::NT_VERSION, "NT_VERSION (version)"},
|
||||||
|
{ELF::NT_ARCH, "NT_ARCH (architecture)"},
|
||||||
|
{ELF::NT_GNU_BUILD_ATTRIBUTE_OPEN, "OPEN"},
|
||||||
|
{ELF::NT_GNU_BUILD_ATTRIBUTE_FUNC, "func"},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto &Note : Notes)
|
||||||
|
if (Note.ID == NT)
|
||||||
|
return Note.Name;
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
static std::string getGNUNoteTypeName(const uint32_t NT) {
|
static std::string getGNUNoteTypeName(const uint32_t NT) {
|
||||||
static const struct {
|
static const struct {
|
||||||
uint32_t ID;
|
uint32_t ID;
|
||||||
|
@ -3877,7 +3895,11 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
|
||||||
if (!N.Type.empty())
|
if (!N.Type.empty())
|
||||||
OS << " " << N.Type << ":\n " << N.Value << '\n';
|
OS << " " << N.Type << ":\n " << N.Value << '\n';
|
||||||
} else {
|
} else {
|
||||||
OS << "Unknown note type: (" << format_hex(Type, 10) << ')';
|
StringRef NoteType = getGenericNoteTypeName(Type);
|
||||||
|
if (!NoteType.empty())
|
||||||
|
OS << NoteType;
|
||||||
|
else
|
||||||
|
OS << "Unknown note type: (" << format_hex(Type, 10) << ')';
|
||||||
}
|
}
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
};
|
};
|
||||||
|
@ -4682,8 +4704,12 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
|
||||||
if (!N.Type.empty())
|
if (!N.Type.empty())
|
||||||
W.printString(N.Type, N.Value);
|
W.printString(N.Type, N.Value);
|
||||||
} else {
|
} else {
|
||||||
W.printString("Type",
|
StringRef NoteType = getGenericNoteTypeName(Type);
|
||||||
"Unknown (" + to_string(format_hex(Type, 10)) + ")");
|
if (!NoteType.empty())
|
||||||
|
W.printString("Type", NoteType);
|
||||||
|
else
|
||||||
|
W.printString("Type",
|
||||||
|
"Unknown (" + to_string(format_hex(Type, 10)) + ")");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue