Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3891063pxb; Tue, 17 Nov 2020 06:18:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbyLFLVg2rppnkTrZmrpCQ7f6xrnpAfNVb9g+jgX9xPJl8wDhsG33RNvx9fyCzS5rZnars X-Received: by 2002:a50:8745:: with SMTP id 5mr20652344edv.49.1605622725298; Tue, 17 Nov 2020 06:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622725; cv=none; d=google.com; s=arc-20160816; b=fC/iHCA52uGH4h8pIMNIvGA3iwOnn+iFM6CBJbOK7mSt0dexrnAQcRquTc+VKXEPk5 Mwtlub3IbwPV/eOD6GWQqE/I7Wd3ar6PryndoMudpxk25QQr7fKYRvwLd/JnLoXdshXW 952g8jxGsKZoWn85gcDbEjkgRPuD7KRKGHnRHQvR2SyOc+t5rSRtVKkTuR5Fq6PHyxfT NT+ceRykLTaQtg2UYcfGT+OXp2Aw4GXXOSyJVOSDBnOsd3Us78q0oQohPqX7rF3ifU4/ AyTYWENdPlD3ufYNvGWKt1WNdteXLntacvm87isX5Aq0tSYtNMZdHS0apnTsI7Qw1eKu gjKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=q7Gb00X+ptAC3NjXV7qpuGuBhy2o+Fp5qVIv8aCY5T4=; b=FyXdXscwckVsyUo+/10+DtTx7qnEqlNQHyLYf9sx9+9o9KNIyeM4qaPlYhXHd1fmxk XsUiqWdmQxy+zS2svk8zgYsRWgp3m0Fd8+vSRHmYC5okG/9fvuD280GDAH3SkUaCnXpB 2fkin9Sr7ag8jhv5saFy9Rlg/Ye83w2fBpCrwdZ2a5ys4YZu+TOeAjMMRKqe1GAG323S 7L3tTpgTOv2ajX0KV0C4VmUKiOyYsgJl0fcjqFmfW9t/xwC4/G/5ENzfMbGCZiPyg3GC jutXsJMusJSDsteMkXBA4gpeFrD9Hgpl9MhoZCZQ2jMBwWWCiF0sgZe9V0xom02qtVpB 6FmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RcMovvYw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n11si1610528eji.197.2020.11.17.06.18.21; Tue, 17 Nov 2020 06:18:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RcMovvYw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732370AbgKQNdM (ORCPT + 99 others); Tue, 17 Nov 2020 08:33:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:43034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732360AbgKQNdD (ORCPT ); Tue, 17 Nov 2020 08:33:03 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 764A62078E; Tue, 17 Nov 2020 13:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619984; bh=VpdT9lKyqfpBIjmn8GlbyElO6RyekOFckXcwyTx1sQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RcMovvYwYnQhHdRlckbt2Z8RzFKqOkFVOP2GfB/JBQc5FOGb4tCEIXrtEFOLL8OQC 23rpXdGufdhiAz16jl6VLsmzha4mgHLX57bXMGcslkGmb4zNYJ9xbfgPsWqPfmN26x UiRomyCXzL6sgl2v+exz1MgN2D8OA+FJ5zHA6LA0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Palmer Dabbelt , Sasha Levin Subject: [PATCH 5.9 070/255] RISC-V: Fix the VDSO symbol generaton for binutils-2.35+ Date: Tue, 17 Nov 2020 14:03:30 +0100 Message-Id: <20201117122142.358536689@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Palmer Dabbelt [ Upstream commit c2c81bb2f69138f902e1a58d3bef6ad97fb8a92c ] We were relying on GNU ld's ability to re-link executable files in order to extract our VDSO symbols. This behavior was deemed a bug as of binutils-2.35 (specifically the binutils-gdb commit a87e1817a4 ("Have the linker fail if any attempt to link in an executable is made."), but as that has been backported to at least Debian's binutils-2.34 in may manifest in other places. The previous version of this was a bit of a mess: we were linking a static executable version of the VDSO, containing only a subset of the input symbols, which we then linked into the kernel. This worked, but certainly wasn't a supported path through the toolchain. Instead this new version parses the textual output of nm to produce a symbol table. Both rely on near-zero addresses being linkable, but as we rely on weak undefined symbols being linkable elsewhere I don't view this as a major issue. Fixes: e2c0cdfba7f6 ("RISC-V: User-facing API") Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 18 +++++++++--------- arch/riscv/kernel/vdso/so2s.sh | 6 ++++++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100755 arch/riscv/kernel/vdso/so2s.sh diff --git a/arch/riscv/kernel/vdso/.gitignore b/arch/riscv/kernel/vdso/.gitignore index 11ebee9e4c1d6..3a19def868ecc 100644 --- a/arch/riscv/kernel/vdso/.gitignore +++ b/arch/riscv/kernel/vdso/.gitignore @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only vdso.lds *.tmp +vdso-syms.S diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile index 7d6a94d45ec94..cb8f9e4cfcbf8 100644 --- a/arch/riscv/kernel/vdso/Makefile +++ b/arch/riscv/kernel/vdso/Makefile @@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so SYSCFLAGS_vdso.so.dbg = $(c_flags) $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE $(call if_changed,vdsold) +SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ + -Wl,--build-id -Wl,--hash-style=both # We also create a special relocatable object that should mirror the symbol # table and layout of the linked DSO. With ld --just-symbols we can then # refer to these symbols in the kernel code rather than hand-coded addresses. - -SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ - -Wl,--build-id=sha1 -Wl,--hash-style=both -$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE - $(call if_changed,vdsold) - -LDFLAGS_vdso-syms.o := -r --just-symbols -$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE - $(call if_changed,ld) +$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE + $(call if_changed,so2s) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S @@ -73,6 +68,11 @@ quiet_cmd_vdsold = VDSOLD $@ $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \ rm $@.tmp +# Extracts symbol offsets from the VDSO, converting them into an assembly file +# that contains the same symbols at the same offsets. +quiet_cmd_so2s = SO2S $@ + cmd_so2s = $(NM) -D $< | $(srctree)/$(src)/so2s.sh > $@ + # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@ cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@ diff --git a/arch/riscv/kernel/vdso/so2s.sh b/arch/riscv/kernel/vdso/so2s.sh new file mode 100755 index 0000000000000..e64cb6d9440e7 --- /dev/null +++ b/arch/riscv/kernel/vdso/so2s.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2020 Palmer Dabbelt + +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)\(@@LINUX_4.15\)*!.global \2\n.set \2,0x\1!' \ +| grep '^\.' -- 2.27.0