perf tools: Pass build id object to sysfs__read_build_id()
[linux-2.6-microblaze.git] / tools / perf / util / symbol-elf.c
index 94a156d..97a55f1 100644 (file)
@@ -534,8 +534,9 @@ out:
 
 #ifdef HAVE_LIBBFD_BUILDID_SUPPORT
 
-int filename__read_build_id(const char *filename, void *bf, size_t size)
+int filename__read_build_id(const char *filename, struct build_id *bid)
 {
+       size_t size = sizeof(bid->data);
        int err = -1;
        bfd *abfd;
 
@@ -551,9 +552,9 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
        if (!abfd->build_id || abfd->build_id->size > size)
                goto out_close;
 
-       memcpy(bf, abfd->build_id->data, abfd->build_id->size);
-       memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size);
-       err = abfd->build_id->size;
+       memcpy(bid->data, abfd->build_id->data, abfd->build_id->size);
+       memset(bid->data + abfd->build_id->size, 0, size - abfd->build_id->size);
+       err = bid->size = abfd->build_id->size;
 
 out_close:
        bfd_close(abfd);
@@ -562,8 +563,9 @@ out_close:
 
 #else // HAVE_LIBBFD_BUILDID_SUPPORT
 
-int filename__read_build_id(const char *filename, void *bf, size_t size)
+int filename__read_build_id(const char *filename, struct build_id *bid)
 {
+       size_t size = sizeof(bid->data);
        int fd, err = -1;
        Elf *elf;
 
@@ -580,7 +582,9 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
                goto out_close;
        }
 
-       err = elf_read_build_id(elf, bf, size);
+       err = elf_read_build_id(elf, bid->data, size);
+       if (err > 0)
+               bid->size = err;
 
        elf_end(elf);
 out_close:
@@ -591,13 +595,11 @@ out:
 
 #endif // HAVE_LIBBFD_BUILDID_SUPPORT
 
-int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
+int sysfs__read_build_id(const char *filename, struct build_id *bid)
 {
+       size_t size = sizeof(bid->data);
        int fd, err = -1;
 
-       if (size < BUILD_ID_SIZE)
-               goto out;
-
        fd = open(filename, O_RDONLY);
        if (fd < 0)
                goto out;
@@ -618,8 +620,9 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
                                break;
                        if (memcmp(bf, "GNU", sizeof("GNU")) == 0) {
                                size_t sz = min(descsz, size);
-                               if (read(fd, build_id, sz) == (ssize_t)sz) {
-                                       memset(build_id + sz, 0, size - sz);
+                               if (read(fd, bid->data, sz) == (ssize_t)sz) {
+                                       memset(bid->data + sz, 0, size - sz);
+                                       bid->size = sz;
                                        err = 0;
                                        break;
                                }