Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3382615rwl; Tue, 27 Dec 2022 08:19:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXuYM1+K/IIsO8wSehcBgV9SzIU1DKZFDfuKnLDca32/qa3FvfwG9y/NnxoHZIDR6dU48+hb X-Received: by 2002:a05:6a21:99a4:b0:a3:94cd:1435 with SMTP id ve36-20020a056a2199a400b000a394cd1435mr36450711pzb.38.1672157985132; Tue, 27 Dec 2022 08:19:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672157985; cv=none; d=google.com; s=arc-20160816; b=C9DEUt/Ut64MP+gKwGziZUKNDPftqu2egK+mxYofUS4WBZCliDSaxi9o6wQqmnJhyp 45WppyZZwqa+YaHAexP6qwIJIupIv/OHJ2hfzkq5iLkl79rPWB4p82+YsmZ4utvcXmLI fc8vmWH7U4hrw3RIZ01e24PKkYCTK7deUkymDf9xzJWj/EPwimgaIDijORVUf8HJGNiV FEEDlF21P/+TcdfNXY8mCFuHPC2bt3FbscJvSFVxbVOu0ldI3pbBxsBRqYxs3+g1KV56 JaMMN/949cqM4gfe0Kf992IAIre90MmWb6JrhCRzMt7aNhCXuUP33M+3DklpzUVazz79 uvDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:dkim-signature :from; bh=SF2vaSzCUPYujLiuToAcktE0mfkoRJgXutov5HwIa8M=; b=uee5A0GABqCWhgP97m/Nqk51fHTnLGjmtUVVtdOvvRCIPMkBDzXLPnKiAIQxY+SAkp raNb1F7yXE17+H5JI5AKipMkiSx3F89QMi4x5RiNOeYiBED/8NmMcJ2m4QFBQdhkAc/b 7rGWg7MBchjdlVElsqmCBu64HEIsQAAH/QdegNpkfGmc5YL5aoS6Skt+Dd1ucINf2OSR jlnW3oufb8d4CCZX8TAeovffG0anzntm8uoc/PQmlq81+Jf3UoJBzWkkk1THsNdv3tfr 3utJSG2J8clcqBEe5slOzxuR3qVV6oIMkC7TV/YSBcueH+zZOiPj4wSe1VS5gSMM0oGJ IXYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=lINXVNrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z9-20020a63c049000000b00485ae62fb77si2738064pgi.306.2022.12.27.08.19.36; Tue, 27 Dec 2022 08:19:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=lINXVNrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbiL0QDD (ORCPT + 66 others); Tue, 27 Dec 2022 11:03:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbiL0QCt (ORCPT ); Tue, 27 Dec 2022 11:02:49 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9BAEF18 for ; Tue, 27 Dec 2022 08:02:46 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156964; bh=XawsrqdClQjkEya+uIP7vjQbb3ysRQ5lLFyEAtEK+X4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lINXVNrUUOk3hwcmjZnbQqmQK+nWm1BcT4cDJEsbYIIzLtmYmF/Pa46Qr/kz4ILKE aIMVVuWkMs85n8wybbHJLPIPfPqJEsNwLInKYqw77S5rV88v2eBaeTtg/42RC+aktE 9Yv1W/0cepNMMrI8WYetZPG6WcPIEyVLUIggI8/s= Date: Tue, 27 Dec 2022 16:01:00 +0000 Subject: [PATCH v2 4/8] objtool: introduce function elf_reloc_set_type MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-Id: <20221216-objtool-memory-v2-4-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=3243; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=XawsrqdClQjkEya+uIP7vjQbb3ysRQ5lLFyEAtEK+X4=; b=gugRTtsJc0DvdnolPu6136JquZ3HSZXxFn9SkQmu8SbmeCtcWKkUYH2qz4tHTEEZRpry7agDfeVf xZvDrS44Czdh0zzmjTf9DxjCa0HgwUTq3S7H3iJUan4BcdvqDiOC X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An upcoming patch needs to perform validation when setting reloc->type so introduce a helper to contain this validation. Signed-off-by: Thomas Weißschuh --- tools/objtool/check.c | 6 +++--- tools/objtool/elf.c | 11 ++++++++--- tools/objtool/include/objtool/elf.h | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4350be739f4f..971ee6826de7 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1355,7 +1355,7 @@ static void annotate_call_site(struct objtool_file *file, */ if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) { if (reloc) { - reloc->type = R_NONE; + elf_reloc_set_type(reloc, R_NONE); elf_write_reloc(file->elf, reloc); } @@ -1384,7 +1384,7 @@ static void annotate_call_site(struct objtool_file *file, WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset); if (opts.mnop) { if (reloc) { - reloc->type = R_NONE; + elf_reloc_set_type(reloc, R_NONE); elf_write_reloc(file->elf, reloc); } @@ -1863,7 +1863,7 @@ static int handle_jump_alt(struct objtool_file *file, struct reloc *reloc = insn_reloc(file, orig_insn); if (reloc) { - reloc->type = R_NONE; + elf_reloc_set_type(reloc, R_NONE); elf_write_reloc(file->elf, reloc); } elf_write_insn(file->elf, orig_insn->sec, diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 9c326efb8cd9..ee355beb0d82 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -555,7 +555,7 @@ int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, reloc->sec = sec->reloc; reloc->offset = offset; - reloc->type = type; + elf_reloc_set_type(reloc, type); reloc->sym = sym; reloc->addend = addend; @@ -872,7 +872,7 @@ static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsig WARN_ELF("gelf_getrel"); return -1; } - reloc->type = GELF_R_TYPE(reloc->rel.r_info); + elf_reloc_set_type(reloc, GELF_R_TYPE(reloc->rel.r_info)); reloc->addend = 0; reloc->offset = reloc->rel.r_offset; *symndx = GELF_R_SYM(reloc->rel.r_info); @@ -885,7 +885,7 @@ static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsi WARN_ELF("gelf_getrela"); return -1; } - reloc->type = GELF_R_TYPE(reloc->rela.r_info); + elf_reloc_set_type(reloc, GELF_R_TYPE(reloc->rela.r_info)); reloc->addend = reloc->rela.r_addend; reloc->offset = reloc->rela.r_offset; *symndx = GELF_R_SYM(reloc->rela.r_info); @@ -1471,3 +1471,8 @@ void elf_close(struct elf *elf) free(elf->section_data); free(elf); } + +void elf_reloc_set_type(struct reloc *reloc, int type) +{ + reloc->type = type; +} diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index 1c90f0ac0d53..33ec6cf72325 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -83,6 +83,8 @@ struct reloc { bool jump_table_start; }; +void elf_reloc_set_type(struct reloc *reloc, int type); + #define ELF_HASH_BITS 20 struct elf { -- 2.39.0