Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp740091imm; Fri, 3 Aug 2018 10:40:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeQ2lCXQtRKwFETC1UOXOT3pWwZ/zVu5NK3AvCsnpwSHBuUl8Bsn7XHoOEL17w/0Ls5q6YP X-Received: by 2002:a17:902:262:: with SMTP id 89-v6mr4391434plc.221.1533318040745; Fri, 03 Aug 2018 10:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533318040; cv=none; d=google.com; s=arc-20160816; b=anJ1KXoD5ePk1rLD7FcjQNcW63idfrMZ85vJpXqT0++hEy300pEEL543Hs2MZh/MiF RKDC9yguKGQFocedMTohOZjwTM5Dw+kyZHZ0LtYeeuCkZjBqpE8bOMSWNLgAtHq7bXXm Tp9DvlTpn0WV9g32CLyGIzRt9c9AYV37o5I9RyJhkaVZXEFYZ/x9C24Gg5Y4PNw87Yiq HxCtb16W3e3H6ejDHTYrqTsyQjDVxgNqsjLvnRqmbHvKuvt88+x1OXqs+vJ08LxMq96s fOdkaMn2+fSbQQhOktRboIfjAAe+8feUDkhb49m6GASX1Y2kMfHzgpiej/zweGTKJ/sE xwHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature:arc-authentication-results; bh=SfASL4WVP4AoU489Xfidj2MP5Y9bShGHEOW26RWa2mo=; b=AbCsIGny+7TNagPvUgfG2ZAAGT5LY/Z3JK3l/dObUTb18K7lbmNhteg3jj21tCEawt 189Pez0124AVZ+cx1gHvqyj7U9Io9emdn3k+eFIghzd2qDorWE0qzklYsg6EYH/vx0qM xf3xLu56/HuS3Pr8pLXj0eEDz978C+d325UJYSRcpN+OSzFL+WIekH4Ry4WYrCFHyUjZ I6Nx5XNihtTuvW6TcYz+n0WYKXBgsDQAS7Te9+laC+o84HrXMhhMzLt25p6zIc/cAx4o 6S9WTYi8rQ/CUVd/V9PVF+H/AWnr5pnktxje8wuac/YwOQHKVPjon5srouloPU+q7Op+ m4iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fzetkwo+; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9-v6si5402876pgj.70.2018.08.03.10.40.25; Fri, 03 Aug 2018 10:40:40 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=fzetkwo+; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729825AbeHCTgv (ORCPT + 99 others); Fri, 3 Aug 2018 15:36:51 -0400 Received: from mail-ua0-f201.google.com ([209.85.217.201]:35697 "EHLO mail-ua0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728300AbeHCTgv (ORCPT ); Fri, 3 Aug 2018 15:36:51 -0400 Received: by mail-ua0-f201.google.com with SMTP id l22-v6so3057566uak.2 for ; Fri, 03 Aug 2018 10:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=SfASL4WVP4AoU489Xfidj2MP5Y9bShGHEOW26RWa2mo=; b=fzetkwo+Q7nxgMpyYnqtmrMYw3Kn8KeXn7MowGRVFHaO7PXPzSdL3jYoBuT6u4mZ8C GW2z0wyWtMteMZ2MgwHCowBMun+8QPkrvvmh7EelUoNLji1+e5x1A5ZQdelmbNCQEdXv ofFKp6MSdIfI3OVq6BJfRa8eJzyE12ptWhLnPfRcghyvB+8elxmhNpZKCrNyvGk+hqC2 z8WdTB8ldzgMgy4F7HR22Q9Qv43DjTxm4eR8wiqZMBgzrC0DIhmkjnTrl2LU4yWZQdaj r5B/GjXoz8rQ4WfQ4oNP+MOA57QQbR3QTTsqVUZniVPucwIalmsYQIhW59Vp+w4pdEkm Z9QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=SfASL4WVP4AoU489Xfidj2MP5Y9bShGHEOW26RWa2mo=; b=X51cw9yDwjXvJI1cB/yp0DalzdTNtTkxoV7W2GeUtHzZ8lT1yxg1o/jVMHfBCgmoTJ AbsWPis7d0WHRHUe9XYpZNo/M79TdtARbeSvDhyR8lH/bXSk+mltmseytMxQzWL5IYJ4 A6iL2kUB797fISmJjbYuGxse25+f1Rm6fBeelM9Uc297qJc3FII0XxGzTBdRQ9P7dT1q 1CMg7fRbA6S8qvhAhRRgWUB5K1zf92EgN/6okyhqgUMwQBoE85oB3EmVOISGG6jjNiCV GpKnJ1l6ywGgUiPFcPZR9p0yd3kzM3lsZvej+gtTYs0H9AB7blwIzlA33XwC7jkcziiW /f1g== X-Gm-Message-State: AOUpUlGmp4CVHFZmTgjmdzP+RzYGU17mYKygH3X+7f4EJV5KF7bzEivF hT02kzZBdU4zbQgMEDtyycdLCpQh/jU94gKUvPPFbqZE0FTdT+fqfZ3aPJfEXTpSe2uonRnbf9V im9HhJn1yzjtU+cDaUW4y9/QPKDlcv+vWMS9xLcI/+tXpR+hwzPEtuKq5CatsB+tl3/EpwQ1fXf c7Cw== X-Received: by 2002:a1f:64f:: with SMTP id 76-v6mr3775618vkg.49.1533317973760; Fri, 03 Aug 2018 10:39:33 -0700 (PDT) Date: Fri, 3 Aug 2018 10:39:31 -0700 Message-Id: <20180803173931.117515-1-astrachan@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog Subject: [PATCH v2] x86: vdso: Use $LD instead of $CC to link From: Alistair Strachan To: linux-kernel@vger.kernel.org Cc: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Greg Kroah-Hartman , x86@kernel.org, kernel-team@android.com, joel@joelfernandes.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The vdso{32,64}.so can fail to link with CC=clang when clang tries to find a suitable GCC toolchain to link these libraries with. /usr/bin/ld: arch/x86/entry/vdso/vclock_gettime.o: access beyond end of merged section (782) This happens because the host environment leaked into the cross compiler environment due to the way clang searches for suitable GCC toolchains. Clang is a retargetable compiler, and each invocation of it must provide --target= --gcc-toolchain= to allow it to find the correct binutils for cross compilation. These flags had been added to KBUILD_CFLAGS, but the vdso code uses CC and not KBUILD_CFLAGS (for various reasons) which breaks clang's ability to find the correct linker when cross compiling. Most of the time this goes unnoticed because the host linker is new enough to work anyway, or is incompatible and skipped, but this cannot be reliably assumed. This change alters the vdso makefile to just use LD directly, which bypasses clang and thus the searching problem. The makefile will just use ${CROSS_COMPILE}ld instead, which is always what we want. This matches the method used to link vmlinux. This change drops references to DISABLE_LTO; this option doesn't seem to be set anywhere, and not knowing what its possible values are, it's not clear how to convert it from CC to LD flag. Cc: Andy Lutomirski Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Greg Kroah-Hartman Cc: x86@kernel.org Cc: kernel-team@android.com Cc: joel@joelfernandes.org Signed-off-by: Alistair Strachan Acked-by: Andy Lutomirski --- v2: Updated changelog and rediffed Supersedes "x86: vdso: Fix leaky vdso link with CC=clang" arch/x86/entry/vdso/Makefile | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index 261802b1cc50..42c6c1bea4f4 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -46,10 +46,8 @@ targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so) CPPFLAGS_vdso.lds += -P -C -VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \ - -Wl,--no-undefined \ - -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \ - $(DISABLE_LTO) +VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \ + -z max-page-size=4096 -z common-page-size=4096 $(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE $(call if_changed,vdso) @@ -95,10 +93,8 @@ CFLAGS_REMOVE_vvar.o = -pg # CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds) -VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \ - -Wl,-soname=linux-vdso.so.1 \ - -Wl,-z,max-page-size=4096 \ - -Wl,-z,common-page-size=4096 +VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \ + -z max-page-size=4096 -z common-page-size=4096 # x32-rebranded versions vobjx32s-y := $(vobjs-y:.o=-x32.o) @@ -123,7 +119,7 @@ $(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE $(call if_changed,vdso) CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds) -VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1 +VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1 targets += vdso32/vdso32.lds targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o @@ -157,13 +153,13 @@ $(obj)/vdso32.so.dbg: FORCE \ # The DSO images are built using a special linker script. # quiet_cmd_vdso = VDSO $@ - cmd_vdso = $(CC) -nostdlib -o $@ \ + cmd_vdso = $(LD) -nostdlib -o $@ \ $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ - -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ + -T $(filter %.lds,$^) $(filter %.o,$^) && \ sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \ - $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS) +VDSO_LDFLAGS = -shared $(call ld-option, --hash-style=both) \ + $(call ld-option, --build-id) -Bsymbolic GCOV_PROFILE := n #