Received: by 10.213.65.68 with SMTP id h4csp219317imn; Tue, 13 Mar 2018 01:53:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELtV+X6IApp5n7XO/tfhlFjO3Dx8GjoOBhJkleIC5TljH5tAd/JD97tbEkYNlDnurxUoAVap X-Received: by 10.101.78.133 with SMTP id b5mr5315726pgs.229.1520931231455; Tue, 13 Mar 2018 01:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520931231; cv=none; d=google.com; s=arc-20160816; b=CjNZ7yxL1UqGdvd3PHAfiQpV//snm3rlM1TzljJnHTKbvJ3r8ZDNKG9y+t2d5HABoC klE08TQdnQYuC6JZi2LFjT4koU3Xau7JvZLjztbVQ9pPxBhEmfkaVbpwCtW6Z8400IjU qBcoJmmjZWTYCLNhWK+sBXK33uiQ14AbkHUVw7cobk+K6J9CuSMuXet5NlGG0vcxy42E c4yvfVZwoGepumO6ZxS6AWlJ79YUAD8Q31PE/8CvH671ScDKKFegEMb1DMFyifeexp9D /5OY9/1/jAvKoENKFSOhrHZ9t9c3Q9UoBv9g5hTOOXYO5mIstIC5tfCPzU0B2323iahM jnEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=7/E7PTkuQf3RfZPN52TXdvGVp5Rt3E/n0C1EgAnDp8E=; b=Ku8/Z3TysS2PpSvnxaW/3LwEAkS6GwoXIku/+U4J+h9MfOYpxLDlAD52b9MKG8P4OS qWG+T4tVNxYYz8Rs/pHiIiii57ru4eHsFSZwv/AzklcOdSx59rx46sf5fgu4jIP/YiUc S669uwAxDOi+nIvUDEWnLDEEI6GTDpsJee+jK5KI//veW1nH7Y1NJQL+D4/TBqVNwun+ iEUh9ribQy3FHokB6VLNS7MRkATz1cwHjjvNSbjapaP7NBxyR3HgpINaXayYfV/DR+iQ pLqD2Hryl6EQdDyHzdt3dR7L9YOD1an5qpqullyN1CvuTG/VapnOjv5DAfd346desmi7 ntXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z124si6214913pgb.811.2018.03.13.01.53.36; Tue, 13 Mar 2018 01:53:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752385AbeCMIvi (ORCPT + 99 others); Tue, 13 Mar 2018 04:51:38 -0400 Received: from exmail.andestech.com ([59.124.169.137]:25662 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932279AbeCMIs0 (ORCPT ); Tue, 13 Mar 2018 04:48:26 -0400 Received: from ATCSQR.andestech.com (localhost [127.0.0.2] (may be forged)) by ATCSQR.andestech.com with ESMTP id w2D8XaLu025130 for ; Tue, 13 Mar 2018 16:33:36 +0800 (GMT-8) (envelope-from zong@andestech.com) Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w2D8XFFS025056; Tue, 13 Mar 2018 16:33:15 +0800 (GMT-8) (envelope-from zong@andestech.com) Received: from atcsqa06.andestech.com (10.0.1.85) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Tue, 13 Mar 2018 16:36:42 +0800 From: Zong Li To: , , , , , CC: Subject: [PATCH 04/11] RISC-V: Support CALL relocation type in kernel module Date: Tue, 13 Mar 2018 16:35:09 +0800 Message-ID: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.1.85] X-DNSRBL: X-MAIL: ATCSQR.andestech.com w2D8XFFS025056 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Zong Li --- arch/riscv/kernel/module.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 242d3a14c210..7e85e5840b4d 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -141,6 +141,27 @@ static int apply_r_riscv_call_plt_rela(struct module *me, u32 *location, return 0; } +static int apply_r_riscv_call_rela(struct module *me, u32 *location, + Elf_Addr v) +{ + s64 offset = (void *)v - (void *)location; + s32 fill_v = offset; + u32 hi20, lo12; + + if (offset != fill_v) { + pr_err( + "%s: target %016llx can not be addressed by the 32-bit offset from PC = %p\n", + me->name, v, location); + return -EINVAL; + } + + hi20 = (offset + 0x800) & 0xfffff000; + lo12 = (offset - hi20) & 0xfff; + *location = (*location & 0xfff) | hi20; + *(location + 1) = (*(location + 1) & 0xfffff) | (lo12 << 20); + return 0; +} + static int apply_r_riscv_relax_rela(struct module *me, u32 *location, Elf_Addr v) { @@ -157,6 +178,7 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location, [R_RISCV_PCREL_LO12_S] = apply_r_riscv_pcrel_lo12_s_rela, [R_RISCV_GOT_HI20] = apply_r_riscv_got_hi20_rela, [R_RISCV_CALL_PLT] = apply_r_riscv_call_plt_rela, + [R_RISCV_CALL] = apply_r_riscv_call_rela, [R_RISCV_RELAX] = apply_r_riscv_relax_rela, }; -- 2.16.1