[PATCH] D30804: [llvm-readobj] Only print the real size of the note
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 18:55:14 PST 2017
phosek created this revision.
Note payloads are padded to a multiple of 4 bytes in size, but the size of the string that should be print can be smaller e.g. the n_descsz field in gold's version note is 9, so that's the whole size of the string that should be printed. The padding is part of the format of a SHT_NOTE section or PT_NOTE segment, but it's not part of the note itself.
Printing the extra null bytes may confuse some tools, e.g. when the llvm-readobj is sent to grep, it treats the output as binary because it contains a null byte.
Repository:
rL LLVM
https://reviews.llvm.org/D30804
Files:
tools/llvm-readobj/ELFDumper.cpp
Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -3367,7 +3367,8 @@
template <typename ELFT>
static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
- ArrayRef<typename ELFFile<ELFT>::Elf_Word> Words) {
+ ArrayRef<typename ELFFile<ELFT>::Elf_Word> Words,
+ size_t Size) {
switch (NoteType) {
default:
return;
@@ -3390,16 +3391,14 @@
}
case ELF::NT_GNU_BUILD_ID: {
OS << " Build ID: ";
- ArrayRef<uint8_t> ID(reinterpret_cast<const uint8_t *>(Words.data()),
- Words.size() * 4);
+ ArrayRef<uint8_t> ID(reinterpret_cast<const uint8_t *>(Words.data()), Size);
for (const auto &B : ID)
OS << format_hex_no_prefix(B, 2);
break;
}
case ELF::NT_GNU_GOLD_VERSION:
OS << " Version: "
- << StringRef(reinterpret_cast<const char *>(Words.data()),
- Words.size() * 4);
+ << StringRef(reinterpret_cast<const char *>(Words.data()), Size);
break;
}
@@ -3443,7 +3442,7 @@
if (Name == "GNU") {
OS << getGNUNoteTypeName(Type) << '\n';
- printGNUNote<ELFT>(OS, Type, Descriptor);
+ printGNUNote<ELFT>(OS, Type, Descriptor, DescriptorSize);
} else if (Name == "FreeBSD") {
OS << getFreeBSDNoteTypeName(Type) << '\n';
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30804.91253.patch
Type: text/x-patch
Size: 1505 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170310/97cba7c6/attachment.bin>
More information about the llvm-commits
mailing list