perf symbols: Fix a memory leak in vmlinux_path__init()
[deliverable/linux.git] / tools / perf / util / symbol-minimal.c
index bd15f490d04fe5ea83607d761b65bcdfca09cbbe..c9541fea95148163b380979a5d5a8a8405bfd692 100644 (file)
@@ -288,6 +288,44 @@ int dso__synthesize_plt_symbols(struct dso *dso __maybe_unused,
        return 0;
 }
 
+static int fd__is_64_bit(int fd)
+{
+       u8 e_ident[EI_NIDENT];
+
+       if (lseek(fd, 0, SEEK_SET))
+               return -1;
+
+       if (readn(fd, e_ident, sizeof(e_ident)) != sizeof(e_ident))
+               return -1;
+
+       if (memcmp(e_ident, ELFMAG, SELFMAG) ||
+           e_ident[EI_VERSION] != EV_CURRENT)
+               return -1;
+
+       return e_ident[EI_CLASS] == ELFCLASS64;
+}
+
+enum dso_type dso__type_fd(int fd)
+{
+       Elf64_Ehdr ehdr;
+       int ret;
+
+       ret = fd__is_64_bit(fd);
+       if (ret < 0)
+               return DSO__TYPE_UNKNOWN;
+
+       if (ret)
+               return DSO__TYPE_64BIT;
+
+       if (readn(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr))
+               return DSO__TYPE_UNKNOWN;
+
+       if (ehdr.e_machine == EM_X86_64)
+               return DSO__TYPE_X32BIT;
+
+       return DSO__TYPE_32BIT;
+}
+
 int dso__load_sym(struct dso *dso, struct map *map __maybe_unused,
                  struct symsrc *ss,
                  struct symsrc *runtime_ss __maybe_unused,
@@ -295,6 +333,11 @@ int dso__load_sym(struct dso *dso, struct map *map __maybe_unused,
                  int kmodule __maybe_unused)
 {
        unsigned char *build_id[BUILD_ID_SIZE];
+       int ret;
+
+       ret = fd__is_64_bit(ss->fd);
+       if (ret >= 0)
+               dso->is_64_bit = ret;
 
        if (filename__read_build_id(ss->name, build_id, BUILD_ID_SIZE) > 0) {
                dso__set_build_id(dso, build_id);
This page took 0.038404 seconds and 5 git commands to generate.