Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp817043pxf; Thu, 25 Mar 2021 14:55:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQcXoDWJw1TxvfUO9lDBxLk66CpXZsjKtJqDxNoAJR74uofdpOsBlAp15o3IDmlNQ3ieak X-Received: by 2002:a17:906:7e12:: with SMTP id e18mr12331732ejr.316.1616709313332; Thu, 25 Mar 2021 14:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616709313; cv=none; d=google.com; s=arc-20160816; b=t8mI8kYG0WkUwlm4Da/f1CHSZkuEn7q9vWkJADzW8u3cZVCGzdkurjr9xufnIfTdf3 2jbBk1cCww/bsgRxM+CVckJEXj0fAxqU3nZkh+Hu2xxBQlVE7lGx2RaH07xYNhXSA6UM za+e6zCt9bXoeraL3ic11blmprMUuQw7uSDsz98WpSB4hFDVWNJLEOlq9HhCjvg8Eoqv Km3+z5yQ4l9a3eUxkCJxKgciIZgrm+EAEDEBnvLVOT7PXFCV6cKGfTnHPofl4sBVufqd MrL0CsuH2vCvMSlBo3dDTX4Dl2u4P/0U+v2dVihxItcyt+hw5A7L4MzOnXTBcRP1+325 kfEQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=BCtG47frM2KZ5TS5cn5ecZV2baxTHH+HmXoc14Qe0mI=; b=MRDuO+CIniNZ/9H8MJXnH6iehFmyoIqoJMgT5BPIUdi3hhaWknktSD/GKJCyKp+7ia LxhtFwEAnN6stg01hGX+JZHCkXKAwovstqewwi/h9/ooFvfR5hK/Jxi8cSaLTtxi/n3E Y8iULATXgG6xGM4uLsRF8VU6hQ0H+k9t5ntrVHuhhJUiPIxVF3ynH44oh3TOb3fUunLx 03/AkbJBG8cQMS2bJ0+u8ZvPSA/tb+LGImd6QWgjTV3MGl0Q74zwt/mOfnuxAj9SHcZP 0fZO1Q9IrXVy87qZgf9iDSjBFXxVorZtnJ6bvTMdtq3gguAaz568VCurKcKStc2kpBep TmNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c4O6fgS9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si5717049edj.230.2021.03.25.14.54.51; Thu, 25 Mar 2021 14:55:13 -0700 (PDT) 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=k20201202 header.b=c4O6fgS9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbhCYVwW (ORCPT + 99 others); Thu, 25 Mar 2021 17:52:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:37840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbhCYVwP (ORCPT ); Thu, 25 Mar 2021 17:52:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 37C0C61A27; Thu, 25 Mar 2021 21:52:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616709135; bh=YtDhb3Z8cilmN9rnRVuyvYpXzUlic0PVSJKa43SR7pw=; h=From:To:Cc:Subject:Date:From; b=c4O6fgS9TGJZv9FSlb2zLmj1hrBLMBabLoEz40x7zGWV9vj0lWWdnr2KoqF8iW3CW UX4JmMqoedKAiMy1raldxlU0UPboSKnljxVq3AE2FNz5QOvE3sYZtFAFVHJSIZJ22Y rjAnCGARLNFDjwJcCg5JnY36hSv/mGOLIVsh+/SVCdP0lEqdsZpxL8qt1qOEBuiTyP KkFJySwbz/xeO0Jf3tOzv7yyua/CBSeS2eUaKjkAkWdMnB7qPsWGUWI6foCDwuYwDl br6c3wS9Hokiib/y9w11tQKW+oRZPTXIxFLhbPwJTuPMRYTl46+2ZSidnwIgtW1qoy q180k/Q4lgKwQ== From: Nathan Chancellor To: Palmer Dabbelt , Paul Walmsley , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Nathan Chancellor Subject: [PATCH] riscv: Use $(LD) instead of $(CC) to link vDSO Date: Thu, 25 Mar 2021 14:51:56 -0700 Message-Id: <20210325215156.1986901-1-nathan@kernel.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the VDSO is being linked through $(CC). This does not match how the rest of the kernel links objects, which is through the $(LD) variable. When linking with clang, there are a couple of warnings about flags that will not be used during the link: clang-12: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument] clang-12: warning: argument unused during compilation: '-pg' [-Wunused-command-line-argument] '-no-pie' was added in commit 85602bea297f ("RISC-V: build vdso-dummy.o with -no-pie") to override '-pie' getting added to the ld command from distribution versions of GCC that enable PIE by default. It is technically no longer needed after commit c2c81bb2f691 ("RISC-V: Fix the VDSO symbol generaton for binutils-2.35+"), which removed vdso-dummy.o in favor of generating vdso-syms.S from vdso.so with $(NM) but this also resolves the issue in case it ever comes back due to having full control over the $(LD) command. '-pg' is for function tracing, it is not used during linking as clang states. These flags could be removed/filtered to fix the warnings but it is easier to just match the rest of the kernel and use $(LD) directly for linking. See commits fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to link VDSO") 691efbedc60d ("arm64: vdso: use $(LD) instead of $(CC) to link VDSO") 2ff906994b6c ("MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO") 2b2a25845d53 ("s390/vdso: Use $(LD) instead of $(CC) to link vDSO") for more information. The flags are converted to linker flags and '--eh-frame-hdr' is added to match what is added by GCC implicitly, which can be seen by adding '-v' to GCC's invocation. Additionally, since this area is being modified, use the $(OBJCOPY) variable instead of an open coded $(CROSS_COMPILE)objcopy so that the user's choice of objcopy binary is respected. Link: https://github.com/ClangBuiltLinux/linux/issues/803 Link: https://github.com/ClangBuiltLinux/linux/issues/970 Signed-off-by: Nathan Chancellor --- arch/riscv/kernel/vdso/Makefile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile index 71a315e73cbe..ca2b40dfd24b 100644 --- a/arch/riscv/kernel/vdso/Makefile +++ b/arch/riscv/kernel/vdso/Makefile @@ -41,11 +41,10 @@ KASAN_SANITIZE := n $(obj)/vdso.o: $(obj)/vdso.so # link rule for the .so file, .lds has to be first -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=sha1 -Wl,--hash-style=both +LDFLAGS_vdso.so.dbg = -shared -s -soname=linux-vdso.so.1 \ + --build-id=sha1 --hash-style=both --eh-frame-hdr # 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 @@ -60,13 +59,10 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # actual build commands # The DSO images are built using a special linker script -# Add -lgcc so rv32 gets static muldi3 and lshrdi3 definitions. # Make sure only to export the intended __vdso_xxx symbol offsets. quiet_cmd_vdsold = VDSOLD $@ - cmd_vdsold = $(CC) $(KBUILD_CFLAGS) $(call cc-option, -no-pie) -nostdlib -nostartfiles $(SYSCFLAGS_$(@F)) \ - -Wl,-T,$(filter-out FORCE,$^) -o $@.tmp && \ - $(CROSS_COMPILE)objcopy \ - $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \ + cmd_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \ + $(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \ rm $@.tmp # Extracts symbol offsets from the VDSO, converting them into an assembly file -- 2.31.0