Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp144923imn; Fri, 29 Jul 2022 02:34:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sBethGi7v6m8dIllWUa1wHzQgPaCO+Qxh4C7+1gyamQ6NypaFkofX2nT7TUZ0lSnGkyyVF X-Received: by 2002:a63:69c3:0:b0:411:9d19:ff13 with SMTP id e186-20020a6369c3000000b004119d19ff13mr2317036pgc.34.1659087253515; Fri, 29 Jul 2022 02:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659087253; cv=none; d=google.com; s=arc-20160816; b=npQO4Uv1yOR6yLBn9USWgJtsrHdOkG0xPzmrnqFHDzSS8rr1QdktDrqgDj6E39YJbF UYMxuRnwwYCrkbFnWkWmtTf2NKR+sa/XeEM1T03rXMnGuSb6O+/GJDhIxt4hAdV7wqXv tdD9TEgCbWEdLQaQMQv09i3z5yRzBu7cpiIOK7PU4KsKenvETNlC683eEncEVsGbh8/p SQFvKbHCkXsTG5Yq86JC/HZug4hH6lkcZ+CPu/VGpTQ0kiy6wWfMms2SehNNk3JBoc8p 1rZEvzakM6VMPsop8mArChyCtRUza6kWfninrZvp1FUcz89XcOn732jEszMSCxTLs1pO cNZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:date:cc:to:from:subject:message-id :dkim-signature; bh=ehBxrq4lnWe48vuhq5dR3ntOZSN1NBYbY06zQVOr654=; b=NvsWxZtTt3TYoKrXSp0woB5EOv9DC1AjuxPOJEt8eOa+4eg6WlVn16VNO6+qNkg41K svzDuq4UitDr2qNPD8kRiaW/DacLDsnxcWGYUsks52N1GSqkLL2L1L+XYjua3YAJqiNj if3RpZImUK3wLK26jM8Q3a2gfyKnvjqDCd4u+WjwvgY3ymUy/xe4Sosowa9fs7qGjQMp zx9b4PkqCsBD1MqSkRGY1HhiUOFlBed9gvVEMxXCojAHtNL9RQH36xLbr7raVnthNa57 Mea/bBtNoqdkSITfDoWdvbYfd9jfXG/tf23MeZEABQnlCxBrq9imUG3jEzkCHDTPhOPi HPlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=FUPN6Cpc; 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=REJECT sp=REJECT dis=NONE) header.from=xry111.site Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lr15-20020a17090b4b8f00b001f291c80d40si8333982pjb.12.2022.07.29.02.33.58; Fri, 29 Jul 2022 02:34:13 -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=@xry111.site header.s=default header.b=FUPN6Cpc; 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=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235025AbiG2Iix (ORCPT + 99 others); Fri, 29 Jul 2022 04:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233362AbiG2Iiv (ORCPT ); Fri, 29 Jul 2022 04:38:51 -0400 Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1C1963C2 for ; Fri, 29 Jul 2022 01:38:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1659083925; bh=nhRJetfqLKjmUCbDBNY/1f03LEEuOrUUxiVJylmuTJE=; h=Subject:From:To:Cc:Date:From; b=FUPN6Cpcxd7PojPojV6dE7ZyP1ozEemFkP/TZvrTC9cJwmTdB2ehw5D6zz21VxfkV R0QrPz/6vaAcqfXrA84ZZ1d8ayALTh+y+IiP3qZCiEj3GiAd1cX61IrC54bTJulrOj PPQ1g6inqJxLLcRKfK8uAh4rZTAP//RHm53LCnVE= 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 972CE669EA; Fri, 29 Jul 2022 04:38:43 -0400 (EDT) Message-ID: <32a74a218c76611f897fd1df1ad0059068621133.camel@xry111.site> Subject: [PATCH v4 0/4] LoongArch: Support new relocation types From: Xi Ruoyao To: loongarch@lists.linux.dev Cc: linux-kernel@vger.kernel.org, WANG Xuerui , Huacai Chen , Youling Tang , Jinyang He Date: Fri, 29 Jul 2022 16:38:41 +0800 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.3 MIME-Version: 1.0 X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, FROM_SUSPICIOUS_NTLD_FP,PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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 The version 2.00 of LoongArch ELF ABI specification introduced new relocation types, and the development tree of Binutils and GCC has started to use them. If the kernel is built with the latest snapshot of Binutils or GCC, it will fail to load the modules because of unrecognized relocation types in modules. Add support for GOT and new relocation types for the module loader, so the kernel (with modules) can be built with the "normal" code model and function properly. This series does not break the compatibility with old toolchain using stack-based relocation types, so with the patches applied the kernel can be be built with both old and new toolchains. Tested by building the kernel with both Binutils & GCC master branch and my system Binutils & GCC (without new relocation type support), running both the builds with 35 in-tree modules loaded, and loading one module with 20 GOT loads (loaded addresses verified by comparing with /proc/kallsyms). Changes from v3 to v4: - No code change. Reword the commit message of the 3rd patch again based on suggestion from Huacai. Changes from v2 to v3: - Use `union loongarch_instruction` instead of explicit bit shifts applying the relocation. Suggested by Youling. - For R_LARCH_B26, move the alignment check before the range check to be consistent with stack pop relocations. Suggested by Youling. - Reword the commit message of the 3rd patch. Suggested by Huacai. Changes from v1 to v2: - Fix a stupid programming error (confusion between the number of PLT entries and the number of GOT entries). (Bug spotted by Youling). - Synthesize the _GLOBAL_OFFSET_TABLE_ symbol with module.lds, instead of faking it at runtime. The 3rd patch from V1 is now merged into the 1st patch because it would be a one-line change. (Suggested by Jinyang). - Keep reloc_rela_handlers[] ordered by the relocation type ID. (Suggested by Youling). - Remove -fplt along with -Wa,-mla-* options because it's the default. (Suggested by Youling). Xi Ruoyao (4): LoongArch: Add section of GOT for kernel module LoongArch: Support R_LARCH_SOP_PUSH_GPREL relocation type in kernel module LoongArch: Remove -fplt and -Wa,-mla-* from CFLAGS LoongArch: Support modules with new relocation types arch/loongarch/Makefile | 4 -- arch/loongarch/include/asm/elf.h | 37 ++++++++++ arch/loongarch/include/asm/module.h | 23 ++++++ arch/loongarch/include/asm/module.lds.h | 1 + arch/loongarch/kernel/head.S | 10 +-- arch/loongarch/kernel/module-sections.c | 51 +++++++++++-- arch/loongarch/kernel/module.c | 96 +++++++++++++++++++++++++ 7 files changed, 209 insertions(+), 13 deletions(-) --=20 2.37.0