[llvm] r299576 - [llvm-readobj] Only print the real size of the note
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 14:19:36 PDT 2017
It should be possible to add a test case, no?
Cheers,
Rafael
On 5 April 2017 at 14:55, Petr Hosek via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: phosek
> Date: Wed Apr 5 13:55:50 2017
> New Revision: 299576
>
> URL: http://llvm.org/viewvc/llvm-project?rev=299576&view=rev
> Log:
> [llvm-readobj] Only print the real size of the note
>
> 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.
>
> Differential Revision: https://reviews.llvm.org/D30804
>
> Modified:
> llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
>
> Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=299576&r1=299575&r2=299576&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
> +++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Wed Apr 5 13:55:50 2017
> @@ -3370,7 +3370,8 @@ static std::string getFreeBSDNoteTypeNam
>
> 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;
> @@ -3393,16 +3394,14 @@ static void printGNUNote(raw_ostream &OS
> }
> 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;
> }
>
> @@ -3446,7 +3445,7 @@ void GNUStyle<ELFT>::printNotes(const EL
>
> 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 {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list