Skip to content

Commit f398238

Browse files
captain5050namhyung
authored andcommitted
perf build-id: Reduce size of "size" variable
Later clean up of the dso_id to include a build_id will suffer from alignment and size issues. The size can only hold up to a value of BUILD_ID_SIZE (20) and the mmap2 event uses a byte for the value. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent fcc7cc3 commit f398238

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

tools/perf/util/build-id.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
struct build_id {
1515
u8 data[BUILD_ID_SIZE];
16-
size_t size;
16+
u8 size;
1717
};
1818

1919
struct dso;

tools/perf/util/synthetic-events.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,9 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool,
22482248

22492249
memset(&ev, 0, len);
22502250

2251-
ev.build_id.size = min(bid->size, sizeof(ev.build_id.build_id));
2251+
ev.build_id.size = bid->size;
2252+
if (ev.build_id.size > sizeof(ev.build_id.build_id))
2253+
ev.build_id.size = sizeof(ev.build_id.build_id);
22522254
memcpy(ev.build_id.build_id, bid->data, ev.build_id.size);
22532255
ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
22542256
ev.build_id.header.misc = misc | PERF_RECORD_MISC_BUILD_ID_SIZE;
@@ -2308,7 +2310,9 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool,
23082310
ev.mmap2.len = len;
23092311
ev.mmap2.pgoff = pgoff;
23102312

2311-
ev.mmap2.build_id_size = min(bid->size, sizeof(ev.mmap2.build_id));
2313+
ev.mmap2.build_id_size = bid->size;
2314+
if (ev.mmap2.build_id_size > sizeof(ev.mmap2.build_id))
2315+
ev.build_id.size = sizeof(ev.mmap2.build_id);
23122316
memcpy(ev.mmap2.build_id, bid->data, ev.mmap2.build_id_size);
23132317

23142318
ev.mmap2.prot = prot;

0 commit comments

Comments
 (0)