Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4825571rwd; Tue, 30 May 2023 10:23:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lwQSGLZPhniJewFIqXh9G8QVjcZhX0gcrjsBGOmP2+AG7LxkubnkjPhGC86x3PWnLH9yL X-Received: by 2002:a05:6a20:7346:b0:10a:f8d3:2cf3 with SMTP id v6-20020a056a20734600b0010af8d32cf3mr3719591pzc.7.1685467387567; Tue, 30 May 2023 10:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685467387; cv=none; d=google.com; s=arc-20160816; b=RmuBI3Tqdhpkpsps2/4zYdjCdzpEZGakOx7P/G+wCRx/grN7UApLhkyoOjMrzlWwNT CqmrT/Iy2XCqFkYqQmwTymhrW9WPhzy6+zHXUr41vMQhp0OR102nXmPmmgSM6A2JnXWR 0Z/gtQG9B0/Vm/GhAyrVNW3hqu6lnVf2xKYwzjAyW/L4hpBwFYHNf6MiDZ7D9KdO95Ac 3FGnRFX4HBmOe39rVPiCR7avEHd4Lo6zmSzdHlLpZKNGLyY0+Jic/P9c5pTCcQng9mxS hvTTFS31kJI7bVQibojSsGto2OcfQNbD3bGch3dsoe8RKkEuCB4Z/LBaj9/wwYHQVbP+ ufkA== 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=tk7bN7n5UdJSBsGXqvrCS95jIAuNM/X0LTBXXC9bdLc=; b=VzctRtuAPgp3W8SaH9xNieN3o1hJjjr7irhHZqW8cWMVtWuEYX68GjkNaT6FkL7Yvo tP0kd1+Nqt0Vc8veK3XK0LXEYuUSbvzp8lbc7CXUeYX4S00fKn7nd2xYX0dvlltYDHEb K0cY8u7wkvdICmxqR8D4Rclj4iX6Fl99lxHIkWzDLwwRWgL+vzXySyNZClULAe512qSB EGfmeJ2DqKPj77YqewjJ/UdM1mqUcMNP3vLPz+1ST6kC+KQIylGF8tUh/oTLtGo5+nWE R64MaUsvtJssCj3kR8wmrzOx04nWmZIZF/A1dVJJy061xdniJugR+RKGRa3JsWAfvfFt OotA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OxnUPmim; 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 m23-20020a638c17000000b0051b70ce7dd2si4325215pgd.80.2023.05.30.10.22.52; Tue, 30 May 2023 10:23:07 -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=OxnUPmim; 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 S232634AbjE3RVi (ORCPT + 99 others); Tue, 30 May 2023 13:21:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231264AbjE3RVe (ORCPT ); Tue, 30 May 2023 13:21:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52A0BB2 for ; Tue, 30 May 2023 10:21:33 -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 DDB18630F9 for ; Tue, 30 May 2023 17:21:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C719C4339C; Tue, 30 May 2023 17:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685467292; bh=f0Zkn5jXIKjGAYlwWWUPP5ioQ2KYARa2dNntzf0AIO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OxnUPmimkmalR7CDQ193rpnYzskhU71pNu8Ny++TNm7eT6EqNSDLRfiYNd9Mj0ylC I6sBD8RFM5j3uqSR4FV+i/usidJaTzssrGZIeEvu37HTTyEGWTLmv0NxtgVHuH7xw4 HRCPIm1fpqe9okZaLaSNpRhI9t5K8+LZ7vzttJdBU2swXxPUM3gS+9qSoy0ssUsZnf 5xPA19iWudGVHk0kWFyt3dU/W4RZprl8YqoN/SkPdL66wOab2dzTieX/6hkJQgiEh7 NOx0iz0j75lIo63SgJTdjfyBCnJSAGkNaY3MDsWATHcpsqdgnolYZgqgWjG4Wd3taA 16F0RUzzrQ3PQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH 01/22] objtool: Tidy elf.h Date: Tue, 30 May 2023 10:20:53 -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=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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. 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 78e2d0fc21ca..b24f83e7ca34 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 */ -- 2.40.1