| .. | .. |
|---|
| 1 | | -// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | +#include "dso.h" |
|---|
| 2 | 2 | #include "symbol.h" |
|---|
| 3 | | -#include "util.h" |
|---|
| 3 | +#include "symsrc.h" |
|---|
| 4 | 4 | |
|---|
| 5 | 5 | #include <errno.h> |
|---|
| 6 | +#include <unistd.h> |
|---|
| 6 | 7 | #include <stdio.h> |
|---|
| 7 | 8 | #include <fcntl.h> |
|---|
| 8 | 9 | #include <string.h> |
|---|
| 10 | +#include <stdlib.h> |
|---|
| 9 | 11 | #include <byteswap.h> |
|---|
| 10 | 12 | #include <sys/stat.h> |
|---|
| 11 | | - |
|---|
| 13 | +#include <linux/zalloc.h> |
|---|
| 14 | +#include <internal/lib.h> |
|---|
| 12 | 15 | |
|---|
| 13 | 16 | static bool check_need_swap(int file_endian) |
|---|
| 14 | 17 | { |
|---|
| .. | .. |
|---|
| 28 | 31 | |
|---|
| 29 | 32 | #define NT_GNU_BUILD_ID 3 |
|---|
| 30 | 33 | |
|---|
| 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) |
|---|
| 33 | 36 | { |
|---|
| 37 | + size_t size = sizeof(bid->data); |
|---|
| 34 | 38 | struct { |
|---|
| 35 | 39 | u32 n_namesz; |
|---|
| 36 | 40 | u32 n_descsz; |
|---|
| .. | .. |
|---|
| 60 | 64 | nhdr->n_namesz == sizeof("GNU")) { |
|---|
| 61 | 65 | if (memcmp(name, "GNU", sizeof("GNU")) == 0) { |
|---|
| 62 | 66 | 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; |
|---|
| 65 | 70 | return 0; |
|---|
| 66 | 71 | } |
|---|
| 67 | 72 | } |
|---|
| .. | .. |
|---|
| 81 | 86 | /* |
|---|
| 82 | 87 | * Just try PT_NOTE header otherwise fails |
|---|
| 83 | 88 | */ |
|---|
| 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) |
|---|
| 85 | 90 | { |
|---|
| 86 | 91 | FILE *fp; |
|---|
| 87 | 92 | int ret = -1; |
|---|
| .. | .. |
|---|
| 153 | 158 | if (fread(buf, buf_size, 1, fp) != 1) |
|---|
| 154 | 159 | goto out_free; |
|---|
| 155 | 160 | |
|---|
| 156 | | - ret = read_build_id(buf, buf_size, bf, size, need_swap); |
|---|
| 161 | + ret = read_build_id(buf, buf_size, bid, need_swap); |
|---|
| 157 | 162 | if (ret == 0) |
|---|
| 158 | | - ret = size; |
|---|
| 163 | + ret = bid->size; |
|---|
| 159 | 164 | break; |
|---|
| 160 | 165 | } |
|---|
| 161 | 166 | } else { |
|---|
| .. | .. |
|---|
| 204 | 209 | if (fread(buf, buf_size, 1, fp) != 1) |
|---|
| 205 | 210 | goto out_free; |
|---|
| 206 | 211 | |
|---|
| 207 | | - ret = read_build_id(buf, buf_size, bf, size, need_swap); |
|---|
| 212 | + ret = read_build_id(buf, buf_size, bid, need_swap); |
|---|
| 208 | 213 | if (ret == 0) |
|---|
| 209 | | - ret = size; |
|---|
| 214 | + ret = bid->size; |
|---|
| 210 | 215 | break; |
|---|
| 211 | 216 | } |
|---|
| 212 | 217 | } |
|---|
| .. | .. |
|---|
| 217 | 222 | return ret; |
|---|
| 218 | 223 | } |
|---|
| 219 | 224 | |
|---|
| 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) |
|---|
| 221 | 226 | { |
|---|
| 222 | 227 | int fd; |
|---|
| 223 | 228 | int ret = -1; |
|---|
| .. | .. |
|---|
| 240 | 245 | if (read(fd, buf, buf_size) != (ssize_t) buf_size) |
|---|
| 241 | 246 | goto out_free; |
|---|
| 242 | 247 | |
|---|
| 243 | | - ret = read_build_id(buf, buf_size, build_id, size, false); |
|---|
| 248 | + ret = read_build_id(buf, buf_size, bid, false); |
|---|
| 244 | 249 | out_free: |
|---|
| 245 | 250 | free(buf); |
|---|
| 246 | 251 | out: |
|---|
| .. | .. |
|---|
| 336 | 341 | struct symsrc *runtime_ss __maybe_unused, |
|---|
| 337 | 342 | int kmodule __maybe_unused) |
|---|
| 338 | 343 | { |
|---|
| 339 | | - unsigned char build_id[BUILD_ID_SIZE]; |
|---|
| 344 | + struct build_id bid; |
|---|
| 340 | 345 | int ret; |
|---|
| 341 | 346 | |
|---|
| 342 | 347 | ret = fd__is_64_bit(ss->fd); |
|---|
| 343 | 348 | if (ret >= 0) |
|---|
| 344 | 349 | dso->is_64_bit = ret; |
|---|
| 345 | 350 | |
|---|
| 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); |
|---|
| 349 | 353 | return 0; |
|---|
| 350 | 354 | } |
|---|
| 351 | 355 | |
|---|