History

objtool: Identify the different types of alternatives

Alternative code, including jump table and exception table, is represented with the same struct alternative structure. But there is no obvious way to identify whether the struct represents alternative instructions, a jump table or an exception table. So add a type to struct alternative to clearly identify the type of alternative.

Alexandre Chartre committed 11 months ago

Commit d490aa21 parent 26a453f2 files · +20 −5Browse files

Unified · Split

2 files
  1. tools/objtool/check.c +8 −5
  2. tools/objtool/include/objtool/check.h +12 −0
tools/objtool/check.c+8−5
@@ -27,11 +27,6 @@ · 26 unmodified lines
27#include <linux/static_call_types.h>27#include <linux/static_call_types.h>
28#include <linux/string.h>28#include <linux/string.h>
29 29
30struct alternative {
31 struct alternative *next;
32 struct instruction *insn;
33};
34
35static unsigned long nr_cfi, nr_cfi_reused, nr_cfi_cache;30static unsigned long nr_cfi, nr_cfi_reused, nr_cfi_cache;
36 31
37static struct cfi_init_state initial_func_cfi;32static struct cfi_init_state initial_func_cfi;
@@ -1924,6 +1919,7 @@ static int add_special_section_alts(struct objtool_file *file) · 1886 unmodified lines
1924 struct list_head special_alts;1919 struct list_head special_alts;
1925 struct instruction *orig_insn, *new_insn;1920 struct instruction *orig_insn, *new_insn;
1926 struct special_alt *special_alt, *tmp;1921 struct special_alt *special_alt, *tmp;
1922 enum alternative_type alt_type;
1927 struct alternative *alt;1923 struct alternative *alt;
1928 1924
1929 if (special_get_alts(file->elf, &special_alts))1925 if (special_get_alts(file->elf, &special_alts))
@@ -1959,9 +1955,15 @@ static int add_special_section_alts(struct objtool_file *file) · 29 unmodified lines
1959 if (handle_group_alt(file, special_alt, orig_insn, &new_insn))1955 if (handle_group_alt(file, special_alt, orig_insn, &new_insn))
1960 return -1;1956 return -1;
1961 1957
1958 alt_type = ALT_TYPE_INSTRUCTIONS;
1959
1962 } else if (special_alt->jump_or_nop) {1960 } else if (special_alt->jump_or_nop) {
1963 if (handle_jump_alt(file, special_alt, orig_insn, &new_insn))1961 if (handle_jump_alt(file, special_alt, orig_insn, &new_insn))
1964 return -1;1962 return -1;
1963
1964 alt_type = ALT_TYPE_JUMP_TABLE;
1965 } else {
1966 alt_type = ALT_TYPE_EX_TABLE;
1965 }1967 }
1966 1968
1967 alt = calloc(1, sizeof(*alt));1969 alt = calloc(1, sizeof(*alt));
@@ -1972,6 +1974,7 @@ static int add_special_section_alts(struct objtool_file *file) · 4 unmodified lines
1972 1974
1973 alt->insn = new_insn;1975 alt->insn = new_insn;
1974 alt->next = orig_insn->alts;1976 alt->next = orig_insn->alts;
1977 alt->type = alt_type;
1975 orig_insn->alts = alt;1978 orig_insn->alts = alt;
1976 1979
1977 list_del(&special_alt->list);1980 list_del(&special_alt->list);
tools/objtool/include/objtool/check.h+12−0
@@ -38,6 +38,18 @@ struct alt_group { · 37 unmodified lines
38 bool ignore;38 bool ignore;
39};39};
40 40
41enum alternative_type {
42 ALT_TYPE_INSTRUCTIONS,
43 ALT_TYPE_JUMP_TABLE,
44 ALT_TYPE_EX_TABLE,
45};
46
47struct alternative {
48 struct alternative *next;
49 struct instruction *insn;
50 enum alternative_type type;
51};
52
41#define INSN_CHUNK_BITS 853#define INSN_CHUNK_BITS 8
42#define INSN_CHUNK_SIZE (1 << INSN_CHUNK_BITS)54#define INSN_CHUNK_SIZE (1 << INSN_CHUNK_BITS)
43#define INSN_CHUNK_MAX (INSN_CHUNK_SIZE - 1)55#define INSN_CHUNK_MAX (INSN_CHUNK_SIZE - 1)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t