1 // SPDX-License-Identifier: GPL-2.0
2 #include "symbol/kallsyms.h"
6 u8 kallsyms2elf_type(char type)
9 return (type == 't' || type == 'w') ? STT_FUNC : STT_OBJECT;
12 bool kallsyms__is_function(char symbol_type)
14 symbol_type = toupper(symbol_type);
15 return symbol_type == 'T' || symbol_type == 'W';
19 * While we find nice hex chars, build a long_val.
20 * Return number of chars processed.
22 int hex2u64(const char *ptr, u64 *long_val)
26 *long_val = strtoull(ptr, &p, 16);
31 int kallsyms__parse(const char *filename, void *arg,
32 int (*process_symbol)(void *arg, const char *name,
33 char type, u64 start))
38 FILE *file = fopen(filename, "r");
51 line_len = getline(&line, &n, file);
52 if (line_len < 0 || !line)
55 line[--line_len] = '\0'; /* \n */
57 len = hex2u64(line, &start);
59 /* Skip the line if we failed to parse the address. */
64 if (len + 2 >= line_len)
67 symbol_type = line[len];
69 symbol_name = line + len;
72 if (len >= KSYM_NAME_LEN) {
77 err = process_symbol(arg, symbol_name, symbol_type, start);