Skip to content

Commit c6f5dc2

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
objtool: Union instruction::{call_dest,jump_table}
The instruction call_dest and jump_table members can never be used at the same time, their usage depends on type. struct instruction { struct list_head list; /* 0 16 */ struct hlist_node hash; /* 16 16 */ struct list_head call_node; /* 32 16 */ struct section * sec; /* 48 8 */ long unsigned int offset; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ long unsigned int immediate; /* 64 8 */ unsigned int len; /* 72 4 */ u8 type; /* 76 1 */ /* Bitfield combined with previous fields */ u16 dead_end:1; /* 76: 8 2 */ u16 ignore:1; /* 76: 9 2 */ u16 ignore_alts:1; /* 76:10 2 */ u16 hint:1; /* 76:11 2 */ u16 save:1; /* 76:12 2 */ u16 restore:1; /* 76:13 2 */ u16 retpoline_safe:1; /* 76:14 2 */ u16 noendbr:1; /* 76:15 2 */ u16 entry:1; /* 78: 0 2 */ u16 visited:4; /* 78: 1 2 */ u16 no_reloc:1; /* 78: 5 2 */ /* XXX 2 bits hole, try to pack */ /* Bitfield combined with next fields */ s8 instr; /* 79 1 */ struct alt_group * alt_group; /* 80 8 */ - struct symbol * call_dest; /* 88 8 */ - struct instruction * jump_dest; /* 96 8 */ - struct instruction * first_jump_src; /* 104 8 */ - struct reloc * jump_table; /* 112 8 */ - struct alternative * alts; /* 120 8 */ + struct instruction * jump_dest; /* 88 8 */ + struct instruction * first_jump_src; /* 96 8 */ + union { + struct symbol * _call_dest; /* 104 8 */ + struct reloc * _jump_table; /* 104 8 */ + }; /* 104 8 */ + struct alternative * alts; /* 112 8 */ + struct symbol * sym; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ - struct symbol * sym; /* 128 8 */ - struct stack_op * stack_ops; /* 136 8 */ - struct cfi_state * cfi; /* 144 8 */ + struct stack_op * stack_ops; /* 128 8 */ + struct cfi_state * cfi; /* 136 8 */ - /* size: 152, cachelines: 3, members: 29 */ - /* sum members: 150 */ + /* size: 144, cachelines: 3, members: 28 */ + /* sum members: 142 */ /* sum bitfield members: 14 bits, bit holes: 1, sum bit holes: 2 bits */ - /* last cacheline: 24 bytes */ + /* last cacheline: 16 bytes */ }; pre: 5:39.35 real, 215.58 user, 123.69 sys, 2344873 mem post: 5:38.18 real, 213.25 user, 124.90 sys, 23449040 mem Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Tested-by: Nathan Chancellor <[email protected]> # build only Tested-by: Thomas Weißschuh <[email protected]> # compile and run Link: https://lore.kernel.org/r/[email protected]
1 parent 0932dbe commit c6f5dc2

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

tools/objtool/check.c

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,34 @@ static struct instruction *prev_insn_same_sym(struct objtool_file *file,
114114
for (insn = next_insn_same_sec(file, insn); insn; \
115115
insn = next_insn_same_sec(file, insn))
116116

117+
static inline struct symbol *insn_call_dest(struct instruction *insn)
118+
{
119+
if (insn->type == INSN_JUMP_DYNAMIC ||
120+
insn->type == INSN_CALL_DYNAMIC)
121+
return NULL;
122+
123+
return insn->_call_dest;
124+
}
125+
126+
static inline struct reloc *insn_jump_table(struct instruction *insn)
127+
{
128+
if (insn->type == INSN_JUMP_DYNAMIC ||
129+
insn->type == INSN_CALL_DYNAMIC)
130+
return insn->_jump_table;
131+
132+
return NULL;
133+
}
134+
117135
static bool is_jump_table_jump(struct instruction *insn)
118136
{
119137
struct alt_group *alt_group = insn->alt_group;
120138

121-
if (insn->jump_table)
139+
if (insn_jump_table(insn))
122140
return true;
123141

124142
/* Retpoline alternative for a jump table? */
125143
return alt_group && alt_group->orig_group &&
126-
alt_group->orig_group->first_insn->jump_table;
144+
insn_jump_table(alt_group->orig_group->first_insn);
127145
}
128146

129147
static bool is_sibling_call(struct instruction *insn)
@@ -137,8 +155,8 @@ static bool is_sibling_call(struct instruction *insn)
137155
return !is_jump_table_jump(insn);
138156
}
139157

140-
/* add_jump_destinations() sets insn->call_dest for sibling calls. */
141-
return (is_static_jump(insn) && insn->call_dest);
158+
/* add_jump_destinations() sets insn_call_dest(insn) for sibling calls. */
159+
return (is_static_jump(insn) && insn_call_dest(insn));
142160
}
143161

144162
/*
@@ -274,8 +292,8 @@ static void init_insn_state(struct objtool_file *file, struct insn_state *state,
274292

275293
/*
276294
* We need the full vmlinux for noinstr validation, otherwise we can
277-
* not correctly determine insn->call_dest->sec (external symbols do
278-
* not have a section).
295+
* not correctly determine insn_call_dest(insn)->sec (external symbols
296+
* do not have a section).
279297
*/
280298
if (opts.link && opts.noinstr && sec)
281299
state->noinstr = sec->noinstr;
@@ -678,7 +696,7 @@ static int create_static_call_sections(struct objtool_file *file)
678696
return -1;
679697

680698
/* find key symbol */
681-
key_name = strdup(insn->call_dest->name);
699+
key_name = strdup(insn_call_dest(insn)->name);
682700
if (!key_name) {
683701
perror("strdup");
684702
return -1;
@@ -709,7 +727,7 @@ static int create_static_call_sections(struct objtool_file *file)
709727
* trampoline address. This is fixed up in
710728
* static_call_add_module().
711729
*/
712-
key_sym = insn->call_dest;
730+
key_sym = insn_call_dest(insn);
713731
}
714732
free(key_name);
715733

@@ -1340,7 +1358,7 @@ static void annotate_call_site(struct objtool_file *file,
13401358
struct instruction *insn, bool sibling)
13411359
{
13421360
struct reloc *reloc = insn_reloc(file, insn);
1343-
struct symbol *sym = insn->call_dest;
1361+
struct symbol *sym = insn_call_dest(insn);
13441362

13451363
if (!sym)
13461364
sym = reloc->sym;
@@ -1425,7 +1443,7 @@ static void annotate_call_site(struct objtool_file *file,
14251443
static void add_call_dest(struct objtool_file *file, struct instruction *insn,
14261444
struct symbol *dest, bool sibling)
14271445
{
1428-
insn->call_dest = dest;
1446+
insn->_call_dest = dest;
14291447
if (!dest)
14301448
return;
14311449

@@ -1683,12 +1701,12 @@ static int add_call_destinations(struct objtool_file *file)
16831701
if (insn->ignore)
16841702
continue;
16851703

1686-
if (!insn->call_dest) {
1704+
if (!insn_call_dest(insn)) {
16871705
WARN_FUNC("unannotated intra-function call", insn->sec, insn->offset);
16881706
return -1;
16891707
}
16901708

1691-
if (insn_func(insn) && insn->call_dest->type != STT_FUNC) {
1709+
if (insn_func(insn) && insn_call_dest(insn)->type != STT_FUNC) {
16921710
WARN_FUNC("unsupported call to non-function",
16931711
insn->sec, insn->offset);
16941712
return -1;
@@ -2125,7 +2143,7 @@ static void mark_func_jump_tables(struct objtool_file *file,
21252143
reloc = find_jump_table(file, func, insn);
21262144
if (reloc) {
21272145
reloc->jump_table_start = true;
2128-
insn->jump_table = reloc;
2146+
insn->_jump_table = reloc;
21292147
}
21302148
}
21312149
}
@@ -2137,10 +2155,10 @@ static int add_func_jump_tables(struct objtool_file *file,
21372155
int ret;
21382156

21392157
func_for_each_insn(file, func, insn) {
2140-
if (!insn->jump_table)
2158+
if (!insn_jump_table(insn))
21412159
continue;
21422160

2143-
ret = add_jump_table(file, insn, insn->jump_table);
2161+
ret = add_jump_table(file, insn, insn_jump_table(insn));
21442162
if (ret)
21452163
return ret;
21462164
}
@@ -2612,8 +2630,8 @@ static int decode_sections(struct objtool_file *file)
26122630
static bool is_fentry_call(struct instruction *insn)
26132631
{
26142632
if (insn->type == INSN_CALL &&
2615-
insn->call_dest &&
2616-
insn->call_dest->fentry)
2633+
insn_call_dest(insn) &&
2634+
insn_call_dest(insn)->fentry)
26172635
return true;
26182636

26192637
return false;
@@ -3320,8 +3338,8 @@ static inline const char *call_dest_name(struct instruction *insn)
33203338
struct reloc *rel;
33213339
int idx;
33223340

3323-
if (insn->call_dest)
3324-
return insn->call_dest->name;
3341+
if (insn_call_dest(insn))
3342+
return insn_call_dest(insn)->name;
33253343

33263344
rel = insn_reloc(NULL, insn);
33273345
if (rel && !strcmp(rel->sym->name, "pv_ops")) {
@@ -3403,13 +3421,13 @@ static int validate_call(struct objtool_file *file,
34033421
struct insn_state *state)
34043422
{
34053423
if (state->noinstr && state->instr <= 0 &&
3406-
!noinstr_call_dest(file, insn, insn->call_dest)) {
3424+
!noinstr_call_dest(file, insn, insn_call_dest(insn))) {
34073425
WARN_FUNC("call to %s() leaves .noinstr.text section",
34083426
insn->sec, insn->offset, call_dest_name(insn));
34093427
return 1;
34103428
}
34113429

3412-
if (state->uaccess && !func_uaccess_safe(insn->call_dest)) {
3430+
if (state->uaccess && !func_uaccess_safe(insn_call_dest(insn))) {
34133431
WARN_FUNC("call to %s() with UACCESS enabled",
34143432
insn->sec, insn->offset, call_dest_name(insn));
34153433
return 1;
@@ -3847,11 +3865,11 @@ static int validate_entry(struct objtool_file *file, struct instruction *insn)
38473865

38483866
/* fallthrough */
38493867
case INSN_CALL:
3850-
dest = find_insn(file, insn->call_dest->sec,
3851-
insn->call_dest->offset);
3868+
dest = find_insn(file, insn_call_dest(insn)->sec,
3869+
insn_call_dest(insn)->offset);
38523870
if (!dest) {
38533871
WARN("Unresolved function after linking!?: %s",
3854-
insn->call_dest->name);
3872+
insn_call_dest(insn)->name);
38553873
return -1;
38563874
}
38573875

@@ -3952,13 +3970,13 @@ static int validate_retpoline(struct objtool_file *file)
39523970
static bool is_kasan_insn(struct instruction *insn)
39533971
{
39543972
return (insn->type == INSN_CALL &&
3955-
!strcmp(insn->call_dest->name, "__asan_handle_no_return"));
3973+
!strcmp(insn_call_dest(insn)->name, "__asan_handle_no_return"));
39563974
}
39573975

39583976
static bool is_ubsan_insn(struct instruction *insn)
39593977
{
39603978
return (insn->type == INSN_CALL &&
3961-
!strcmp(insn->call_dest->name,
3979+
!strcmp(insn_call_dest(insn)->name,
39623980
"__ubsan_handle_builtin_unreachable"));
39633981
}
39643982

@@ -4036,7 +4054,8 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio
40364054
* It may also insert a UD2 after calling a __noreturn function.
40374055
*/
40384056
prev_insn = list_prev_entry(insn, list);
4039-
if ((prev_insn->dead_end || dead_end_function(file, prev_insn->call_dest)) &&
4057+
if ((prev_insn->dead_end ||
4058+
dead_end_function(file, insn_call_dest(prev_insn))) &&
40404059
(insn->type == INSN_BUG ||
40414060
(insn->type == INSN_JUMP_UNCONDITIONAL &&
40424061
insn->jump_dest && insn->jump_dest->type == INSN_BUG)))

tools/objtool/include/objtool/check.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ struct instruction {
6262
s8 instr;
6363

6464
struct alt_group *alt_group;
65-
struct symbol *call_dest;
6665
struct instruction *jump_dest;
6766
struct instruction *first_jump_src;
68-
struct reloc *jump_table;
67+
union {
68+
struct symbol *_call_dest;
69+
struct reloc *_jump_table;
70+
};
6971
struct alternative *alts;
7072
struct symbol *sym;
7173
struct stack_op *stack_ops;

0 commit comments

Comments
 (0)