2019-05-19 15:51:43 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-02-28 22:22:41 -06:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
2021-02-26 10:59:59 +01:00
|
|
|
#include <unistd.h>
|
2016-02-28 22:22:41 -06:00
|
|
|
#include <subcmd/exec-cmd.h>
|
|
|
|
|
#include <subcmd/pager.h>
|
2017-04-17 11:58:55 -03:00
|
|
|
#include <linux/kernel.h>
|
2016-02-28 22:22:41 -06:00
|
|
|
|
2020-11-13 00:03:32 +01:00
|
|
|
#include <objtool/builtin.h>
|
|
|
|
|
#include <objtool/objtool.h>
|
|
|
|
|
#include <objtool/warn.h>
|
2016-02-28 22:22:41 -06:00
|
|
|
|
2025-09-17 09:04:00 -07:00
|
|
|
bool debug;
|
|
|
|
|
int indent;
|
|
|
|
|
|
2020-08-25 13:47:39 +01:00
|
|
|
static struct objtool_file file;
|
|
|
|
|
|
2025-03-14 12:29:07 -07:00
|
|
|
struct objtool_file *objtool_open_read(const char *filename)
|
2020-08-25 13:47:39 +01:00
|
|
|
{
|
2025-03-14 12:29:07 -07:00
|
|
|
if (file.elf) {
|
2025-03-31 21:26:41 -07:00
|
|
|
ERROR("won't handle more than one file at a time");
|
2025-03-14 12:29:07 -07:00
|
|
|
return NULL;
|
2020-08-25 13:47:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-14 12:29:07 -07:00
|
|
|
file.elf = elf_open_read(filename, O_RDWR);
|
2020-08-25 13:47:39 +01:00
|
|
|
if (!file.elf)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
hash_init(file.insn_hash);
|
2021-03-26 16:12:12 +01:00
|
|
|
INIT_LIST_HEAD(&file.retpoline_call_list);
|
2022-06-14 23:15:38 +02:00
|
|
|
INIT_LIST_HEAD(&file.return_thunk_list);
|
2020-08-25 13:47:39 +01:00
|
|
|
INIT_LIST_HEAD(&file.static_call_list);
|
2020-08-06 15:14:09 -07:00
|
|
|
INIT_LIST_HEAD(&file.mcount_loc_list);
|
2022-03-08 16:30:55 +01:00
|
|
|
INIT_LIST_HEAD(&file.endbr_list);
|
2022-09-15 13:11:09 +02:00
|
|
|
INIT_LIST_HEAD(&file.call_list);
|
2022-04-18 09:50:26 -07:00
|
|
|
file.ignore_unreachables = opts.no_unreachable;
|
2020-08-25 13:47:39 +01:00
|
|
|
file.hints = false;
|
|
|
|
|
|
|
|
|
|
return &file;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-24 14:55:59 -07:00
|
|
|
int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func)
|
2021-06-24 11:41:23 +02:00
|
|
|
{
|
2022-04-18 09:50:26 -07:00
|
|
|
if (!opts.noinstr)
|
2025-03-24 14:55:59 -07:00
|
|
|
return 0;
|
2021-06-24 11:41:23 +02:00
|
|
|
|
|
|
|
|
if (!f->pv_ops) {
|
2025-03-31 21:26:41 -07:00
|
|
|
ERROR("paravirt confusion");
|
2025-03-24 14:55:59 -07:00
|
|
|
return -1;
|
2021-06-24 11:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* These functions will be patched into native code,
|
|
|
|
|
* see paravirt_patch().
|
|
|
|
|
*/
|
|
|
|
|
if (!strcmp(func->name, "_paravirt_nop") ||
|
|
|
|
|
!strcmp(func->name, "_paravirt_ident_64"))
|
2025-03-24 14:55:59 -07:00
|
|
|
return 0;
|
2021-06-24 11:41:23 +02:00
|
|
|
|
2021-12-02 21:45:34 +01:00
|
|
|
/* already added this function */
|
|
|
|
|
if (!list_empty(&func->pv_target))
|
2025-03-24 14:55:59 -07:00
|
|
|
return 0;
|
2021-12-02 21:45:34 +01:00
|
|
|
|
2021-06-24 11:41:23 +02:00
|
|
|
list_add(&func->pv_target, &f->pv_ops[idx].targets);
|
|
|
|
|
f->pv_ops[idx].clean = false;
|
2025-03-24 14:55:59 -07:00
|
|
|
return 0;
|
2021-06-24 11:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-17 09:03:59 -07:00
|
|
|
char *top_level_dir(const char *file)
|
|
|
|
|
{
|
|
|
|
|
ssize_t len, self_len, file_len;
|
|
|
|
|
char self[PATH_MAX], *str;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
len = readlink("/proc/self/exe", self, sizeof(self) - 1);
|
|
|
|
|
if (len <= 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
self[len] = '\0';
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
char *s = strrchr(self, '/');
|
|
|
|
|
if (!s)
|
|
|
|
|
return NULL;
|
|
|
|
|
*s = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self_len = strlen(self);
|
|
|
|
|
file_len = strlen(file);
|
|
|
|
|
|
|
|
|
|
str = malloc(self_len + file_len + 2);
|
|
|
|
|
if (!str)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
memcpy(str, self, self_len);
|
|
|
|
|
str[self_len] = '/';
|
|
|
|
|
strcpy(str + self_len + 1, file);
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-28 22:22:41 -06:00
|
|
|
int main(int argc, const char **argv)
|
|
|
|
|
{
|
|
|
|
|
static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED";
|
|
|
|
|
|
2025-12-02 15:01:17 -08:00
|
|
|
if (init_signal_handler())
|
|
|
|
|
return -1;
|
|
|
|
|
|
2016-02-28 22:22:41 -06:00
|
|
|
/* libsubcmd init */
|
|
|
|
|
exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED);
|
|
|
|
|
pager_init(UNUSED);
|
|
|
|
|
|
2025-09-17 09:03:59 -07:00
|
|
|
if (argc > 1 && !strcmp(argv[1], "klp")) {
|
|
|
|
|
argc--;
|
|
|
|
|
argv++;
|
|
|
|
|
return cmd_klp(argc, argv);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 17:08:18 -07:00
|
|
|
return objtool_run(argc, argv);
|
2016-02-28 22:22:41 -06:00
|
|
|
}
|