From patchwork Fri Jun 9 07:47:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 105322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp778432vqr; Fri, 9 Jun 2023 00:50:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7awBNorETIn3CNzrUIojqLuuubeCA7dp3GqrCXW72kFjcWpMl8Ir7HIEH6oFtRBw4gX2oP X-Received: by 2002:a05:6a00:198b:b0:64f:c9a7:a809 with SMTP id d11-20020a056a00198b00b0064fc9a7a809mr495956pfl.6.1686297036502; Fri, 09 Jun 2023 00:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686297036; cv=none; d=google.com; s=arc-20160816; b=fnGlH/Gg9zOj57sC+FYuDrJ4nR2XgGQHerMfwPRsMweZi4GkhnGNzjYmVklQVAS8TT TyLldJpUyuF4kEr17IAgaSpz0pTwqsQjBT4/CCuutLdL1amh0mlwco3LoQMfbDDOukj6 paaIBR+re9Typ1xZDrheNKqnKqElv1S3l4OjBv0688OioAjjn2pXW0kf3Vcwd8Y+egeC BOu3Kpc5VxKWUdBM0gFixK8imcEmaA2hVdkazxT4UjHeP09kUiLHfu7v8cnVksdNosHK O8QqvQZuJmcweKbkPzJ+mh7OKo/WT80a8OhcUyTfHou74brhfQlX0/EwUPgvIQ4Hj464 vBmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=9P87doE6Z0HH3lUedPUa2tyR5oQm9EuwPpj3rRLBwbI=; b=pep0j5kr18t2n/jyDNfKsCZ3MpqPN7PjAP/MIzDfhmleBeabD0bUFfyWFJbB7gHr8e FF+KeCPDKm498HQebvHCyDWEIOioSSWgTqJ2tc/iApIkXtj15bLRptdNL6OCHoYTT5WY xiTDoNzivZgxqN7Wxvd1Wu2pTiAf9CMqLehDQwIqB2izk87+aTbnZ8T9vwDNQLwBdjV9 dqdMGBws+M0kFGiu9CnJG7uyEWguDfqa3yyeDQ/Qp39QnM6MUE2IcS5i6EofNet0mGn6 Pl0ui2fWpqfrkLdQNV39Ug5PUpNxuErnzkmyZGQ+sxT54jQ6uJEAHXsmmg9fcwDT19ak Kidg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KlKjnLkT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Y2CRn8IE; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a625306000000b0064d3894678bsi2132581pfb.64.2023.06.09.00.50.21; Fri, 09 Jun 2023 00:50:36 -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=@linutronix.de header.s=2020 header.b=KlKjnLkT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Y2CRn8IE; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239272AbjFIHtX (ORCPT + 99 others); Fri, 9 Jun 2023 03:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239117AbjFIHrq (ORCPT ); Fri, 9 Jun 2023 03:47:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A05B2D7F; Fri, 9 Jun 2023 00:47:43 -0700 (PDT) Date: Fri, 09 Jun 2023 07:47:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686296859; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9P87doE6Z0HH3lUedPUa2tyR5oQm9EuwPpj3rRLBwbI=; b=KlKjnLkTGiNJn0Mnutx3SqgB1I0XrhaDHa9brf2j6U24v46bO0V2lfSyjJRvTqjDm9ZHDX 75fYUiDor5HavPUqh9mMBn9SjfMIS0BL+X4UH7JkOZkP3rFHymPJ1ZuWAh8Z2NuAtB1iKd /69Hxw4HCUi+Y9yPpB5FW9jj185BSySqCWG/T7oZRSXYisAy10zOVWGbbCs6i/Dk8yDA82 kcDVhZqbmh2eFEHTZztfs0LgTKl5onG12a0L1GuYRh5r3u1wwlYIG7coTKjuwx0TQ/YArm 4QlvaIQVRenQgE1+bP+Cl/HMRd93dLkh3+UVDwkQSrX2zj5AAcRzK6uYhA9wwg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686296859; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9P87doE6Z0HH3lUedPUa2tyR5oQm9EuwPpj3rRLBwbI=; b=Y2CRn8IEwyUA1qprseFGMQb2DMHoqIIHfhUyaNm9y9t192bnqrwmDJCq5C8RWjsR1mUho+ 7MoK7asZaqqEi7CQ== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Tidy elf.h Cc: Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <168629685929.404.5936123077928755991.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767341178746080889?= X-GMAIL-MSGID: =?utf-8?q?1768210601255615430?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: 809373e17b2649948cc681dd1962b2736b22c7a6 Gitweb: https://git.kernel.org/tip/809373e17b2649948cc681dd1962b2736b22c7a6 Author: Josh Poimboeuf AuthorDate: Tue, 30 May 2023 10:20:53 -07:00 Committer: Josh Poimboeuf CommitterDate: Wed, 07 Jun 2023 10:03:13 -07:00 objtool: Tidy elf.h Reorganize elf.h a bit: - Move the prototypes higher up so they can be used by the inline functions. - Move hash-related code to the bottom. - Remove the unused ELF_HASH_BITS macro. No functional changes. Link: https://lore.kernel.org/r/b1490ed85951868219a6ece177a7cd30a6454d66.1685464332.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- tools/objtool/include/objtool/elf.h | 96 +++++++++++++--------------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index 78e2d0f..b24f83e 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -83,8 +83,6 @@ struct reloc { bool jump_table_start; }; -#define ELF_HASH_BITS 20 - struct elf { Elf *elf; GElf_Ehdr ehdr; @@ -110,53 +108,6 @@ struct elf { struct symbol *symbol_data; }; -#define OFFSET_STRIDE_BITS 4 -#define OFFSET_STRIDE (1UL << OFFSET_STRIDE_BITS) -#define OFFSET_STRIDE_MASK (~(OFFSET_STRIDE - 1)) - -#define for_offset_range(_offset, _start, _end) \ - for (_offset = ((_start) & OFFSET_STRIDE_MASK); \ - _offset >= ((_start) & OFFSET_STRIDE_MASK) && \ - _offset <= ((_end) & OFFSET_STRIDE_MASK); \ - _offset += OFFSET_STRIDE) - -static inline u32 sec_offset_hash(struct section *sec, unsigned long offset) -{ - u32 ol, oh, idx = sec->idx; - - offset &= OFFSET_STRIDE_MASK; - - ol = offset; - oh = (offset >> 16) >> 16; - - __jhash_mix(ol, oh, idx); - - return ol; -} - -static inline u32 reloc_hash(struct reloc *reloc) -{ - return sec_offset_hash(reloc->sec, reloc->offset); -} - -/* - * Try to see if it's a whole archive (vmlinux.o or module). - * - * Note this will miss the case where a module only has one source file. - */ -static inline bool has_multiple_files(struct elf *elf) -{ - return elf->num_files > 1; -} - -static inline int elf_class_addrsize(struct elf *elf) -{ - if (elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32) - return sizeof(u32); - else - return sizeof(u64); -} - struct elf *elf_open_read(const char *name, int flags); struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr); @@ -186,6 +137,24 @@ struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *se unsigned long offset, unsigned int len); struct symbol *find_func_containing(struct section *sec, unsigned long offset); +/* + * Try to see if it's a whole archive (vmlinux.o or module). + * + * Note this will miss the case where a module only has one source file. + */ +static inline bool has_multiple_files(struct elf *elf) +{ + return elf->num_files > 1; +} + +static inline int elf_class_addrsize(struct elf *elf) +{ + if (elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32) + return sizeof(u32); + else + return sizeof(u64); +} + #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list) @@ -198,4 +167,33 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset); for_each_sec(file, __sec) \ sec_for_each_sym(__sec, sym) +#define OFFSET_STRIDE_BITS 4 +#define OFFSET_STRIDE (1UL << OFFSET_STRIDE_BITS) +#define OFFSET_STRIDE_MASK (~(OFFSET_STRIDE - 1)) + +#define for_offset_range(_offset, _start, _end) \ + for (_offset = ((_start) & OFFSET_STRIDE_MASK); \ + _offset >= ((_start) & OFFSET_STRIDE_MASK) && \ + _offset <= ((_end) & OFFSET_STRIDE_MASK); \ + _offset += OFFSET_STRIDE) + +static inline u32 sec_offset_hash(struct section *sec, unsigned long offset) +{ + u32 ol, oh, idx = sec->idx; + + offset &= OFFSET_STRIDE_MASK; + + ol = offset; + oh = (offset >> 16) >> 16; + + __jhash_mix(ol, oh, idx); + + return ol; +} + +static inline u32 reloc_hash(struct reloc *reloc) +{ + return sec_offset_hash(reloc->sec, reloc->offset); +} + #endif /* _OBJTOOL_ELF_H */