From patchwork Fri Jul 7 05:40:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 13304451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF1E0EB64D9 for ; Fri, 7 Jul 2023 05:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Cc:MIME-Version:Message-ID:Date :Subject:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=44xmlN2+x0umoEJJ3JGu8x7jpevlGbcI+4X5DByznj4=; b=kh+dLAI9CFmjzy sJ8tsVx8kl5dH1sgil6TWv1Qx2NwBYn37ozv/IsZ/NTyTP5lfV23g9akl7b6Zd5K7QF61DrYjOvMs 1uVeSpjLk6kz7wHZw9U8L2De1YoHEVetAn0B6786WZz6enE0xxYumnZZxQP/Kzlpy/sTwQif2NcV6 NPkYyA5jmoNqY/7iQEdXfTLAx1hSO0+cz9ROeQGXOFi9Ec5w8/FmWPfDXgyNfWPU6bK+ujhqdplqH UoFxYAE7CfdPAQmqpq6y2F8MORPZ7TF+x2rfGqyJNjYkbIk0Tnb9KY7c3eFTiroV2A/Oyqf6Bpj4J QCepTXREdc6/n1xWIOkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHeJN-003f4H-2h; Fri, 07 Jul 2023 05:47:21 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHeJL-003f2J-1p for linux-riscv@lists.infradead.org; Fri, 07 Jul 2023 05:47:21 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6b7474b0501so1396690a34.1 for ; Thu, 06 Jul 2023 22:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1688708837; x=1691300837; h=to:from:cc:content-transfer-encoding:mime-version:message-id:date :subject:from:to:cc:subject:date:message-id:reply-to; bh=18JEHmCNriSXCt9lwVG1gdY95Ti8XFVzzNrMetTB3RE=; b=ogFntHJ6RxrAEPFVudPEAa0C385HOnOfUwce+99Yasx8myU/rGAYtZSCGU0Eg6ka2k fStAVEM215dE6taLQkpDCoVzX0gIBP50UI7H/XkVpcsDVTA90x0Sfgrc4Ft2KYz7AnKq RxFnRYV+MZVB5aSMSp7mFQQgunJ/v4Uemk3OuBWv+DLXyb9MDeP9aiPq6kNgqIUxOG+a +0WgAyvP2+nS43sXwUu2x16ezvod9el2VwCAHh4JvXyafuZMbmq/OVfpGtGrGZC6rlKD y0iO3BSK7iCLTf2qyZz3acrM6pKF7ZgTFb9VwN7JFN4JGrV+Sc8V38KYbGMY0lg1tGLm l+Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688708837; x=1691300837; h=to:from:cc:content-transfer-encoding:mime-version:message-id:date :subject:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=18JEHmCNriSXCt9lwVG1gdY95Ti8XFVzzNrMetTB3RE=; b=XEtr8+vt7uJN73izWoSx17yBcfalOQDqrDpcxEfr92d5Tfqt2utdV3SGn0BhPf6VBD 6Ja6xTM7gynTeX4ewIjqnv2Ke5wcYQmJCCCzvSVuG1hsZZBMtps1GltKRGFO0LMha9ci 7zhCM7JH47Ku2BgC1J5vXyegb2V8DZB+AMmT9EUfHCRR4tpaes+rPsP8586/9uwSCShz p66dbPAFg9bBmhLH+MpMEJa+Wmvb7LxAEX/lxS+DaHVUTw9kLxoRvEZFP50WcnvEr9mu Qu2CbycWl1T4LlDTYkL8Ex2bxmlEydqZrHW1Qij4fujcLzESDzr+QmmgGyc1JcNXxLn/ //1w== X-Gm-Message-State: ABy/qLamRO3v6GR23jaTwaNp1JdFcWwxKSPmL2bVpvtr/aAz2Zb7z956 JcC9T8rZ+8LzQr2IvGf4HLBxPyn5/i1xbiGxbuk= X-Google-Smtp-Source: APBJJlHUM5/Nf9hH+y4tg3FzZmGqyw1ddyEvNg72h5Yn0LMsT5qA1AMEzfyr6IZEBbt4CHH90jrmOg== X-Received: by 2002:a05:6870:d20e:b0:17a:c7ff:ccf5 with SMTP id g14-20020a056870d20e00b0017ac7ffccf5mr4889304oac.32.1688708837341; Thu, 06 Jul 2023 22:47:17 -0700 (PDT) Received: from localhost ([135.180.227.0]) by smtp.gmail.com with ESMTPSA id p16-20020a17090ad31000b00263fc1ef1aasm710558pju.10.2023.07.06.22.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 22:47:16 -0700 (PDT) Subject: [PATCH] module: Ignore RISC-V mapping symbols too Date: Thu, 6 Jul 2023 22:40:01 -0700 Message-ID: <20230707054007.32591-1-palmer@rivosinc.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt From: Palmer Dabbelt To: mcgrof@kernel.org, rdunlap@infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230706_224719_686747_D9625306 X-CRM114-Status: GOOD ( 19.83 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org RISC-V has an extended form of mapping symbols that we use to encode the ISA when it changes in the middle of an ELF. This trips up modpost as a build failure, I haven't yet verified it yet but I believe the kallsyms difference should result in stacks looking sane again. Reported-by: Randy Dunlap Link: https://lore.kernel.org/all/9d9e2902-5489-4bf0-d9cb-556c8e5d71c2@infradead.org/ Signed-off-by: Palmer Dabbelt Reviewed-by: Randy Dunlap Tested-by: Randy Dunlap # build-tested --- I'm not sure about a fixes here, the breakage comes from a binutils change that's pretty much independent from the kernel. Plumbing in through the RISC-V-specific switch is also a bit ugly, but I'm not sure just dropping everyone's "$"-prefixed symbols is a good idea -- the rest of this is sort of half-way arch-specific, though, so maybe that's the way to go? I figure it's easier to delete stuff than add it, though. --- include/linux/module_symbol.h | 12 +++++++++++- kernel/module/kallsyms.c | 8 +++++++- scripts/mod/modpost.c | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/linux/module_symbol.h b/include/linux/module_symbol.h index 7ace7ba30203..5b799942b243 100644 --- a/include/linux/module_symbol.h +++ b/include/linux/module_symbol.h @@ -3,12 +3,22 @@ #define _LINUX_MODULE_SYMBOL_H /* This ignores the intensely annoying "mapping symbols" found in ELF files. */ -static inline int is_mapping_symbol(const char *str) +static inline int is_mapping_symbol(const char *str, int is_riscv) { if (str[0] == '.' && str[1] == 'L') return true; if (str[0] == 'L' && str[1] == '0') return true; + /* + * RISC-V defines various special symbols that start with "$".  The + * mapping symbols, which exist to differentiate between incompatible + * instruction encodings when disassembling, show up all over the place + * and are generally not meant to be treated like other symbols.  So + * just ignore any of the special symbols. + */ + if (is_riscv) + return str[0] == '$'; + return str[0] == '$' && (str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x') && (str[2] == '\0' || str[2] == '.'); diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index ef73ae7c8909..1e988e542c5d 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -12,6 +12,12 @@ #include #include "internal.h" +#ifdef CONFIG_RISCV +#define IS_RISCV 1 +#else +#define IS_RISCV 0 +#endif + /* Lookup exported symbol in given range of kernel_symbols */ static const struct kernel_symbol *lookup_exported_symbol(const char *name, const struct kernel_symbol *start, @@ -289,7 +295,7 @@ static const char *find_kallsyms_symbol(struct module *mod, * and inserted at a whim. */ if (*kallsyms_symbol_name(kallsyms, i) == '\0' || - is_mapping_symbol(kallsyms_symbol_name(kallsyms, i))) + is_mapping_symbol(kallsyms_symbol_name(kallsyms, i), IS_RISCV)) continue; if (thisval <= addr && thisval > bestval) { diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index b29b29707f10..7c71429d6502 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1052,7 +1052,7 @@ static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym) if (!name || !strlen(name)) return 0; - return !is_mapping_symbol(name); + return !is_mapping_symbol(name, elf->hdr->e_machine == EM_RISCV); } /* Look up the nearest symbol based on the section and the address */