Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1400435rwl; Wed, 12 Apr 2023 12:12:59 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgBS6UQinVxN9Naiq50DYzn3FdI5B3mRWOrt7TtEVqPIwvVYl6j/fwrBfNYbrwiJCKjFvf X-Received: by 2002:a17:90b:38d0:b0:246:b973:4d2b with SMTP id nn16-20020a17090b38d000b00246b9734d2bmr10926343pjb.37.1681326779324; Wed, 12 Apr 2023 12:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681326779; cv=none; d=google.com; s=arc-20160816; b=ECxH+hlPKy0Jbbhab2YI8H+C/b0Y2pNOfeULXPMBtKAW/OtYX5ZP7Jc0peI0Jw3fiH Q85zhtMUZVxeYWLcbrVFeuX4k5bNEJ0bqihRsnK+qD81ovAv2bUR2scZxXx2Ka9yUWTm Per/fEhkUmb6ulHZcMh43aIIS30PdZog+lPwZco4DD0Tq0wOOaMFCYB8hsyGxPSYltI2 iZ4Vg67PLlWeLzUOy8d4QPn/sNPT1kIiWcf62zWhGO4MmBowjTGlyT38Jzr/wEvkgueO bDgKGMaalJb/e3qecPuLs8HlLTycz2Iv1X++TtxI0FYMp9OR3rVBfaeMVaqR4nSEpy2K HEiA== 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=16t4cWKSwh/orYuIIb2fPbMmLoAs7nnYoBeAc6VSW1M=; b=PrRFEKotHbVINrghwRFUmWevmfNa2WRtxikxQ7I5DNhu0k2QxB+ebwcfRBPahXwykL +Ea5InkAtdkPcPHXDi/40b1UzLwuygsnW8kwt5eFP/XKRr4ez9kBVQgl8U6s9PWw7bw0 HSRfzKEVuq+v3YcQKLZSffzxZXB4nLmTIh1mSC+xZ0rcI7bozxtsYfEytyQg37rSEQLc XGHPd4QVaTxvvTr9V/9oVewOgXXxxvHhIyDgETvsa62UrYzNPIcXZvmAvjSGLXZumhWY /bmCbE4dV5tSGX8LeDU8gR3eyDavgYxj01QzUDX9whjaWl5o5lxjdqMdef6VDeNzDudX +NjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qLyqRwZ7; 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 i71-20020a63874a000000b0051972e42719si9590160pge.66.2023.04.12.12.12.46; Wed, 12 Apr 2023 12:12:59 -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=qLyqRwZ7; 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 S229999AbjDLTD7 (ORCPT + 99 others); Wed, 12 Apr 2023 15:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbjDLTDt (ORCPT ); Wed, 12 Apr 2023 15:03:49 -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 634A519AD for ; Wed, 12 Apr 2023 12:03:47 -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 F32C763871 for ; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9879AC433A0; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326226; bh=xaXnGfbC/VMDQDGu1YDrIHmJbcCkfgf/aMjvRsvTeLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qLyqRwZ7Cm9rjuMjVK1mOv2LqbY4qSfm/yt2qOzI90jMhIHqgq3Ne5OXSfZj5MnfC /G9y/FHQz5d2PLw0bF5VWTTAthGhPRPxoBpO+1f1ZzzDnPcLclndGWA2e5eC6nbWU5 tKJ8Jl5bhwLJ2D0jboWiZimpuyS92Mss683UZM8Qz+owmWnqpp9lFOgsckrwPOonmt gLNYTiI2BWey0p+J4oSdLlrU4WZhr/hoY38iDSJmW4vSZCHfap0N0AA+YanzZY4jzV //2ty/m4b9zemQ/58plj+1OcX8fQdafga5hgJcAAOV14c2ktHILY7a8B1nT7ja+n4L kOa8ttD6I5loQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 4/9] objtool: Add symbol iteration helpers Date: Wed, 12 Apr 2023 12:03:19 -0700 Message-Id: <59023e5886ab125aa30702e633be7732b1acaa7e.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 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 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 Add [sec_]for_each_sym() and use them. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 98 ++++++++++++----------------- tools/objtool/elf.c | 2 +- tools/objtool/include/objtool/elf.h | 9 +++ 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index de0d0234527d..d1d47baa252c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -470,7 +470,7 @@ static int decode_instructions(struct objtool_file *file) // printf("%s: last chunk used: %d\n", sec->name, (int)idx); - list_for_each_entry(func, &sec->symbol_list, list) { + sec_for_each_sym(sec, func) { if (func->type != STT_NOTYPE && func->type != STT_FUNC) continue; @@ -924,7 +924,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file) static int create_cfi_sections(struct objtool_file *file) { - struct section *sec, *s; + struct section *sec; struct symbol *sym; unsigned int *loc; int idx; @@ -937,19 +937,14 @@ static int create_cfi_sections(struct objtool_file *file) } idx = 0; - for_each_sec(file, s) { - if (!s->text) + for_each_sym(file, sym) { + if (sym->type != STT_FUNC) continue; - list_for_each_entry(sym, &s->symbol_list, list) { - if (sym->type != STT_FUNC) - continue; - - if (strncmp(sym->name, "__cfi_", 6)) - continue; + if (strncmp(sym->name, "__cfi_", 6)) + continue; - idx++; - } + idx++; } sec = elf_create_section(file->elf, ".cfi_sites", 0, sizeof(unsigned int), idx); @@ -957,28 +952,23 @@ static int create_cfi_sections(struct objtool_file *file) return -1; idx = 0; - for_each_sec(file, s) { - if (!s->text) + for_each_sym(file, sym) { + if (sym->type != STT_FUNC) continue; - list_for_each_entry(sym, &s->symbol_list, list) { - if (sym->type != STT_FUNC) - continue; - - if (strncmp(sym->name, "__cfi_", 6)) - continue; + if (strncmp(sym->name, "__cfi_", 6)) + continue; - loc = (unsigned int *)sec->data->d_buf + idx; - memset(loc, 0, sizeof(unsigned int)); + loc = (unsigned int *)sec->data->d_buf + idx; + memset(loc, 0, sizeof(unsigned int)); - if (elf_add_reloc_to_insn(file->elf, sec, - idx * sizeof(unsigned int), - R_X86_64_PC32, - s, sym->offset)) - return -1; + if (elf_add_reloc_to_insn(file->elf, sec, + idx * sizeof(unsigned int), + R_X86_64_PC32, + sym->sec, sym->offset)) + return -1; - idx++; - } + idx++; } return 0; @@ -2205,23 +2195,20 @@ static int add_func_jump_tables(struct objtool_file *file, */ static int add_jump_table_alts(struct objtool_file *file) { - struct section *sec; struct symbol *func; int ret; if (!file->rodata) return 0; - for_each_sec(file, sec) { - list_for_each_entry(func, &sec->symbol_list, list) { - if (func->type != STT_FUNC) - continue; + for_each_sym(file, func) { + if (func->type != STT_FUNC) + continue; - mark_func_jump_tables(file, func); - ret = add_func_jump_tables(file, func); - if (ret) - return ret; - } + mark_func_jump_tables(file, func); + ret = add_func_jump_tables(file, func); + if (ret) + return ret; } return 0; @@ -2533,30 +2520,27 @@ static bool is_profiling_func(const char *name) static int classify_symbols(struct objtool_file *file) { - struct section *sec; struct symbol *func; - for_each_sec(file, sec) { - list_for_each_entry(func, &sec->symbol_list, list) { - if (func->bind != STB_GLOBAL) - continue; + for_each_sym(file, func) { + if (func->bind != STB_GLOBAL) + continue; - if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR, - strlen(STATIC_CALL_TRAMP_PREFIX_STR))) - func->static_call_tramp = true; + if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR, + strlen(STATIC_CALL_TRAMP_PREFIX_STR))) + func->static_call_tramp = true; - if (arch_is_retpoline(func)) - func->retpoline_thunk = true; + if (arch_is_retpoline(func)) + func->retpoline_thunk = true; - if (arch_is_rethunk(func)) - func->return_thunk = true; + if (arch_is_rethunk(func)) + func->return_thunk = true; - if (arch_ftrace_match(func->name)) - func->fentry = true; + if (arch_ftrace_match(func->name)) + func->fentry = true; - if (is_profiling_func(func->name)) - func->profiling_func = true; - } + if (is_profiling_func(func->name)) + func->profiling_func = true; } return 0; @@ -4222,7 +4206,7 @@ static int validate_section(struct objtool_file *file, struct section *sec) struct symbol *func; int warnings = 0; - list_for_each_entry(func, &sec->symbol_list, list) { + sec_for_each_sym(sec, func) { if (func->type != STT_FUNC) continue; diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 6806ce01d933..500e92979a31 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -474,7 +474,7 @@ static int read_symbols(struct elf *elf) /* Create parent/child links for any cold subfunctions */ list_for_each_entry(sec, &elf->sections, list) { - list_for_each_entry(sym, &sec->symbol_list, list) { + sec_for_each_sym(sec, sym) { char pname[MAX_NAME_LEN + 1]; size_t pnamelen; if (sym->type != STT_FUNC) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index a668173a5869..78e2d0fc21ca 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -189,4 +189,13 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset); #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list) +#define sec_for_each_sym(sec, sym) \ + list_for_each_entry(sym, &sec->symbol_list, list) + +#define for_each_sym(file, sym) \ + for (struct section *__sec, *__fake = (struct section *)1; \ + __fake; __fake = NULL) \ + for_each_sec(file, __sec) \ + sec_for_each_sym(__sec, sym) + #endif /* _OBJTOOL_ELF_H */ -- 2.39.2