From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 26DD980032 for ; Thu, 26 Nov 2026 06:12:46 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQ6BZj0005836; Thu, 26 Nov 2026 09:11:36 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ6BZj0005836 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="UySE8COr" Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQ67gx0005304 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 26 Nov 2026 09:07:42 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ67gx0005304 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-c5101fd59e3so554045966b.0 for ; Wed, 25 Nov 2026 22:07:42 -0800 (PST) X-Gm-Message-State: APuU4Z/TjzDQ5L+Krv1CVuqbQyr1dJyJLyAu33mWZX2q1Fw1UWO8Vxwt f0UdY62teuJxvxNHR7lXdfBVLhsRUYPsOPH9hvTJ+2o8rbXgt+AGNpxKUsHYCkmfxe0qLDL4vbF zBugdHiy0ECY4lYJNCBHTHn/+1BC0HWxVYrPXZqlp7vW9ZtojsEz/CQ== X-Gm-Gg: AZFdTZcyIqFZABIWTDbLd8NFaX/DTNhitgI9lxWQidGHcIXKOAWHJY5UpgJbphPdE7S epNY/MObFCJyBM82eoftqLGN5ILrXVWfKpJV/BFJjZa3H1na6HDMp+UfWtoeREn0pGv3Li2cDeP 9oAk1690iv5olOKnJPLXI17eurD+RUQ0NZT5jrWE6Gc10Z0xpPqzACmxQmPpqC6IUZ/LJiMouRO 0sL4fPjt8GZbVXIMi+xm9JbKgzO760VIu5tK0SN8PFRkBy8N5CFczX5MFTrnCzjNxqtbybdLSwe ld3oyWjgDqHH25+0DmiiIQ1hSQ5rAZODhcOhibw38gNFszu1gwrJ8O0m0XGT/kYEBvuCnW4G7ks wJAXxo9HPCAyl/m+C54DomK6S X-Received: by 2002:a17:906:7d7:b0:c46:8913:d89d with SMTP id a640c23a62f3a-c513a9997c4mr1314303466b.14.1795673261585; Wed, 25 Nov 2026 22:07:41 -0800 (PST) X-Received: by 2002:a17:906:7d7:b0:c46:8913:d89d with SMTP id a640c23a62f3a-c513a9997c4mr1314302566b.14.1795673261134; Wed, 25 Nov 2026 22:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795673261; cv=none; d=google.com; s=arc-20260327; b=Z6vDO2OKJx0+wjIj/XIlN1AYo0tw0GTVgQP+nV3qu3rQFvxrexrGPEtu+UC50ToBWp 5nRClTCxguxIjNoJ7AJqJtay0+0O0dCrs7mAmCuhEWJ4CkLGbqOnZBvHuK8WtED4oX5i FjQCK1TXVyYLdbBQyJSLl9F5v0PGsttJ/fm1xvSRDgK5S0I+nibdTBsnK3SHDVQVT9QZ vBliJFuSynj/jdr4SPak3BkUxgv8e3sYL8cBQKJ37WBomoK6YPQG+SLG/wWvvTkDtwxE 2hPvXWGX8CZUjmfRBR2Pb08SHUV79nmtsBcJ497jQPk7VMd4q2OkC0+lHoHVZD9SYkBv s9OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=05xeEa52mjx+6R7eoN7XYOUBMl3nEMAWkjo9A7pAclE=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=AcuESvjwBitSFLdiUYsMAx7UwTu4J+acB8Pa1Et5FxGWRIL1cg7z+gQI5jylmUXaGc jx4xoT45flBC+HMPqvoodQZuYbHi832dJnN/ElkYfnFUkYZT9nhnkgVoBHY3WVqQGwZH c/NJ5yKaJvR/8B+jQz8lEAmJxSvONV7cTHfEplquu7QzAidtU0rbyEdaiHb+ODMwPiGY VKxX3UkOAqI0hEif1a5HqJE/3uNp7PycvWuT09bA6WJFtAAtz5oC+LND+NbSh0UrvD84 B6Hsa36iZH78wapevst70WGr+GHfOStKtnezld9zQP/qpZ6pVEYsDwqs3Bfail+UxcPQ xIMg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=UySE8COr; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513b0d987asi1312150066b.345.2026.11.25.22.07.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 22:07:41 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=UySE8COr; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=05xeEa52mjx+6R7eoN7XYOUBMl3nEMAWkjo9A7pAclE=; b=UySE8COrSHBi MIgMSW3dP9K8rGhkdWmXzfdEmI9fZNv7AIDy8gPCDt2gBdC60cbRMEQsjTougEa/wWoDKhTcGS21t T1QyXqzAH+5B7s2JsWy2gEL7N7HuItoal6zvPH16FuZx+xpWloak4gLBQemsggW0UE2adeOhaAa3X 68Gs/FTa3E6e+wUXgTjnIGvkq1pXf2JFnjGn+JMsDeuw+wATTmw5EKh4QYw4poSGe3rCxN3k5gLZe YsYTtpYXPW7aYIQ6tIO/GVx3PFmli0pblTcO/eYzSnnFcWvU+8o8gRkMu5eTQ7ZD7VggqXp5zn3mn B729SnMN3f4pOFzkrvIgXw==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xWScs-00E8nT-0Q; Thu, 26 Nov 2026 07:06:44 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 26 Nov 2026 07:07:21 +0200 Message-ID: <20261126060620.2126341-24-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126060620.2126341-2-eva.kurchatova@virtuozzo.com> References: <20261126060620.2126341-2-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 22/28] ms/objtool/klp: Add .klp.symid for sympos disambiguation X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Josh Poimboeuf Livepatch identifies a duplicate-named symbol by its position (sympos) among same-named kallsyms entries, which for vmlinux are counted in ascending address order in the final linked kernel. That order can't be reliably derived from vmlinux.o: the final link reorders sub-sections (.text.unlikely*, .data..*, etc). Bridge the gap with a new .klp.symid section which can be used to correlate symbols between vmlinux.o and vmlinux so that klp-diff can reliably determine the sympos. The table can't survive --gc-sections: keeping it alive would keep every duplicate-named symbol's section alive, so the reference kernel would stop matching the one which ships. klp-build rejects CONFIG_LD_DEAD_CODE_DATA_ELIMINATION instead. Nothing is lost today: x86_64 is the only HAVE_KLP_BUILD arch and doesn't select HAVE_LD_DEAD_CODE_DATA_ELIMINATION, arm64 and s390 have never selected it either, and on powerpc, it's still EXPERIMENTAL and disabled by every distro kernel. This is the build-time half of reliable vmlinux sympos computation; "objtool klp diff" will consume the table in a subsequent commit. Signed-off-by: Josh Poimboeuf Signed-off-by: Ingo Molnar Cc: live-patching@vger.kernel.org Link: https://patch.msgid.link/64d50f077b569f47883c015cdb7079edb068efe8.1785727106.git.jpoimboe@kernel.org (cherry picked from commit 029223d301620bc4e1086696047b0d5d6eba5edd) Rebase note: for_each_sym_by_name() is added here, on the symbol name hash of this tree, and str_hash() moves to elf.h from elf.c and klp-diff.c, as mainline has them since 0333b7399587 ("objtool: Replace iterator callback with for_each_sym_by_mangled_name()") and def5b60dcd22 ("objtool/klp: Fix --debug-checksum for duplicate symbol names"). Context conflicts only elsewhere. https://virtuozzo.atlassian.net/browse/VSTOR-156924 Feature: klp-build support Signed-off-by: Eva Kurchatova --- include/asm-generic/vmlinux.lds.h | 10 +- scripts/Makefile.vmlinux_o | 3 + scripts/livepatch/klp-build | 5 + scripts/mod/modpost.c | 1 + tools/objtool/Build | 1 + tools/objtool/builtin-check.c | 7 ++ tools/objtool/check.c | 7 ++ tools/objtool/elf.c | 12 ++- tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/elf.h | 17 ++++ tools/objtool/include/objtool/klp.h | 15 +++ tools/objtool/klp-diff.c | 5 - tools/objtool/klp-symid.c | 117 ++++++++++++++++++++++++ 13 files changed, 190 insertions(+), 11 deletions(-) create mode 100644 tools/objtool/klp-symid.c diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 366ac310ad09..28c9ac174599 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -841,12 +841,20 @@ .stab.index 0 : { *(.stab.index) } \ .stab.indexstr 0 : { *(.stab.indexstr) } +#ifdef CONFIG_KLP_BUILD +#define KLP_SYMID \ + .klp.symid 0 : { *(.klp.symid) } +#else +#define KLP_SYMID +#endif + /* Required sections not related to debugging. */ #define ELF_DETAILS \ .comment 0 : { *(.comment) } \ .symtab 0 : { *(.symtab) } \ .strtab 0 : { *(.strtab) } \ - .shstrtab 0 : { *(.shstrtab) } + .shstrtab 0 : { *(.shstrtab) } \ + KLP_SYMID #ifdef CONFIG_GENERIC_BUG #define BUG_TABLE \ diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o index cd6b21d89f44..632f882e2791 100644 --- a/scripts/Makefile.vmlinux_o +++ b/scripts/Makefile.vmlinux_o @@ -47,6 +47,9 @@ endif vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr \ $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_SRSO)), --unret) +# Only used for builds initiated by klp-build +vmlinux-objtool-args-$(if $(KLP_SYMIDS),y) += --klp-symids + objtool-args = $(vmlinux-objtool-args-y) --link # Link of vmlinux.o used for section mismatch analysis diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 882272120c9e..3bd134fe2283 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -249,6 +249,9 @@ validate_config() { [[ -v CONFIG_GCC_PLUGIN_RANDSTRUCT ]] && \ die "kernel option 'CONFIG_GCC_PLUGIN_RANDSTRUCT' not supported" + [[ -v CONFIG_LD_DEAD_CODE_DATA_ELIMINATION ]] && \ + die "kernel option 'CONFIG_LD_DEAD_CODE_DATA_ELIMINATION' not supported" + return 0 } @@ -513,6 +516,8 @@ build_kernel() { # cmd+=("KBUILD_MODPOST_WARN=1") + cmd+=("KLP_SYMIDS=1") + cmd+=("$VERBOSE") cmd+=("-j$JOBS") cmd+=("KCFLAGS=-ffunction-sections -fdata-sections") diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 6e5ae3a05b36..746a51cf9821 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -749,6 +749,7 @@ static const char *const section_white_list[] = ".gnu.lto*", ".discard.*", ".llvm.call-graph-profile", /* call graph */ + ".klp.symid", /* objtool --klp-symids */ NULL }; diff --git a/tools/objtool/Build b/tools/objtool/Build index 8cd71b9a5eef..6b01eaa4e554 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -6,6 +6,7 @@ objtool-y += check.o objtool-y += special.o objtool-y += builtin-check.o objtool-y += elf.o +objtool-y += klp-symid.o objtool-y += objtool.o objtool-$(BUILD_ORC) += orc_gen.o orc_dump.o diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index e550fb9a504e..45163ba80b09 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -77,6 +77,7 @@ static const struct option check_options[] = { OPT_BOOLEAN(0, "cfi", &opts.cfi, "annotate kernel control flow integrity (kCFI) function preambles"), OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake", "patch toolchain bugs/limitations", parse_hacks), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), + OPT_BOOLEAN(0, "klp-symids", &opts.klp_symids, "generate .klp.symids for duplicate symbol disambiguation"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls for ftrace"), OPT_BOOLEAN(0, "noabs", &opts.noabs, "reject absolute references in allocatable sections"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), @@ -174,10 +175,16 @@ static bool opts_valid(void) return false; } + if (opts.klp_symids && !opts.link) { + ERROR("--klp-symids requires --link"); + return false; + } + if (opts.checksum || opts.hack_jump_label || opts.hack_noinstr || opts.ibt || + opts.klp_symids || opts.mcount || opts.noabs || opts.noinstr || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f9539dae294f..403da0d3739a 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -4972,6 +4973,12 @@ int check(struct objtool_file *file) goto out; } + if (opts.klp_symids) { + ret = klp_create_symid_sections(file); + if (ret) + goto out; + } + if (opts.noabs) warnings += check_abs_references(file); diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 167a57cf71ab..1c6d071f81e2 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -27,11 +27,6 @@ #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); -} - #define __elf_table(name) (elf->name##_hash) #define __elf_bits(name) (elf->name##_bits) @@ -290,6 +285,13 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset) return NULL; } +/* The first symbol of the hash chain of @name, see for_each_sym_by_name() */ +struct symbol *elf_sym_name_chain(const struct elf *elf, const char *name) +{ + return elf_list_entry(__elf_table_entry(symbol_name, str_hash(name)), + struct symbol, name_hash); +} + struct symbol *find_symbol_by_name(const struct elf *elf, const char *name) { struct symbol *sym; diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h index bb0b25eb08ba..b944cb30540e 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -16,6 +16,7 @@ struct opts { bool hack_noinstr; bool hack_skylake; bool ibt; + bool klp_symids; bool mcount; bool noabs; bool noinstr; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index 411f7ada7e47..757f7c78acd3 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -21,6 +21,11 @@ #define SEC_NAME_LEN 1024 #define SYM_NAME_LEN 512 +static inline u32 str_hash(const char *str) +{ + return jhash(str, strlen(str), 0); +} + #define bswap_if_needed(elf, val) __bswap_if_needed(&elf->ehdr, val) #ifdef LIBELF_USE_DEPRECATED @@ -184,6 +189,7 @@ struct section *find_section_by_name(const struct elf *elf, const char *name); struct symbol *find_func_by_offset(struct section *sec, unsigned long offset); struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset); struct symbol *find_symbol_by_name(const struct elf *elf, const char *name); +struct symbol *elf_sym_name_chain(const struct elf *elf, const char *name); struct symbol *find_global_symbol_by_name(const struct elf *elf, const char *name); struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset); struct symbol *find_symbol_containing_inclusive(const struct section *sec, unsigned long offset); @@ -470,6 +476,17 @@ static inline void set_sym_next_reloc(struct reloc *reloc, struct reloc *next) #define for_each_sym_continue(elf, sym) \ list_for_each_entry_continue(sym, &elf->symbols, global_list) +static inline struct symbol *elf_sym_name_next(struct symbol *sym) +{ + return sym->name_hash.next ? + container_of(sym->name_hash.next, struct symbol, name_hash) : NULL; +} + +#define for_each_sym_by_name(elf, _name, sym) \ + for (sym = elf_sym_name_chain(elf, _name); sym; \ + sym = elf_sym_name_next(sym)) \ + if (strcmp(sym->name, _name)) {} else + #define rsec_next_reloc(rsec, reloc) \ reloc_idx(reloc) < sec_num_entries(rsec) - 1 ? reloc + 1 : NULL diff --git a/tools/objtool/include/objtool/klp.h b/tools/objtool/include/objtool/klp.h index d9cb594f4924..b23ddde8b47d 100644 --- a/tools/objtool/include/objtool/klp.h +++ b/tools/objtool/include/objtool/klp.h @@ -33,6 +33,21 @@ struct klp_reloc { u32 type; }; +/* + * .klp.symid is used to correlate symbols between vmlinux.o and vmlinux, for + * calculating sympos to disambiguate duplicately-named symbols. + */ +#define KLP_SYMID_SEC ".klp.symid" + +struct klp_symid { + u64 id; + u64 addr; +}; + +struct objtool_file; + +int klp_create_symid_sections(struct objtool_file *file); + int cmd_klp_diff(int argc, const char **argv); int cmd_klp_post_link(int argc, const char **argv); diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 1428ac71dff8..d9c91539f690 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -46,11 +46,6 @@ static const struct option klp_diff_options[] = { static DEFINE_HASHTABLE(exports, 15); -static inline u32 str_hash(const char *str) -{ - return jhash(str, strlen(str), 0); -} - static char *escape_str(const char *orig) { size_t len = 0; diff --git a/tools/objtool/klp-symid.c b/tools/objtool/klp-symid.c new file mode 100644 index 000000000000..cf188cdfa607 --- /dev/null +++ b/tools/objtool/klp-symid.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Emit the .klp.symid table which allows "objtool klp diff" to reliably + * disambiguate duplicate-named local symbols in vmlinux. + * + * Livepatch identifies a duplicate-named symbol by its position (sympos) + * among the same-named kallsyms entries, counted in ascending address order + * in the final linked vmlinux. That order can't be derived from vmlinux.o + * alone: the final link reorders sub-sections (.text.unlikely*, .data..*, + * etc). + * + * Bridge the gap with a table which survives the final link: a single + * non-alloc section containing an array of { id, addr } entries, where + * 'id' is a unique counter identifier and 'addr' has a relocation to the + * symbol. The linker copies 'id' verbatim and resolves 'addr' to the symbol's + * final address. + * + * The table is only emitted for vmlinux.o, and only when klp-build asks for it + * with KLP_SYMIDS=1, which adds --klp-symids to the vmlinux.o objtool run. + * + * It can't survive --gc-sections, which sweeps the whole section; klp-build + * rejects CONFIG_LD_DEAD_CODE_DATA_ELIMINATION. + */ +#include + +#include +#include +#include +#include + +static const char * const discarded_secs[] = { + ".discard", + ".modinfo", + "__tracepoint_check", +}; + +static bool discarded_sec(struct section *sec) +{ + if (!(sec->sh.sh_flags & SHF_ALLOC)) + return true; + + for (int i = 0; i < ARRAY_SIZE(discarded_secs); i++) + if (strstarts(sec->name, discarded_secs[i])) + return true; + + return false; +} + +static bool symid_needed(struct elf *elf, struct symbol *sym) +{ + struct symbol *s; + + if (!is_local_sym(sym) || is_undef_sym(sym)) + return false; + + if (!is_func_sym(sym) && !is_object_sym(sym)) + return false; + + if (is_prefix_func(sym)) + return false; + + if (discarded_sec(sym->sec)) + return false; + + for_each_sym_by_name(elf, sym->name, s) { + if (s == sym || is_sec_sym(s) || is_file_sym(s) || is_undef_sym(s)) + continue; + return true; + } + + return false; +} + +int klp_create_symid_sections(struct objtool_file *file) +{ + struct elf *elf = file->elf; + struct klp_symid *symids; + struct section *sec; + struct symbol *sym; + u64 nr = 0, i = 0; + + if (!str_ends_with(objname, "vmlinux.o")) + return 0; + + for_each_sym(elf, sym) + if (symid_needed(elf, sym)) + nr++; + + if (!nr) + return 0; + + sec = elf_create_section(elf, KLP_SYMID_SEC, 0, sizeof(struct klp_symid), + SHT_PROGBITS, 8, 0); + if (!sec) + return -1; + + symids = elf_add_data(elf, sec, NULL, nr * sizeof(struct klp_symid)); + if (!symids) + return -1; + + for_each_sym(elf, sym) { + if (!symid_needed(elf, sym)) + continue; + + symids[i].id = bswap_if_needed(elf, i); + + if (!elf_create_reloc(elf, sec, + i * sizeof(struct klp_symid) + + offsetof(struct klp_symid, addr), + sym, 0, R_ABS64)) + return -1; + + i++; + } + + return 0; +} -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel