#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.86 2010/07/21 16:47:18 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.87 2011/05/13 22:15:24 christos Exp $")
#endif
#ifdef BUILTIN_ELF
"NetBSD",
};
-#define FLAGS_DID_CORE 1
-#define FLAGS_DID_NOTE 2
-#define FLAGS_DID_CORE_STYLE 4
-#define FLAGS_IS_CORE 8
+#define FLAGS_DID_CORE 0x01
+#define FLAGS_DID_NOTE 0x02
+#define FLAGS_DID_BUILD_ID 0x04
+#define FLAGS_DID_CORE_STYLE 0x08
+#define FLAGS_IS_CORE 0x10
private int
dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
return (offset >= size) ? offset : size;
}
- if (*flags & FLAGS_DID_NOTE)
+ if ((*flags & (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID)) ==
+ (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID))
goto core;
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
return size;
}
+ if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
+ xnh_type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) {
+ uint32_t desc[5], i;
+ if (file_printf(ms, ", BuildID[%s]=0x", descsz == 16 ? "md5/uuid" :
+ "sha1") == -1)
+ return size;
+ (void)memcpy(desc, &nbuf[doff], descsz);
+ for (i = 0; i < descsz >> 2; i++)
+ if (file_printf(ms, "%.8x", desc[i]) == -1)
+ return size;
+ *flags |= FLAGS_DID_BUILD_ID;
+ }
+
if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0 &&
xnh_type == NT_NETBSD_VERSION && descsz == 4) {
uint32_t desc;
* Note: cobbled from the linux header file, with modifications
*/
#ifndef __fake_elf_h__
-#define __fake_elf_h__
+#define __fake_elf_h__
#if HAVE_STDINT_H
#include <stdint.h>
typedef uint8_t Elf32_Char;
#if SIZEOF_LONG_LONG != 8
-#define USE_ARRAY_FOR_64BIT_TYPES
+#define USE_ARRAY_FOR_64BIT_TYPES
typedef uint32_t Elf64_Addr[2];
typedef uint32_t Elf64_Off[2];
typedef uint32_t Elf64_Xword[2];
typedef uint32_t Elf64_Word;
typedef uint8_t Elf64_Char;
-#define EI_NIDENT 16
+#define EI_NIDENT 16
typedef struct {
Elf32_Char e_ident[EI_NIDENT];
} Elf64_Ehdr;
/* e_type */
-#define ET_REL 1
-#define ET_EXEC 2
-#define ET_DYN 3
-#define ET_CORE 4
+#define ET_REL 1
+#define ET_EXEC 2
+#define ET_DYN 3
+#define ET_CORE 4
/* e_machine (used only for SunOS 5.x hardware capabilities) */
#define EM_SPARC 2
#define EM_AMD64 62
/* sh_type */
-#define SHT_SYMTAB 2
-#define SHT_NOTE 7
-#define SHT_DYNSYM 11
-#define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */
+#define SHT_SYMTAB 2
+#define SHT_NOTE 7
+#define SHT_DYNSYM 11
+#define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */
/* elf type */
-#define ELFDATANONE 0 /* e_ident[EI_DATA] */
-#define ELFDATA2LSB 1
-#define ELFDATA2MSB 2
+#define ELFDATANONE 0 /* e_ident[EI_DATA] */
+#define ELFDATA2LSB 1
+#define ELFDATA2MSB 2
/* elf class */
-#define ELFCLASSNONE 0
-#define ELFCLASS32 1
-#define ELFCLASS64 2
+#define ELFCLASSNONE 0
+#define ELFCLASS32 1
+#define ELFCLASS64 2
/* magic number */
#define EI_MAG0 0 /* e_ident[] indexes */
#define NT_PRFPREG 2
#define NT_PRPSINFO 3
#define NT_PRXREG 4
-#define NT_TASKSTRUCT 4
+#define NT_TASKSTRUCT 4
#define NT_PLATFORM 5
#define NT_AUXV 6
/* Note types used in executables */
/* NetBSD executables (name = "NetBSD") */
-#define NT_NETBSD_VERSION 1
-#define NT_NETBSD_EMULATION 2
-#define NT_FREEBSD_VERSION 1
-#define NT_OPENBSD_VERSION 1
-#define NT_DRAGONFLY_VERSION 1
-/* GNU executables (name = "GNU") */
-#define NT_GNU_VERSION 1
+#define NT_NETBSD_VERSION 1
+#define NT_NETBSD_EMULATION 2
+#define NT_FREEBSD_VERSION 1
+#define NT_OPENBSD_VERSION 1
+#define NT_DRAGONFLY_VERSION 1
+/*
+ * GNU executables (name = "GNU")
+ * word[0]: GNU OS tags
+ * word[1]: major version
+ * word[2]: minor version
+ * word[3]: tiny version
+ */
+#define NT_GNU_VERSION 1
/* GNU OS tags */
-#define GNU_OS_LINUX 0
-#define GNU_OS_HURD 1
-#define GNU_OS_SOLARIS 2
-#define GNU_OS_KFREEBSD 3
-#define GNU_OS_KNETBSD 4
+#define GNU_OS_LINUX 0
+#define GNU_OS_HURD 1
+#define GNU_OS_SOLARIS 2
+#define GNU_OS_KFREEBSD 3
+#define GNU_OS_KNETBSD 4
+
+/*
+ * GNU Hardware capability information
+ * word[0]: Number of entries
+ * word[1]: Bitmask of enabled entries
+ * Followed by a byte id, and a NUL terminated string per entry
+ */
+#define NT_GNU_HWCAP 2
+
+/*
+ * GNU Build ID generated by ld
+ * 160 bit SHA1 [default]
+ * 128 bit md5 or uuid
+ */
+#define NT_GNU_BUILD_ID 3
/* SunOS 5.x hardware/software capabilities */
typedef struct {