xref: /linux/scripts/kallsyms.h (revision 5d7f3375cd574fc83f0cd30839b21455c0e79ae2)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef KALLSYMS_H
3 #define KALLSYMS_H
4 
5 #include <stdbool.h>
6 #include <stddef.h>
7 #include <stdio.h>
8 #include <string.h>
9 
10 #include <array_size.h>
11 #include "elf-parse.h"
12 
13 static inline bool string_starts_with(const char *s, const char *prefix)
14 {
15 	return strncmp(s, prefix, strlen(prefix)) == 0;
16 }
17 
18 static inline bool string_ends_with(const char *s, const char *suffix)
19 {
20 	size_t len = strlen(s), suffix_len = strlen(suffix);
21 
22 	return len >= suffix_len && strcmp(s + len - suffix_len, suffix) == 0;
23 }
24 
25 /* A symbol as nm lists it. */
26 struct sysmap_symbol {
27 	unsigned long long addr;
28 	const char *name;
29 	char type;
30 };
31 
32 /* The symbols of an ELF file that System.map lists, in its order. */
33 struct sysmap {
34 	struct sysmap_symbol *syms;
35 	size_t nr_syms;
36 	int addr_width;		/* hex digits of an address */
37 	struct elf_file elf;	/* the mapping the names point into */
38 };
39 
40 struct sysmap *sysmap_read(const char *path);
41 void sysmap_write(const struct sysmap *map, FILE *out);
42 void sysmap_free(struct sysmap *map);
43 
44 #endif /* KALLSYMS_H */
45