From patchwork Fri Jul 7 16:00:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 13305095 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 96738C001DE for ; Fri, 7 Jul 2023 16:03:10 +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=EnXAXuQC+WnRx5J1FiV+fVGdwhrX2HDyHhPhcRbkfaE=; b=S0AtCjs4X4Y/7P R8dRXVv9DBYxybwdJmM1yME+3c7ALkLtRCW6qPfsTHoaKwlgDa1mPgIOiiY/wQuT5kRDhkGXGcIYH jUtbnGLzGTzf7SIdhVHDSMOxfjjeNTTARECmeFHQot+CBJpgCQdOwTdgK+DpBH5lnliJZuZJCVCpY LeWmIMcimU/2yHbATbRM/m+PYBeTz7XONAIADfHo5T1Sa0sBSuoZnR/w4s1z8V4MwYc4hUiTJZUpb dZ6Hwvsb3os4dhjl/bZUNl2k+SNTws1d+SP5XJQiCQyOQfeXL8CF7bsz1MdIBHElYkKKAkO3p2ZpB jXm0BPMgYcwF4icIkLgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHnvG-0058Fa-2w; Fri, 07 Jul 2023 16:03:06 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHnvE-0058EF-18 for linux-riscv@lists.infradead.org; Fri, 07 Jul 2023 16:03:05 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b89e10d356so12071155ad.3 for ; Fri, 07 Jul 2023 09:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1688745782; x=1691337782; h=to:from:cc:content-transfer-encoding:mime-version:message-id:date :subject:from:to:cc:subject:date:message-id:reply-to; bh=kF0uQEN662Ylwi2u8B6YjR1hUODDsncC9aFANUny7O8=; b=cYoTElhkxPgxMxbMBtiYHiY7zIG+iRfcpLBx18CvRbyyrYJav4Qlg47Aj69t/rdGZj UPMEVD5biF0LlK2QptEmZgbDod1gpbFgcl4UFNF7c/xXBHa3QPeLiRlLu6g77JNm7dWi KV34YgdDOOywcumWNpQrGsqcp/x2cTkv33JUr1OmsyW7yhaRIhpxiqI9bkUzcrc0EwU6 Umcboojqup8T8nMnNl6M5MhaKyFDjKWiffKk8VFp6JsqIFw5zljomlNM9gU+F5yKGAoH Ym3KEsN0d3PF6VNryEYS1YQDXP/49075KvpKJrLQvKQZmsM8gJtC1HpkYwdUoxF35ARu q6ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688745782; x=1691337782; 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=kF0uQEN662Ylwi2u8B6YjR1hUODDsncC9aFANUny7O8=; b=BXtpg8u8u5dYudq6cFqYGlpCfREyFqFziXqFPImgQD7//vGc3MiE/xI4bSq6nmD4qe gaah32GeDch2kfIhuYG1hi3X3ki2hQyu/6MdNtP8pR89SLJw2sO2E3DDDRDCKw3qYaMy ubV2BpkHbeEtku+z/Pz3YOu43DTNDcXhzw8ABH2xB89qGvg0163kHHQR1m9wWz5RUAmn rth9aMrOHTkpHyQk4BsI7ARFrJynhwReWs4aIZNHi1mf8zcGfj9Ljl1RGBWXigxCkrp4 fdlUWrNR0euyll68E/fOJt6s1s1qWn1JvtqUudqqmzYpBLOmfBWrYrZSAnHJe6A2k7p9 dxDw== X-Gm-Message-State: ABy/qLZzcUkgnuxQQsWHTrR/kPeiJZFRMQrayBx+tQmZfNijxt3G2dUN i+uLbDSbaY5y8o/iTjS2Cr4iu8ULjzEFVRNIApc= X-Google-Smtp-Source: APBJJlGNN3z7qOn51JWWxegL0GEQ8tvT7dLoK6EFuISJia98DCx0aGARl5XCxRkkRmZuVvjqqBt/Eg== X-Received: by 2002:a17:902:d508:b0:1b8:4ec2:5200 with SMTP id b8-20020a170902d50800b001b84ec25200mr5567552plg.2.1688745782222; Fri, 07 Jul 2023 09:03:02 -0700 (PDT) Received: from localhost ([135.180.227.0]) by smtp.gmail.com with ESMTPSA id u2-20020a170902e80200b001b567bbe82dsm3454695plg.150.2023.07.07.09.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 09:03:01 -0700 (PDT) Subject: [PATCH v2] module: Ignore RISC-V mapping symbols too Date: Fri, 7 Jul 2023 09:00:51 -0700 Message-ID: <20230707160051.2305-2-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, thomas@t-8ch.de X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230707_090304_386792_7C087DF6 X-CRM114-Status: GOOD ( 15.68 ) 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 Closes: 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 --- Changes since v1 <20230707054007.32591-1-palmer@rivosinc.com/>: * Drop the unnecessary IS_RISCV define and just inline it. --- include/linux/module_symbol.h | 12 +++++++++++- kernel/module/kallsyms.c | 2 +- scripts/mod/modpost.c | 2 +- 3 files changed, 13 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..78a1ffc399d9 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -289,7 +289,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_ENABLED(CONFIG_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 */