From mboxrd@z Thu Jan 1 00:00:00 1970 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 AC46BECAAA1 for ; Sat, 3 Sep 2022 01:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230500AbiICB5P (ORCPT ); Fri, 2 Sep 2022 21:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbiICB5N (ORCPT ); Fri, 2 Sep 2022 21:57:13 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 974D4E114D for ; Fri, 2 Sep 2022 18:57:11 -0700 (PDT) Received: from [10.130.0.193] (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxvmtwtBJjM0UQAA--.57569S3; Sat, 03 Sep 2022 09:57:05 +0800 (CST) Subject: Re: [PATCH 1/3] LoongArch: tools: Add relocs tool support To: Xi Ruoyao , Huacai Chen References: <1662113335-14282-1-git-send-email-tangyouling@loongson.cn> <1662113335-14282-2-git-send-email-tangyouling@loongson.cn> <4df8a26c49a35c1fce36d80c370f738fa71a2bef.camel@xry111.site> Cc: linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, Xuerui Wang , Jiaxun Yang , Jinyang He From: Youling Tang Message-ID: Date: Sat, 3 Sep 2022 09:57:04 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <4df8a26c49a35c1fce36d80c370f738fa71a2bef.camel@xry111.site> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf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UU= X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Ruoyao On 09/02/2022 07:27 PM, Xi Ruoyao wrote: > On Fri, 2022-09-02 at 19:10 +0800, Xi Ruoyao wrote: >> Hi Youling, >> >> On Fri, 2022-09-02 at 18:08 +0800, Youling Tang wrote: >>> This tool is based on the arch/mips/boot/tools/relocs tool. >> >> I've dig some history of MIPS relocatable kernel >> (https://lwn.net/Articles/682020/): >> >> * Kernel is compiled & statically linked as normal, with no position >> independent code. MIPS before R6 only has limited relative jump >> instructions so the vast majority of jumps are absolute. To compile >> the kernel position independent would introduce a highly undesireable >> overhead. Relocating the static binary gives a small startup time >> penalty but the kernel otherwise perforns normally. >> >> Unlike (pre-r6) MIPS, LoongArch has a complete support for PIC, and >> currently LoongArch toolchain always produces PIC (except, if -Wa,-mla- >> {local,global}-with-abs or la.abs macros are used explicitly). >> >> So would it be easier to review and correct the uses of "la.abs" in the >> code, and make the main kernel image a real PIE? Then we can load it >> everywhere w/o any need to do relocation at load time. At the beginning I also wanted to make the main kernel image a real PIE and tried it, some of the "la.abs" can be modified, but I encountered difficulties in modifying the exception handling code part, the kernel will not boot after modification :(, I will continue to work hard try. I would be grateful if you all have better suggestions and ideas :). > > Arrgh, doing so will need to get rid of GOT (the GCC patch for this is > still under review) or we still need to relocate the GOT at least :(. Yes, now all global variable access is via got (la.got) in the new toolchain, so we need to relocate the GOT in relocate.c. However there is no need to relocate it in the old toolchain as it is accessed via la.pcrel. Thanks, Youling > >