Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1048449imm; Wed, 18 Jul 2018 15:43:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpelPHtf8TmgSmU11V+eO+tjBUlf6KYpFaHCye0tNCFPTBGNLZ3OcBzN7Q9DMjm/YeDDdp9k X-Received: by 2002:a17:902:8c84:: with SMTP id t4-v6mr7793374plo.100.1531953787758; Wed, 18 Jul 2018 15:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531953787; cv=none; d=google.com; s=arc-20160816; b=e3IvCbeM8SOb30SqkcCsVR//n+Y2vn1kAjME7D/kXP1ARGZmaooWffACtjmXJsFIOr gg+Y2AjBGz1hkxH/68jVzMWgaRi44x2ffuiD75vmnAmDRdWJi9oYDzcyjm82RXRW2zoR RsD5NQ9HXiauKEV8qHX5ZXclkxh2JFQNrN8w40tN3B26F4hos+2dhcVgxyNmQXj9BXJ7 Ou7hPkil48l2ECLOJXSHzQfoEFeJ2qW0JrCa29OgjV6QnoHECB3zV8bMjpDH1G7lPP8Z Kii7OzjMlZkC2wPDgPM07McVb9VkeYbL4ht5qxfIOiybn61SU8fj7FLQq4s/qOM0l0wB EEJw== 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:message-id:date :mime-version:dkim-signature:arc-authentication-results; bh=/SXidF8hAXshqkiFbGoLk/sQ+aaGc8icFptsQuMCA0M=; b=ejN7K+hpbbTbUh1k3cvouwG6QbcZI008Xp+YOwfWyoBXVE8Ki5vK5uxDaAN/xHhF9j y5YyhkbVQbNzUTM1+CJgC4PXowmtbGHR9IfupTI1y3hZPbcrUPTP/3O4TjyxIfR9+iw5 5yJs/stCDIWs2K3WEn4YkfGZSm9njSSQQOMQZOdNLMXIoiJLo4Sq7pVSEMp/oHmO5TId ai/4InfuGT7oZUl0pJDv8Q24YijEBLHcvRfS0DKbBm4MLT46OgXxpyfi4WZVsExNsxi8 FSJTpecrgn8T+ASPslHzUSw9RsP3wFZ6n5gARBjYPsn1UpKgAgMWDPM0WsLj8x0ZQHNy V9kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RZEl1589; 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 c192-v6si4289761pfg.347.2018.07.18.15.42.52; Wed, 18 Jul 2018 15:43:07 -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=RZEl1589; 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 S1729989AbeGRXWG (ORCPT + 99 others); Wed, 18 Jul 2018 19:22:06 -0400 Received: from mail-it0-f73.google.com ([209.85.214.73]:41761 "EHLO mail-it0-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729235AbeGRXWG (ORCPT ); Wed, 18 Jul 2018 19:22:06 -0400 Received: by mail-it0-f73.google.com with SMTP id h26-v6so3968265itj.6 for ; Wed, 18 Jul 2018 15:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to:cc; bh=/SXidF8hAXshqkiFbGoLk/sQ+aaGc8icFptsQuMCA0M=; b=RZEl1589f3jm9MF2c55+cO06KecxJbXsgUBYOrJJvwzZe86uXsDri3nu5F0jIGcJtj bRpwH0LgJaj+L9D4kzrDELKzojKi/z1xSWOK/abERUtktG/vudlekDhF8koqjbcOjrOG RupHib+v5XQHT2aihzCTF8QzkRi/bUvb57uRyuwrpkY7liKJaQSPORtVVnvbfaZAMwCx oL9AjQHyv3oWUC4Ho6JUAsWKpbSVGmvGR6wT5V34V0LTMh1VMQSUjRNWxbaUGBOxBovU tZO+TZ4hJME/EdH3D4i+PFN4eCbvMe2MxDVGhpBns/VP7bqjbb9a9iKBIhR34JG6qcBU NIwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=/SXidF8hAXshqkiFbGoLk/sQ+aaGc8icFptsQuMCA0M=; b=Tc/rtL7tVquACrpAoqJi4JQ39Rd6Kue+1JpW/yUYik9GA8YrX6G8RTxHmgpIe4BVlm YaON1Jkx5eXmkR7j+Fme507DTGRGx+i55xgnJqacLMcjbIdmLW2GPJPKrsixHC+5YJWg GdGOBAIpO6YQDGHaZtRPJtvIAL4OEXk00vnKqyWpaJ5yzZxe+lYy0c9HkVFm0BD/aMF0 eX0kpQ/EBr/y/8/gMpnG83CYnEkZcWOk4bL6uIMpitqZNlfegbWiZQOSH6LptmVZpdfw 802+3WYSyJzweh0MeCe4yPUOa9dtS3W/dA9KKQ+c6q5C98gFg7QHBPbX0Kw11sOyaC+o AGHg== X-Gm-Message-State: AOUpUlFRJJH9nKW027dc1Wph5e97J4+17dOvXQJgqgnJ6Lqu+OClj7jC AORxAkCONhtUyZh8G6bxgiaZfzFvmVlS9KLVqhSMrNfwfX1fAigXD3xjUGImk+Bk1jCVgKd8bN+ ungvRkG2yLmAWLdY7IBtM/GJsQF3KFRWGl9wAAJmVrtAFZyMa5XooA6vJISC9l7aMvgu779gCya MBrw== MIME-Version: 1.0 X-Received: by 2002:a24:1f46:: with SMTP id d67-v6mr1906148itd.49.1531953722265; Wed, 18 Jul 2018 15:42:02 -0700 (PDT) Date: Wed, 18 Jul 2018 15:41:59 -0700 Message-Id: <20180718224159.18236-1-astrachan@google.com> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog Subject: [PATCH] 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.com 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. 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.com Signed-off-by: Alistair Strachan --- 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 1943aebadede..896a55204386 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -48,10 +48,8 @@ targets += $(vdso_img_sodbg) export 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: $(src)/vdso.lds $(vobjs) FORCE $(call if_changed,vdso) @@ -97,10 +95,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 # 64-bit objects to re-brand as x32 vobjs64-for-x32 := $(filter-out $(vobjs-nox32),$(vobjs-y)) @@ -128,7 +124,7 @@ $(obj)/vdsox32.so.dbg: $(src)/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 @@ -162,13 +158,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 #