Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4327854imm; Sat, 21 Jul 2018 16:30:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd1vqqzWe221/1BWirhSmhpH3Sbj8LH76WCi+FiLLXmRuTGY3pzdl8ZbPta/fQTc69sdFrq X-Received: by 2002:a62:6eca:: with SMTP id j193-v6mr7576592pfc.256.1532215823958; Sat, 21 Jul 2018 16:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532215823; cv=none; d=google.com; s=arc-20160816; b=R6Bxt9FyPCa/PtGxw/OhM4x48jrbPMBp4PgvRqhM1aQM8wRQs6mDxuMRVK7t7yAwkg 7khQ8uqt6osymI+bThApuLegOGC50FHhxN8MuwN2V827fudoNUx51HVlc8KvRxjgVr4G FDID8yCeEW1+KH0Sq2MJ+/2IO6T+MdXO9hDOWprnAB+wVLyMXEuM5f1VjvPdVReWA4s9 ywSUX2ZIOmbVtnweh2+t7gTOEtXGyj+W/4/ozol8pqmnWGz8vRljxchy2wllPlqG52hW WkvjPdJijqUCHEc2gotN6pOcvSSID9Wcf+wWmv0qNZQLA7Elr4JcxmOYyDJ4/z+ETMfN BFcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=9UyAFlOB6pLl269jVnNwEBeJDVrMv1ya7Y5q6/uuN5w=; b=QWKjnc7RaD2m3PYJZv7tVVMagAB1hJTxMMEZkGp65/lgnvm7/7StIkV8AM8SE9/Zs9 9Kl7N0SbD1JyrIgzcQEdshu2SFkmBCBU/Wb9GYMQGBV9T6MUriy+qtSFwDoYt6QGBwkG +C3mdlX8rXba5tK66Fh/4B0F95FyfJNTDGusw4k2+qsWz5lg8J6fAEur11rXe4xx2qKF LGM4IipUqle0gqat7wcJSO9mHR1O55ZNSY5nXPEeQ05YsGjuMA6V+OE4XJjAomnX9fQH e9EsnJ17abH6YYM7O6WV5xEcg6Arsy1jKVs9/RyJAiV8Kzlm9LFqYBIpgaRucoIx3Mx2 jHhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="gf/Xw1Zy"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j67-v6si5245440pfg.34.2018.07.21.16.30.09; Sat, 21 Jul 2018 16:30:23 -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=@kernel.org header.s=default header.b="gf/Xw1Zy"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728271AbeGVAXs (ORCPT + 99 others); Sat, 21 Jul 2018 20:23:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:41482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728145AbeGVAXr (ORCPT ); Sat, 21 Jul 2018 20:23:47 -0400 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DD69520856 for ; Sat, 21 Jul 2018 23:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1532215758; bh=GmpP38JKyuO2NM1CDT/Loh2aFcVZegE/jFmJbIL5YDA=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=gf/Xw1ZyfRUxHrFIjF2GS6SZATYAyHvqA3NDi5VxsSNfGGGBj9bxjf9PiylR8Fhim AKTcK9mJrxBL9J3/wBsn1v9h0XHQBbk2S5pQI4lxezdtOSzcU4a9iCYODpa0ixPgji HJp+HWmKuZlM8EkjwnZTemclazhdH3W7VfI+AlRQ= Received: by mail-wr1-f44.google.com with SMTP id g6-v6so14438619wrp.0 for ; Sat, 21 Jul 2018 16:29:17 -0700 (PDT) X-Gm-Message-State: AOUpUlH7fchcMk9+hiDilXRoMMF30FUt24Zqu8otjoc3N9akCbYuajrT WUuy3V0xXAp+ESHjip5bKEnTDcyTkM4WD8vfc9RlPw== X-Received: by 2002:adf:8325:: with SMTP id 34-v6mr4675246wrd.67.1532215756363; Sat, 21 Jul 2018 16:29:16 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:d548:0:0:0:0:0 with HTTP; Sat, 21 Jul 2018 16:28:55 -0700 (PDT) In-Reply-To: <20180718224159.18236-1-astrachan@google.com> References: <20180718224159.18236-1-astrachan@google.com> From: Andy Lutomirski Date: Sat, 21 Jul 2018 16:28:55 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86: vdso: Use $LD instead of $CC to link To: Alistair Strachan Cc: LKML , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Greg Kroah-Hartman , X86 ML , Android Kernel Team , 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 On Wed, Jul 18, 2018 at 3:41 PM, Alistair Strachan wrote: > 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. Acked-by: Andy Lutomirski > > 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 > > #