1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef _WARN_H
19#define _WARN_H
20
21extern const char *objname;
22
23static inline char *offstr(struct section *sec, unsigned long offset)
24{
25 struct symbol *func;
26 char *name, *str;
27 unsigned long name_off;
28
29 func = find_containing_func(sec, offset);
30 if (func) {
31 name = func->name;
32 name_off = offset - func->offset;
33 } else {
34 name = sec->name;
35 name_off = offset;
36 }
37
38 str = malloc(strlen(name) + 20);
39
40 if (func)
41 sprintf(str, "%s()+0x%lx", name, name_off);
42 else
43 sprintf(str, "%s+0x%lx", name, name_off);
44
45 return str;
46}
47
48#define WARN(format, ...) \
49 fprintf(stderr, \
50 "%s: warning: objtool: " format "\n", \
51 objname, ##__VA_ARGS__)
52
53#define WARN_FUNC(format, sec, offset, ...) \
54({ \
55 char *_str = offstr(sec, offset); \
56 WARN("%s: " format, _str, ##__VA_ARGS__); \
57 free(_str); \
58})
59
60#endif
61