commit 7a3f6fe60b8519b5372f5a5521ccbac59411f33f Author: Mark Wielaard Date: Sun Nov 11 23:50:41 2018 +0100 Recognize NT_VERSION notes. NT_VERSION notes are emitted by the gas .version directive. They have an empty description and (ab)use the owner name to store the version data string. Signed-off-by: Mark Wielaard diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c index 57e9f52..8fda7d9 100644 --- a/libebl/eblobjnote.c +++ b/libebl/eblobjnote.c @@ -135,6 +135,14 @@ ebl_object_note (Ebl *ebl, const char *name, uint32_t type, return; } + /* NT_VERSION doesn't have any info. All data is in the name. */ + if (descsz == 0 && type == NT_VERSION) + return; + + /* Everything else should have the "GNU" owner name. */ + if (strcmp ("GNU", name) != 0) + return; + switch (type) { case NT_GNU_BUILD_ID: @@ -337,7 +345,7 @@ ebl_object_note (Ebl *ebl, const char *name, uint32_t type, break; case NT_GNU_ABI_TAG: - if (strcmp (name, "GNU") == 0 && descsz >= 8 && descsz % 4 == 0) + if (descsz >= 8 && descsz % 4 == 0) { Elf_Data in = { diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c index af23cae..8cdd781 100644 --- a/libebl/eblobjnotetypename.c +++ b/libebl/eblobjnotetypename.c @@ -39,6 +39,7 @@ const char * ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type, + GElf_Word descsz, char *buf, size_t len) { const char *res = ebl->object_note_type_name (name, type, buf, len); @@ -80,14 +81,19 @@ ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type, if (strcmp (name, "GNU") != 0) { + /* NT_VERSION is special, all data is in the name. */ + if (descsz == 0 && type == NT_VERSION) + return "VERSION"; + snprintf (buf, len, "%s: %" PRIu32, gettext (""), type); return buf; } + /* And finally all the "GNU" note types. */ static const char *knowntypes[] = { #define KNOWNSTYPE(name) [NT_##name] = #name - KNOWNSTYPE (VERSION), + KNOWNSTYPE (GNU_ABI_TAG), KNOWNSTYPE (GNU_HWCAP), KNOWNSTYPE (GNU_BUILD_ID), KNOWNSTYPE (GNU_GOLD_VERSION), diff --git a/libebl/libebl.h b/libebl/libebl.h index a34fe48..5830654 100644 --- a/libebl/libebl.h +++ b/libebl/libebl.h @@ -175,8 +175,8 @@ extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, /* Return name of the note section type for an object file. */ extern const char *ebl_object_note_type_name (Ebl *ebl, const char *name, - uint32_t type, char *buf, - size_t len); + uint32_t type, GElf_Word descsz, + char *buf, size_t len); /* Print information about object note if available. */ extern void ebl_object_note (Ebl *ebl, const char *name, uint32_t type, diff --git a/src/elflint.c b/src/elflint.c index fa3af4c..dff74ee 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -1,5 +1,5 @@ /* Pedantic checking of ELF files compliance with gABI/psABI spec. - Copyright (C) 2001-2015, 2017 Red Hat, Inc. + Copyright (C) 2001-2015, 2017, 2018 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper , 2001. @@ -4332,7 +4332,17 @@ section [%2d] '%s': unknown core file note type %" PRIu32 case NT_GNU_BUILD_ID: case NT_GNU_GOLD_VERSION: case NT_GNU_PROPERTY_TYPE_0: - break; + if (nhdr.n_namesz == sizeof ELF_NOTE_GNU + && strcmp (data->d_buf + name_offset, ELF_NOTE_GNU) == 0) + break; + else + { + /* NT_VERSION is 1, same as NT_GNU_ABI_TAG. It has no + descriptor and (ab)uses the name as version string. */ + if (nhdr.n_descsz == 0 && nhdr.n_type == NT_VERSION) + break; + } + goto unknown_note; case 0: /* Linux vDSOs use a type 0 note for the kernel version word. */ @@ -4341,16 +4351,21 @@ section [%2d] '%s': unknown core file note type %" PRIu32 break; FALLTHROUGH; default: + { + unknown_note: if (shndx == 0) ERROR (gettext ("\ -phdr[%d]: unknown object file note type %" PRIu32 " at offset %zu\n"), - phndx, (uint32_t) nhdr.n_type, offset); +phdr[%d]: unknown object file note type %" PRIu32 " with owner name '%s' at offset %zu\n"), + phndx, (uint32_t) nhdr.n_type, + (char *) data->d_buf + name_offset, offset); else ERROR (gettext ("\ section [%2d] '%s': unknown object file note type %" PRIu32 - " at offset %zu\n"), + " with owner name '%s' at offset %zu\n"), shndx, section_name (ebl, shndx), - (uint32_t) nhdr.n_type, offset); + (uint32_t) nhdr.n_type, + (char *) data->d_buf + name_offset, offset); + } } } diff --git a/src/readelf.c b/src/readelf.c index c6c3fb3..659e34f 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -12201,6 +12201,7 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr, ? ebl_core_note_type_name (ebl, nhdr.n_type, buf, sizeof (buf)) : ebl_object_note_type_name (ebl, name, nhdr.n_type, + nhdr.n_descsz, buf2, sizeof (buf2))); /* Filter out invalid entries. */