Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4832458rwd; Tue, 30 May 2023 10:29:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4RMH3FpxJOJZBaf6T2Hh2GDRCsRJfpKoYvdYWb7vs4s9fk+JrjceOEDBh6MBdOK+0rIesL X-Received: by 2002:a17:903:2301:b0:1ab:675:3e0c with SMTP id d1-20020a170903230100b001ab06753e0cmr3153844plh.33.1685467782529; Tue, 30 May 2023 10:29:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685467782; cv=none; d=google.com; s=arc-20160816; b=XXI4sr9VIqz+vPbJ4/VbRu8WYYZ/VaBLeKqHIYSxyPLVtX5hmom8jTeTPFTOjiw/4G /tkByoBgf3/jsDq2J/cuuFjWDC6/f5wQ0JHz3lOd5vvqAtXwU6knNPItjvf2RwoyT1p/ gcx18du9TXunpP/3MroAq7VOafGp1yfoPsrl22WN8LzeJGI7BO0uBdYvLjHtaXY3BsA9 1SWctVROAbcZJ5Bckmj6azd1E29ljdZVM3BCxwSgyxLSxIc3mBqCMp4u433l1/fB3vKr Jrc3l8Nq/E8R5VHzwI05kK9edFMIsVG4Xp1yhjRGaXmJXdcSDriqOGNV8hH2KKByhbAm RSxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+anb3718kv6WMM3e/ASp2a9XvJnJmzmQHhbA0o0QOJg=; b=gc3I46O8oWP4oMc9jdtg+VAuKHOsgCkcI5lH0341345eN7/NMZK5ttYnwDY7Snh5ML fQVM1G7wpyuIYG3s27veN6q/7uTycZhoRPoqH0bLioOPXJSk2m/Lp3akvNT385RPu8xl UUYl1mv36LhGjcvbFfVIVT9vw6Ygq63rBC3oQH8g0eO5OSiL8Y4hVxgWuN8YgtjEz63F HikOOxYCbEYM6XsF5sIJD5DGZMl2vRhM9G0ZDlRpeEcY/kV6sJhJP0mndJoTiMH1v8CT Pn6RQO5PSIaz6pfJF5cax6Adger7H0cQFeH2hL4P8AvUUwHP+3b4xYSKQ2ypke4eG4qf Z3Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OWzvEeVS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a17090341c900b001ae8c22791asi8119239ple.477.2023.05.30.10.29.12; Tue, 30 May 2023 10:29:42 -0700 (PDT) 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=pass header.i=@kernel.org header.s=k20201202 header.b=OWzvEeVS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233412AbjE3RWM (ORCPT + 99 others); Tue, 30 May 2023 13:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232942AbjE3RVj (ORCPT ); Tue, 30 May 2023 13:21:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45AF7C5 for ; Tue, 30 May 2023 10:21:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BDDC963119 for ; Tue, 30 May 2023 17:21:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6362CC433D2; Tue, 30 May 2023 17:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685467295; bh=ahsLwQFtwGTVxZ23xRH22wo/YjNgv9FRU2AJq+x5RMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OWzvEeVSYvQlaQGPfxNwl5nzNeioFO0LUl3VrwYzvS7s2yCRICZBPsaPuU62KBtqY 3UAScF7gOdWgQC7XVtY6fL8dnFFZ4XQuqh1nBd0n7V9im5h+XJBtMwnhPzcT9g98lR vj8TSZkjh+eKiG2zcccrGYq2Bl/qm519Uj850VMYcVOI64DenethuXFmM7tPvAuvgd suY1uIsaEFkfuWvSLDSnRlVnrY6WtMM7k6JVEdsZUY/HzgxMukDpHz61kO3BUFW02F 8d4jBAAZYfEGLoAh6NRGP9xtXMzjv16+xYWt5uYXcr+oICFSuIz7vdo/MlpARIyXG4 dOG+ARt/I23QQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH 10/22] objtool: Add for_each_reloc() Date: Tue, 30 May 2023 10:21:02 -0700 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 24 ++++++++++++------------ tools/objtool/include/objtool/elf.h | 6 ++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 88f54bb1b01c..1355e6fec7d6 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -590,7 +590,7 @@ static int add_dead_ends(struct objtool_file *file) if (!rsec) goto reachable; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { if (reloc->sym->type != STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; @@ -625,7 +625,7 @@ static int add_dead_ends(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { if (reloc->sym->type != STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; @@ -1018,7 +1018,7 @@ static void add_ignores(struct objtool_file *file) if (!rsec) return; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { switch (reloc->sym->type) { case STT_FUNC: func = reloc->sym; @@ -1259,7 +1259,7 @@ static int add_ignore_alternatives(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { if (reloc->sym->type != STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; @@ -1990,7 +1990,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, * Each @reloc is a switch table relocation which points to the target * instruction. */ - list_for_each_entry_from(reloc, &table->sec->reloc_list, list) { + for_each_reloc_from(table->sec, reloc) { /* Check for the end of the table: */ if (reloc != table && reloc->jump_table_start) @@ -2264,7 +2264,7 @@ static int read_noendbr_hints(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { insn = find_insn(file, reloc->sym->sec, reloc->sym->offset + reloc->addend); if (!insn) { WARN("bad .discard.noendbr entry"); @@ -2287,7 +2287,7 @@ static int read_retpoline_hints(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { if (reloc->sym->type != STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; @@ -2323,7 +2323,7 @@ static int read_instr_hints(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { if (reloc->sym->type != STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; @@ -2342,7 +2342,7 @@ static int read_instr_hints(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { if (reloc->sym->type != STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; @@ -2370,7 +2370,7 @@ static int read_validate_unret_hints(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { if (reloc->sym->type != STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; @@ -2398,7 +2398,7 @@ static int read_intra_function_calls(struct objtool_file *file) if (!rsec) return 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { + for_each_reloc(rsec, reloc) { unsigned long dest_off; if (reloc->sym->type != STT_SECTION) { @@ -4395,7 +4395,7 @@ static int validate_ibt(struct objtool_file *file) strstr(sec->name, "__patchable_function_entries")) continue; - list_for_each_entry(reloc, &sec->rsec->reloc_list, list) + for_each_reloc(sec->rsec, reloc) warnings += validate_ibt_data_reloc(file, reloc); } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index 74f63934afd3..a938cb1d4172 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -209,6 +209,12 @@ static inline void mark_sec_changed(struct elf *elf, struct section *sec, for_each_sec(file, __sec) \ sec_for_each_sym(__sec, sym) +#define for_each_reloc(rsec, reloc) \ + list_for_each_entry(reloc, &rsec->reloc_list, list) + +#define for_each_reloc_from(rsec, reloc) \ + list_for_each_entry_from(reloc, &rsec->reloc_list, list) + #define OFFSET_STRIDE_BITS 4 #define OFFSET_STRIDE (1UL << OFFSET_STRIDE_BITS) #define OFFSET_STRIDE_MASK (~(OFFSET_STRIDE - 1)) -- 2.40.1