Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7732117rwb; Tue, 6 Dec 2022 09:10:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5XrFCUb/qLJ91NRovhUDFtTYMIjCEBaiCSpE6lW2i37Msen6sVONv03J9G4/h7mh6rAOG4 X-Received: by 2002:aa7:cc04:0:b0:463:1a0c:4dd1 with SMTP id q4-20020aa7cc04000000b004631a0c4dd1mr71029216edt.137.1670346600249; Tue, 06 Dec 2022 09:10:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670346600; cv=none; d=google.com; s=arc-20160816; b=zd3VlN/Y8WZxhn2UFF6We5SqUMYL5L/F8qe0m8OM0Al6krlxP3+Hr1DO/cAI6FZmco 7ztbqFJQ7PT6FoHgu4GFe2jqDcVmIQOxiwzkkYkqRIn3ibZL0QCjsR7ksvz1Vjw3N4jX 0p9Xp8QnDFO7W76lWQneOWu/B0vkweP5D9ODBSb0h9AcJGj/mmGbAzxH7CUtvrtyhr+a NaByCLqsnfBcfkGb5tDScMemcKk/ihumLrUZLGX/1WmVvcHMZHqLJprVAE28VCJaUoX5 r306C4TOERc6BJqT6DuY0aQAjRvoAVIB02sB29+UShlVZNw33maoxDbytk92NMTb1jDb mRBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ykhgd4nkvv5YkwiVgLi5ckjLW82QhWG9e0bvPRFkwiA=; b=cZeisxwcBq+MuGiXWDqjx4xaWClM7xz6uzIV7FatZV1sTfLH30BrxmFfyUq9++jWfM SGpHcbPH7RVZ+iWUIKeoWzJQeoWUgTTEGqxF/9VzqIvXp/lDAitkWeo2A6Pu1q6VVFZX taNL4ckjuO7UvaHSfYQNjtMfBYA2CI2EqNo4T/+nGDx2A+8fwHAz2KVwaFszS7Qfg68Z fd9mWFVFcBh4xv9GLHY9pDFqVv4QZljpaSlao4OwUzErgQ9CO5SKbqdR6EYj2VIU+Kvp ab7P3c6y/Hsf3Tdz4c/1xdgzU4O/T/5Ji5gqV0zYcKzg2TkHFYlT195wVsUj7HdalPfC d1Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Sa6OFIzB; 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 y2-20020a056402358200b0046d1a7ffa67si2067522edc.115.2022.12.06.09.09.41; Tue, 06 Dec 2022 09:10:00 -0800 (PST) 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=Sa6OFIzB; 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 S234508AbiLFRDt (ORCPT + 78 others); Tue, 6 Dec 2022 12:03:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234207AbiLFRDb (ORCPT ); Tue, 6 Dec 2022 12:03:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3094F60C9 for ; Tue, 6 Dec 2022 09:03:30 -0800 (PST) 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 A84B2617DE for ; Tue, 6 Dec 2022 17:03:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A31E7C433D6; Tue, 6 Dec 2022 17:03:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670346209; bh=cfYW1byqkMwLKYDFGfM1WhEMyq4FB1S0nFAddEHLuYo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Sa6OFIzBio19cJzqDyx3HZ4wADsqG5dqXyVrg0MdpPVov+0QAtv1XQukIt+oo6YzV zcmS540xD1oEgbfONVIz3k8OJz//DJWUBx6qtX/yhZHHojpRo/NoPbgSUSCS647jsg eG6tLYyeF0gqn02oD0VA5Ha4ChCbMbNlE4VbObCExD4NtDt7mR+gprwpIxzVjvPBjZ c8KIgOU/VbcrUy9LciuNpKf2xb/rSqWx9r+LEHTFIwHPLmn2nWqPAYt9Wb+NXPmevS P96KqhPuGDwIZ2TtYFVxNnuRzuI20wvm65+6NOd03TrVhNZQSK+AulyActiBZ52y27 z0Fa9j6nZOtog== Date: Tue, 6 Dec 2022 10:03:26 -0700 From: Nathan Chancellor To: Mikhail Zhilkin Cc: Miquel Raynal , kernel test robot , llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org, NOGUCHI Hiroshi Subject: Re: ld.lld: error: undefined symbol: __udivdi3 Message-ID: References: <202212010140.pIueEBNb-lkp@intel.com> <20221201091610.524f7786@xps-13> <20221201171331.42f05097@xps-13> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.1 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 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 Hi Mikhail, First and foremost, apologies for the delay in my response! On Thu, Dec 01, 2022 at 09:39:22PM +0300, Mikhail Zhilkin wrote: > Hi Miqu?l, Nathan, > > On 12/1/2022 7:13 PM, Miquel Raynal wrote: > > Hi Nathan, > > > > nathan@kernel.org wrote on Thu, 1 Dec 2022 09:00:57 -0700: > > > >> On Thu, Dec 01, 2022 at 09:16:10AM +0100, Miquel Raynal wrote: > >>> Hi Mikhail, Hiroshi, > >>> > >>> lkp@intel.com wrote on Thu, 1 Dec 2022 01:46:36 +0800: > >>> > >>>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master > >>>> head: 01f856ae6d0ca5ad0505b79bf2d22d7ca439b2a1 > >>>> commit: 9b78ef0c7997052e9eaa0f7a4513d546fa17358c mtd: parsers: add support for Sercomm partitions > >>>> date: 6 months ago > >>>> config: mips-randconfig-r033-20221128 > >>>> compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6e4cea55f0d1104408b26ac574566a0e4de48036) > >>>> reproduce (this is a W=1 build): > >>>> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > >>>> chmod +x ~/bin/make.cross > >>>> # install mips cross compiling tool for clang build > >>>> # apt-get install binutils-mipsel-linux-gnu > >>>> # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9b78ef0c7997052e9eaa0f7a4513d546fa17358c > >>>> git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git > >>>> git fetch --no-tags linus master > >>>> git checkout 9b78ef0c7997052e9eaa0f7a4513d546fa17358c > >>>> # save the config file > >>>> mkdir build_dir && cp config build_dir/.config > >>>> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash > >>>> > >>>> If you fix the issue, kindly add following tag where applicable > >>>> | Reported-by: kernel test robot > >>>> > >>>> All errors (new ones prefixed by >>): > >>>> > >>>>>> ld.lld: error: undefined symbol: __udivdi3 > >>>> >>> referenced by scpart.c > >>>> >>> mtd/parsers/scpart.o:(scpart_parse) in archive drivers/built-in.a > >>>> > >>> Can you please try to reproduce this with a mips toolchain as advised > >>> and send a fix? > >> For what it's worth, this is likely our bug: > >> > >> https://github.com/ClangBuiltLinux/linux/issues/1635 > >> > >> It sounds like there are some merged LLVM patches that should help but I > >> guess not based on this report... > > Ah, yeah, thanks a lot for the share. > > > > Cheers, Miqu?l > > I could reproduce the issue and found that reference to __udivdi3 > appears in this function: > > static uint32_t scpart_desc_is_valid(struct sc_part_desc *pdesc) > { > return ((pdesc->part_id != 0xffffffffUL) && > (pdesc->part_offs != 0xffffffffUL) && > (pdesc->part_bytes != 0xffffffffUL)); > } > > There is no LLVM compiler error if: > > static uint32_t scpart_desc_is_valid(struct sc_part_desc *pdesc) > { > return (0); > } > > Currently I have no ideas where does __udivdi3 come from, because > there's no division here. Should I try to rewrite somehow the function > to avoid the error? > I would greatly appreciate any ideas. I do not think it is that function that is causing the problem. Making it return zero just causes the code generation to change enough to avoid this issue. Based on the previous analysis and reduction [1], LLVM is transforming the for loop in scpart_scan_partmap() into division; you can verify this by commenting it out some way then rebuilding and running 'readelf -s' to look for __udivdi3. Arnd suggested working around this problem by making offs a 32-bit type, as it is already bounded by ->erasesize, which appears to be a 32-bit value from what I can tell. Making a change like so appears to resolve the issue for me but I am not sure if that has any other implications. diff --git a/drivers/mtd/parsers/scpart.c b/drivers/mtd/parsers/scpart.c index 02601bb33de4..6e5e11c37078 100644 --- a/drivers/mtd/parsers/scpart.c +++ b/drivers/mtd/parsers/scpart.c @@ -50,7 +50,7 @@ static int scpart_scan_partmap(struct mtd_info *master, loff_t partmap_offs, int cnt = 0; int res = 0; int res2; - loff_t offs; + uint32_t offs; size_t retlen; struct sc_part_desc *pdesc = NULL; struct sc_part_desc *tmpdesc; [1]: https://github.com/ClangBuiltLinux/linux/issues/1635 Cheers, Nathan