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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B60F0C636CC for ; Wed, 8 Feb 2023 08:27:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230376AbjBHI1l (ORCPT ); Wed, 8 Feb 2023 03:27:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230373AbjBHI1j (ORCPT ); Wed, 8 Feb 2023 03:27:39 -0500 Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48A47457C2 for ; Wed, 8 Feb 2023 00:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1675844855; bh=+2J469dohyjlak5iPQx/w6sbyFoadZoRv4g88y0JLtU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=NfoA4oqLm7u/obUTCasF6heQxMdccUAAggvyoTcNpCEA9dpkhxCZuwbF5Z11NvoGO eg0BOhj8+XHkE4sg7jqprxkaq/inLgghXjLkCy41QdnhK73C86yhUFR0rCrv6vJHFn smzcs/Cu13P3huiqLqaRY+PQAWkcki7sA72igqag= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 556EA667AF; Wed, 8 Feb 2023 03:27:34 -0500 (EST) Message-ID: <87b9f23ba8b123a765c4139c2112aa365546c1e5.camel@xry111.site> Subject: Re: [PATCH v2 0/5] LoongArch: Add kernel relocation and KASLR support From: Xi Ruoyao To: Youling Tang Cc: Jinyang He , Huacai Chen , Xuerui Wang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Date: Wed, 08 Feb 2023 16:27:31 +0800 In-Reply-To: <70278d23-aa0e-19d9-796f-78c0fd06fee0@loongson.cn> References: <20230207142822.52172-1-xry111@xry111.site> <70278d23-aa0e-19d9-796f-78c0fd06fee0@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2023-02-08 at 12:37 +0800, Youling Tang wrote: > In the case of "[Patch v2 2/5] LoongArch: use la.pcrel instenad of > la.abs for exception handlerS", the above failure will occur. >=20 > Patch2 may have certain problems when using the old toolchains. >=20 > Youling. Thanks for the test... The problem is: old toolchain uses pcaddu12i/ori/lu32i.d/lu52i.d/add.d for a 3-operand la.pcrel, while the new toolchain uses pcalau12i/addi.d/lu32i/lu52i/add.d. (I've somehow forgotten all the difference!) We can fix it with something like... > +void reloc_handler(unsigned long handler, struct handler_reloc *rel) > +{ > + if (!rel) > + return; > + > + for (unsigned long i =3D 0; i < rel->cnt; i++) { > + unsigned long pc =3D handler + rel->entries[i].offset; > + unsigned long v =3D rel->entries[i].sym; /* anchor etc. moved into do_reloc_pcalau12i */ > + union loongarch_instruction *insn =3D > + (union loongarch_instruction *)pc; switch insn[0]->reg1i20_format->reg1i20_format { case pcaddu12i_op: do_reloc_pcaddu12i(insn, pc, v); break; case pcalau12i_op: /* TODO: add it for asm/inst.h */ do_reloc_pcalau12i(insn, pc, v); break; default: panic("what the f**k"); } Alternatively, we can also emit the pcalau12i/addi.d/lu32i/lu52i sequence and overwrite the pcaddu12i/ori sequence generated by the old toolchain. Which way do you like? --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University