hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/tools/perf/util/symbol-minimal.c
....@@ -1,14 +1,17 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+#include "dso.h"
22 #include "symbol.h"
3
-#include "util.h"
3
+#include "symsrc.h"
44
55 #include <errno.h>
6
+#include <unistd.h>
67 #include <stdio.h>
78 #include <fcntl.h>
89 #include <string.h>
10
+#include <stdlib.h>
911 #include <byteswap.h>
1012 #include <sys/stat.h>
11
-
13
+#include <linux/zalloc.h>
14
+#include <internal/lib.h>
1215
1316 static bool check_need_swap(int file_endian)
1417 {
....@@ -28,9 +31,10 @@
2831
2932 #define NT_GNU_BUILD_ID 3
3033
31
-static int read_build_id(void *note_data, size_t note_len, void *bf,
32
- size_t size, bool need_swap)
34
+static int read_build_id(void *note_data, size_t note_len, struct build_id *bid,
35
+ bool need_swap)
3336 {
37
+ size_t size = sizeof(bid->data);
3438 struct {
3539 u32 n_namesz;
3640 u32 n_descsz;
....@@ -60,8 +64,9 @@
6064 nhdr->n_namesz == sizeof("GNU")) {
6165 if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
6266 size_t sz = min(size, descsz);
63
- memcpy(bf, ptr, sz);
64
- memset(bf + sz, 0, size - sz);
67
+ memcpy(bid->data, ptr, sz);
68
+ memset(bid->data + sz, 0, size - sz);
69
+ bid->size = sz;
6570 return 0;
6671 }
6772 }
....@@ -81,7 +86,7 @@
8186 /*
8287 * Just try PT_NOTE header otherwise fails
8388 */
84
-int filename__read_build_id(const char *filename, void *bf, size_t size)
89
+int filename__read_build_id(const char *filename, struct build_id *bid)
8590 {
8691 FILE *fp;
8792 int ret = -1;
....@@ -153,9 +158,9 @@
153158 if (fread(buf, buf_size, 1, fp) != 1)
154159 goto out_free;
155160
156
- ret = read_build_id(buf, buf_size, bf, size, need_swap);
161
+ ret = read_build_id(buf, buf_size, bid, need_swap);
157162 if (ret == 0)
158
- ret = size;
163
+ ret = bid->size;
159164 break;
160165 }
161166 } else {
....@@ -204,9 +209,9 @@
204209 if (fread(buf, buf_size, 1, fp) != 1)
205210 goto out_free;
206211
207
- ret = read_build_id(buf, buf_size, bf, size, need_swap);
212
+ ret = read_build_id(buf, buf_size, bid, need_swap);
208213 if (ret == 0)
209
- ret = size;
214
+ ret = bid->size;
210215 break;
211216 }
212217 }
....@@ -217,7 +222,7 @@
217222 return ret;
218223 }
219224
220
-int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
225
+int sysfs__read_build_id(const char *filename, struct build_id *bid)
221226 {
222227 int fd;
223228 int ret = -1;
....@@ -240,7 +245,7 @@
240245 if (read(fd, buf, buf_size) != (ssize_t) buf_size)
241246 goto out_free;
242247
243
- ret = read_build_id(buf, buf_size, build_id, size, false);
248
+ ret = read_build_id(buf, buf_size, bid, false);
244249 out_free:
245250 free(buf);
246251 out:
....@@ -336,16 +341,15 @@
336341 struct symsrc *runtime_ss __maybe_unused,
337342 int kmodule __maybe_unused)
338343 {
339
- unsigned char build_id[BUILD_ID_SIZE];
344
+ struct build_id bid;
340345 int ret;
341346
342347 ret = fd__is_64_bit(ss->fd);
343348 if (ret >= 0)
344349 dso->is_64_bit = ret;
345350
346
- if (filename__read_build_id(ss->name, build_id, BUILD_ID_SIZE) > 0) {
347
- dso__set_build_id(dso, build_id);
348
- }
351
+ if (filename__read_build_id(ss->name, &bid) > 0)
352
+ dso__set_build_id(dso, &bid);
349353 return 0;
350354 }
351355