Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3927660rwe; Tue, 30 Aug 2022 01:00:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR4RPSavb/Chyzl4AUJSI+sbzGyTEZ0od/zfc3zUydOSvyJjnyWjYyBFzSST+YOjpi2ih2gz X-Received: by 2002:a05:6402:4301:b0:448:d506:e2e5 with SMTP id m1-20020a056402430100b00448d506e2e5mr886685edc.153.1661846433138; Tue, 30 Aug 2022 01:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661846433; cv=none; d=google.com; s=arc-20160816; b=dgI8wZI37S7LELyjYV+eNvP7TwcvPFgvgR7iDZ8RIQhwt0X9EBWRV4Z3Q9frqcLGPC rVxs2R2fW+CCppXexEReN4PgF+m2TMvHtzyBG51fEkdG/b2vXvAV0Qq8QZ+/ym5zU4f/ ZKGa90KnqHTAUJulYZD7XoL9ilIglO19RxLZE8x7kGefuP2o2QGcpDCzNJCZeFGRs0wC ZsLeVxeZw91ygXbTohb8QjnLLRwq0flY8BP7IcbEOTcTGRD1XeiPGOHGsFVB3WCpvwo0 JlNMDOCRP5MzGHizER4keIzAz9ar3EYumD8v9xdd3cbKtfbF6n4Nh/I5KwSKPcGxJ3RX XQ6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=R/j8lhuAf90+jalrFIjieosygO8NUgPBW1dH8HHGso0=; b=aBuZSNb4TOI7QR/Uc8GNWZjzgq77zEs/8unHJ0Lf7k3x3zw33xwMKSodP+DPL/XYu9 NYgTZ6SC5/b+Gp71mU22lbuJAoqukxBA30adGiQbTlrDpgkxaZ6g5iF52NgQn3XVTSkz 7AvadzsvG5H8NZ5tA6JlAVYqUNPnMLB72aodv3aHv/IDOnqwVVLgCh4YBpX1SLshhluP eUA6PeTd8VDZn5dAJ5tw2nyk32kziGiZP48Z5sodrmPyN4zrDO9h7pOm5gcCf2aB+cKN WkDI4SxxE6vIDSr+iit0w+j3wm/Pch8XMUDYG0pHwrcNXhtAbiKBtRHYc1LCdHtY1q8W oO0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c9uSxjfD; 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 m12-20020a50930c000000b004478be1775dsi7777685eda.114.2022.08.30.01.00.06; Tue, 30 Aug 2022 01:00:33 -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=c9uSxjfD; 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 S230077AbiH3HKt (ORCPT + 99 others); Tue, 30 Aug 2022 03:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230407AbiH3HKp (ORCPT ); Tue, 30 Aug 2022 03:10:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5985473329 for ; Tue, 30 Aug 2022 00:10:44 -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 ams.source.kernel.org (Postfix) with ESMTPS id 073E4B815DD for ; Tue, 30 Aug 2022 07:10:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9671DC433B5 for ; Tue, 30 Aug 2022 07:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661843441; bh=aUwZvFPgGPgQxLQm3ylFwunvJW/D4Qz/bEeYplvQR78=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=c9uSxjfDl4qaLcZ5MadHTwWSPttIIsyGGo1y4xC+NBR8tZYA3CxmYRCiCBPNTquC3 R8YxLsncJx0AFoFck02ZSI7FZ4SUi9ePD2hKJyhF/9OTl+ORliLaO+mPu7snTvDLnN mWR6d8YWFDL2bVgvlqlJnyIV+2HPdwB7vfmf3W0D8H5aGqX0wLSYg34dlMouF3aacN WIujNiA8fpmuKM38YpqRcFjUVg7PqtBvr1MM6YthTuZZ4U5gfGI/Z1J584Wp3YHGdN XRwKXSiqC2/VuCukQR27DmS2XbfPNu7WEFkAmR0Ho+SemFYw+Mr9kZMaslJWW5qUGj TNAPWA2MGiWRw== Received: by mail-vs1-f53.google.com with SMTP id n125so10622071vsc.5 for ; Tue, 30 Aug 2022 00:10:41 -0700 (PDT) X-Gm-Message-State: ACgBeo1H0a1vmoqdTyFIhS0Gs6muYX3eeKrgm7AfOs4JF1Txu6Vu3mfJ YeIbARwM5DIPvOCSO4yaWE24epc+Qkw4B7KXoYM= X-Received: by 2002:a05:6102:30bc:b0:390:da09:3a8c with SMTP id y28-20020a05610230bc00b00390da093a8cmr2867659vsd.84.1661843440489; Tue, 30 Aug 2022 00:10:40 -0700 (PDT) MIME-Version: 1.0 References: <20220829133146.15236-1-xry111@xry111.site> <20220829133146.15236-6-xry111@xry111.site> <4033aec9-8df5-53ae-59e1-9ec3ade5f6d7@xen0n.name> In-Reply-To: <4033aec9-8df5-53ae-59e1-9ec3ade5f6d7@xen0n.name> From: Huacai Chen Date: Tue, 30 Aug 2022 15:10:29 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 5/6] LoongArch: Support PC-relative relocations in modules To: WANG Xuerui Cc: Xi Ruoyao , loongarch@lists.linux.dev, LKML , Youling Tang , Jinyang He Content-Type: text/plain; charset="UTF-8" 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,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 On Tue, Aug 30, 2022 at 9:42 AM WANG Xuerui wrote: > > On 2022/8/29 23:08, Huacai Chen wrote: > > [snip] > >> +static int apply_r_larch_pcala(struct module *mod, u32 *location, Elf_Addr v, > >> + s64 *rela_stack, size_t *rela_stack_top, unsigned int type) > >> +{ > >> + union loongarch_instruction *insn = (union loongarch_instruction *)location; > >> + /* Use s32 for a sign-extension deliberately. */ > >> + s32 offset_hi20 = (void *)((v + 0x800) & ~0xfff) - > >> + (void *)((Elf_Addr)location & ~0xfff); > >> + Elf_Addr anchor = (((Elf_Addr)location) & ~0xfff) + offset_hi20; > >> + ptrdiff_t offset_rem = (void *)v - (void *)anchor; > >> + > >> + switch (type) { > >> + case R_LARCH_PCALA_HI20: > >> + v = offset_hi20 >> 12; > >> + break; > >> + case R_LARCH_PCALA64_LO20: > >> + v = offset_rem >> 32; > >> + break; > >> + case R_LARCH_PCALA64_HI12: > >> + v = offset_rem >> 52; > >> + break; > >> + default: > >> + /* Do nothing. */ > >> + } > >> + > >> + switch (type) { > >> + case R_LARCH_PCALA_HI20: > >> + case R_LARCH_PCALA64_LO20: > >> + insn->reg1i20_format.immediate = v & 0xfffff; > >> + break; > >> + case R_LARCH_PCALA_LO12: > >> + case R_LARCH_PCALA64_HI12: > >> + insn->reg2i12_format.immediate = v & 0xfff; > >> + break; > >> + default: > >> + pr_err("%s: Unsupport relocation type %u\n", mod->name, type); > >> + return -EINVAL; > >> + } > > Can we merge the two switch here? > > IMO leaving as-is or even splitting into two functions would be > acceptable, as the two switches are performing two different things -- > namely "adjustFixupValue" (in LLVM-speak) and actually inserting the > value into the insn word. But an argument for merging the two can be > made too, because the v2.00 reloc types are purposely designed with > unique use case for each, meaning there is actually no flexibility in > between the fixup value's calculation and application. So I think this > eventually comes down to coder's preference? Merging them can just make me understand the logic better, and save some lines. :) Huacai > > -- > WANG "xen0n" Xuerui > > Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/ >