treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / objtool / warn.h
blobcbb0a02b7480d5831301d01bf6fd99c84cc98c71
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
4 */
6 #ifndef _WARN_H
7 #define _WARN_H
9 #include <stdlib.h>
10 #include <string.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include "elf.h"
16 extern const char *objname;
18 static inline char *offstr(struct section *sec, unsigned long offset)
20 struct symbol *func;
21 char *name, *str;
22 unsigned long name_off;
24 func = find_containing_func(sec, offset);
25 if (func) {
26 name = func->name;
27 name_off = offset - func->offset;
28 } else {
29 name = sec->name;
30 name_off = offset;
33 str = malloc(strlen(name) + 20);
35 if (func)
36 sprintf(str, "%s()+0x%lx", name, name_off);
37 else
38 sprintf(str, "%s+0x%lx", name, name_off);
40 return str;
43 #define WARN(format, ...) \
44 fprintf(stderr, \
45 "%s: warning: objtool: " format "\n", \
46 objname, ##__VA_ARGS__)
48 #define WARN_FUNC(format, sec, offset, ...) \
49 ({ \
50 char *_str = offstr(sec, offset); \
51 WARN("%s: " format, _str, ##__VA_ARGS__); \
52 free(_str); \
55 #define BT_FUNC(format, insn, ...) \
56 ({ \
57 struct instruction *_insn = (insn); \
58 char *_str = offstr(_insn->sec, _insn->offset); \
59 WARN(" %s: " format, _str, ##__VA_ARGS__); \
60 free(_str); \
63 #define WARN_ELF(format, ...) \
64 WARN(format ": %s", ##__VA_ARGS__, elf_errmsg(-1))
66 #endif /* _WARN_H */