summaryrefslogtreecommitdiff
path: root/tools/objtool
diff options
context:
space:
mode:
Diffstat (limited to 'tools/objtool')
-rw-r--r--tools/objtool/Makefile2
-rw-r--r--tools/objtool/arch/x86/decode.c8
-rw-r--r--tools/objtool/check.c85
-rw-r--r--tools/objtool/disas.c14
-rw-r--r--tools/objtool/elf.c13
-rw-r--r--tools/objtool/include/objtool/check.h1
-rw-r--r--tools/objtool/include/objtool/klp.h10
-rw-r--r--tools/objtool/klp-diff.c55
8 files changed, 137 insertions, 51 deletions
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index a40f30232929..6964175abdfd 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -29,6 +29,8 @@ srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
endif
+RM ?= rm -f
+
LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
ifneq ($(OUTPUT),)
LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index f4af82508228..73bfea220d1b 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -711,10 +711,14 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
immr = find_reloc_by_dest(elf, (void *)sec, offset+3);
disp = find_reloc_by_dest(elf, (void *)sec, offset+7);
- if (!immr || strcmp(immr->sym->name, "pv_ops"))
+ if (!immr || strncmp(immr->sym->name, "pv_ops", 6))
break;
- idx = (reloc_addend(immr) + 8) / sizeof(void *);
+ idx = pv_ops_idx_off(immr->sym->name);
+ if (idx < 0)
+ break;
+
+ idx += (reloc_addend(immr) + 8) / sizeof(void *);
func = disp->sym;
if (disp->sym->type == STT_SECTION)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 3f7999317f4d..37f87c4a0134 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -197,7 +197,8 @@ static bool is_rust_noreturn(const struct symbol *func)
* as well as changes to the source code itself between versions (since
* these come from the Rust standard library).
*/
- return str_ends_with(func->name, "_4core5sliceSp15copy_from_slice17len_mismatch_fail") ||
+ return str_ends_with(func->name, "_4core3num22from_ascii_radix_panic") ||
+ str_ends_with(func->name, "_4core5sliceSp15copy_from_slice17len_mismatch_fail") ||
str_ends_with(func->name, "_4core6option13expect_failed") ||
str_ends_with(func->name, "_4core6option13unwrap_failed") ||
str_ends_with(func->name, "_4core6result13unwrap_failed") ||
@@ -520,21 +521,58 @@ static int decode_instructions(struct objtool_file *file)
}
/*
- * Read the pv_ops[] .data table to find the static initialized values.
+ * Known pv_ops*[] arrays.
*/
-static int add_pv_ops(struct objtool_file *file, const char *symname)
+static struct {
+ const char *name;
+ int idx_off;
+} pv_ops_tables[] = {
+ { .name = "pv_ops", },
+ { .name = "pv_ops_lock", },
+ { .name = NULL, .idx_off = -1 }
+};
+
+/*
+ * Get index offset for a pv_ops* array.
+ */
+int pv_ops_idx_off(const char *symname)
+{
+ int idx;
+
+ for (idx = 0; pv_ops_tables[idx].name; idx++) {
+ if (!strcmp(symname, pv_ops_tables[idx].name))
+ break;
+ }
+
+ return pv_ops_tables[idx].idx_off;
+}
+
+/*
+ * Read a pv_ops*[] .data table to find the static initialized values.
+ */
+static int add_pv_ops(struct objtool_file *file, int pv_ops_idx)
{
struct symbol *sym, *func;
unsigned long off, end;
struct reloc *reloc;
- int idx;
+ int idx, idx_off;
+ const char *symname;
+ symname = pv_ops_tables[pv_ops_idx].name;
sym = find_symbol_by_name(file->elf, symname);
- if (!sym)
- return 0;
+ if (!sym) {
+ ERROR("Unknown pv_ops array %s", symname);
+ return -1;
+ }
off = sym->offset;
end = off + sym->len;
+ idx_off = pv_ops_tables[pv_ops_idx].idx_off;
+ if (idx_off < 0) {
+ ERROR("pv_ops array %s has unknown index offset", symname);
+ return -1;
+ }
+
for (;;) {
reloc = find_reloc_by_dest_range(file->elf, sym->sec, off, end - off);
if (!reloc)
@@ -552,7 +590,7 @@ static int add_pv_ops(struct objtool_file *file, const char *symname)
return -1;
}
- if (objtool_pv_add(file, idx, func))
+ if (objtool_pv_add(file, idx + idx_off, func))
return -1;
off = reloc_offset(reloc) + 1;
@@ -568,14 +606,6 @@ static int add_pv_ops(struct objtool_file *file, const char *symname)
*/
static int init_pv_ops(struct objtool_file *file)
{
- static const char *pv_ops_tables[] = {
- "pv_ops",
- "xen_cpu_ops",
- "xen_irq_ops",
- "xen_mmu_ops",
- NULL,
- };
- const char *pv_ops;
struct symbol *sym;
int idx, nr;
@@ -584,11 +614,20 @@ static int init_pv_ops(struct objtool_file *file)
file->pv_ops = NULL;
- sym = find_symbol_by_name(file->elf, "pv_ops");
- if (!sym)
+ nr = 0;
+ for (idx = 0; pv_ops_tables[idx].name; idx++) {
+ sym = find_symbol_by_name(file->elf, pv_ops_tables[idx].name);
+ if (!sym) {
+ pv_ops_tables[idx].idx_off = -1;
+ continue;
+ }
+ pv_ops_tables[idx].idx_off = nr;
+ nr += sym->len / sizeof(unsigned long);
+ }
+
+ if (nr == 0)
return 0;
- nr = sym->len / sizeof(unsigned long);
file->pv_ops = calloc(nr, sizeof(struct pv_state));
if (!file->pv_ops) {
ERROR_GLIBC("calloc");
@@ -598,8 +637,10 @@ static int init_pv_ops(struct objtool_file *file)
for (idx = 0; idx < nr; idx++)
INIT_LIST_HEAD(&file->pv_ops[idx].targets);
- for (idx = 0; (pv_ops = pv_ops_tables[idx]); idx++) {
- if (add_pv_ops(file, pv_ops))
+ for (idx = 0; pv_ops_tables[idx].name; idx++) {
+ if (pv_ops_tables[idx].idx_off < 0)
+ continue;
+ if (add_pv_ops(file, idx))
return -1;
}
@@ -682,7 +723,7 @@ static int create_static_call_sections(struct objtool_file *file)
key_sym = find_symbol_by_name(file->elf, tmp);
if (!key_sym) {
- if (!opts.module || file->klp) {
+ if (!opts.module) {
ERROR("static_call: can't find static_call_key symbol: %s", tmp);
return -1;
}
@@ -4761,7 +4802,7 @@ static int validate_ibt(struct objtool_file *file)
!strcmp(sec->name, "__bug_table") ||
!strcmp(sec->name, "__ex_table") ||
!strcmp(sec->name, "__jump_table") ||
- !strcmp(sec->name, "__klp_funcs") ||
+ !strcmp(sec->name, ".init.klp_funcs") ||
!strcmp(sec->name, "__mcount_loc") ||
!strcmp(sec->name, ".llvm.call-graph-profile") ||
!strcmp(sec->name, ".llvm_bb_addr_map") ||
diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c
index 2b5059f55e40..26f08d41f2b1 100644
--- a/tools/objtool/disas.c
+++ b/tools/objtool/disas.c
@@ -108,6 +108,8 @@ static int sprint_name(char *str, const char *name, unsigned long offset)
#define DINFO_FPRINTF(dinfo, ...) \
((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__))
+#define bfd_vma_fmt \
+ __builtin_choose_expr(sizeof(bfd_vma) == sizeof(unsigned long), "%#lx <%s>", "%#llx <%s>")
static int disas_result_fprintf(struct disas_context *dctx,
const char *fmt, va_list ap)
@@ -170,10 +172,10 @@ static void disas_print_addr_sym(struct section *sec, struct symbol *sym,
if (sym) {
sprint_name(symstr, sym->name, addr - sym->offset);
- DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
+ DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
} else {
str = offstr(sec, addr);
- DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
+ DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
free(str);
}
}
@@ -252,7 +254,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
* example: "lea 0x0(%rip),%rdi". The kernel can reference
* the next IP with _THIS_IP_ macro.
*/
- DINFO_FPRINTF(dinfo, "0x%lx <_THIS_IP_>", addr);
+ DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, "_THIS_IP_");
return;
}
@@ -264,11 +266,11 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
*/
if (reloc->sym->type == STT_SECTION) {
str = offstr(reloc->sym->sec, reloc->sym->offset + offset);
- DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
+ DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
free(str);
} else {
sprint_name(symstr, reloc->sym->name, offset);
- DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
+ DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
}
}
@@ -311,7 +313,7 @@ static void disas_print_address(bfd_vma addr, struct disassemble_info *dinfo)
*/
sym = insn_call_dest(insn);
if (sym && (sym->offset == addr || (sym->offset == 0 && is_reloc))) {
- DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, sym->name);
+ DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, sym->name);
return;
}
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6a8ed9c62323..2c02c7b49265 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -18,15 +18,14 @@
#include <errno.h>
#include <libgen.h>
#include <ctype.h>
+#include <linux/align.h>
+#include <linux/kernel.h>
#include <linux/interval_tree_generic.h>
+#include <linux/log2.h>
#include <objtool/builtin.h>
#include <objtool/elf.h>
#include <objtool/warn.h>
-#define ALIGN_UP(x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1))
-#define ALIGN_UP_POW2(x) (1U << ((8 * sizeof(x)) - __builtin_clz((x) - 1U)))
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-
static inline u32 str_hash(const char *str)
{
return jhash(str, strlen(str), 0);
@@ -1336,7 +1335,7 @@ unsigned int elf_add_string(struct elf *elf, struct section *strtab, const char
return -1;
}
- offset = ALIGN_UP(strtab->sh.sh_size, strtab->sh.sh_addralign);
+ offset = ALIGN(strtab->sh.sh_size, strtab->sh.sh_addralign);
if (!elf_add_data(elf, strtab, str, strlen(str) + 1))
return -1;
@@ -1378,7 +1377,7 @@ void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_
sec->data->d_size = size;
sec->data->d_align = 1;
- offset = ALIGN_UP(sec->sh.sh_size, sec->sh.sh_addralign);
+ offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign);
sec->sh.sh_size = offset + size;
mark_sec_changed(elf, sec, true);
@@ -1502,7 +1501,7 @@ static int elf_alloc_reloc(struct elf *elf, struct section *rsec)
rsec->data->d_size = nr_relocs_new * elf_rela_size(elf);
rsec->sh.sh_size = rsec->data->d_size;
- nr_alloc = MAX(64, ALIGN_UP_POW2(nr_relocs_new));
+ nr_alloc = max(64UL, roundup_pow_of_two(nr_relocs_new));
if (nr_alloc <= rsec->nr_alloc_relocs)
return 0;
diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/objtool/check.h
index 2e1346ad5e92..5f2f77bd9b41 100644
--- a/tools/objtool/include/objtool/check.h
+++ b/tools/objtool/include/objtool/check.h
@@ -159,5 +159,6 @@ const char *objtool_disas_insn(struct instruction *insn);
extern size_t sym_name_max_len;
extern struct disas_context *objtool_disas_ctx;
+int pv_ops_idx_off(const char *symname);
#endif /* _CHECK_H */
diff --git a/tools/objtool/include/objtool/klp.h b/tools/objtool/include/objtool/klp.h
index ad830a7ce55b..e32e5e8bc631 100644
--- a/tools/objtool/include/objtool/klp.h
+++ b/tools/objtool/include/objtool/klp.h
@@ -6,12 +6,12 @@
#define SHN_LIVEPATCH 0xff20
/*
- * __klp_objects and __klp_funcs are created by klp diff and used by the patch
- * module init code to build the klp_patch, klp_object and klp_func structs
- * needed by the livepatch API.
+ * .init.klp_objects and .init.klp_funcs are created by klp diff and used by the
+ * patch module init code to build the klp_patch, klp_object and klp_func
+ * structs needed by the livepatch API.
*/
-#define KLP_OBJECTS_SEC "__klp_objects"
-#define KLP_FUNCS_SEC "__klp_funcs"
+#define KLP_OBJECTS_SEC ".init.klp_objects"
+#define KLP_FUNCS_SEC ".init.klp_funcs"
/*
* __klp_relocs is an intermediate section which are created by klp diff and
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 4d1f9e9977eb..9f1f4011eb9c 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -364,11 +364,40 @@ static int correlate_symbols(struct elfs *e)
struct symbol *file1_sym, *file2_sym;
struct symbol *sym1, *sym2;
- /* Correlate locals */
- for (file1_sym = first_file_symbol(e->orig),
- file2_sym = first_file_symbol(e->patched); ;
- file1_sym = next_file_symbol(e->orig, file1_sym),
- file2_sym = next_file_symbol(e->patched, file2_sym)) {
+ file1_sym = first_file_symbol(e->orig);
+ file2_sym = first_file_symbol(e->patched);
+
+ /*
+ * Correlate any locals before the first FILE symbol. This has been
+ * seen when LTO inexplicably strips the initramfs_data.o FILE symbol
+ * due to the file only containing data and no code.
+ */
+ for_each_sym(e->orig, sym1) {
+ if (sym1 == file1_sym || !is_local_sym(sym1))
+ break;
+
+ if (dont_correlate(sym1))
+ continue;
+
+ for_each_sym(e->patched, sym2) {
+ if (sym2 == file2_sym || !is_local_sym(sym2))
+ break;
+
+ if (sym2->twin || dont_correlate(sym2))
+ continue;
+
+ if (strcmp(sym1->demangled_name, sym2->demangled_name))
+ continue;
+
+ sym1->twin = sym2;
+ sym2->twin = sym1;
+ break;
+ }
+ }
+
+ /* Correlate locals after the first FILE symbol */
+ for (; ; file1_sym = next_file_symbol(e->orig, file1_sym),
+ file2_sym = next_file_symbol(e->patched, file2_sym)) {
if (!file1_sym && file2_sym) {
ERROR("FILE symbol mismatch: NULL != %s", file2_sym->name);
@@ -1425,9 +1454,6 @@ static int clone_special_sections(struct elfs *e)
{
struct section *patched_sec;
- if (create_fake_symbols(e->patched))
- return -1;
-
for_each_sec(e->patched, patched_sec) {
if (is_special_section(patched_sec)) {
if (clone_special_section(e, patched_sec))
@@ -1439,7 +1465,7 @@ static int clone_special_sections(struct elfs *e)
}
/*
- * Create __klp_objects and __klp_funcs sections which are intermediate
+ * Create .init.klp_objects and .init.klp_funcs sections which are intermediate
* sections provided as input to the patch module's init code for building the
* klp_patch, klp_object and klp_func structs for the livepatch API.
*/
@@ -1704,6 +1730,17 @@ int cmd_klp_diff(int argc, const char **argv)
if (!e.out)
return -1;
+ /*
+ * Special section fake symbols are needed so that individual special
+ * section entries can be extracted by clone_special_sections().
+ *
+ * Note the fake symbols are also needed by clone_included_functions()
+ * because __WARN_printf() call sites add references to bug table
+ * entries in the calling functions.
+ */
+ if (create_fake_symbols(e.patched))
+ return -1;
+
if (clone_included_functions(&e))
return -1;