linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: vdso: Use $LD instead of $CC to link
@ 2018-07-18 22:41 Alistair Strachan
  2018-07-21 23:28 ` Andy Lutomirski
  2018-08-03 10:26 ` Thomas Gleixner
  0 siblings, 2 replies; 4+ messages in thread
From: Alistair Strachan @ 2018-07-18 22:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Greg Kroah-Hartman, x86, kernel-team, joel

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=<something> --gcc-toolchain=<something> 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 <luto@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: x86@kernel.org
Cc: kernel-team@android.com
Cc: joel@joelfernandes.com
Signed-off-by: Alistair Strachan <astrachan@google.com>
---
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
 
 #

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86: vdso: Use $LD instead of $CC to link
  2018-07-18 22:41 [PATCH] x86: vdso: Use $LD instead of $CC to link Alistair Strachan
@ 2018-07-21 23:28 ` Andy Lutomirski
  2018-08-03 10:26 ` Thomas Gleixner
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Lutomirski @ 2018-07-21 23:28 UTC (permalink / raw)
  To: Alistair Strachan
  Cc: LKML, Andy Lutomirski, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, Greg Kroah-Hartman, X86 ML, Android Kernel Team,
	joel

On Wed, Jul 18, 2018 at 3:41 PM, Alistair Strachan <astrachan@google.com> 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=<something> --gcc-toolchain=<something> 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 <luto@kernel.org>



>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: x86@kernel.org
> Cc: kernel-team@android.com
> Cc: joel@joelfernandes.com
> Signed-off-by: Alistair Strachan <astrachan@google.com>
> ---
> 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
>
>  #

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86: vdso: Use $LD instead of $CC to link
  2018-07-18 22:41 [PATCH] x86: vdso: Use $LD instead of $CC to link Alistair Strachan
  2018-07-21 23:28 ` Andy Lutomirski
@ 2018-08-03 10:26 ` Thomas Gleixner
  2018-08-03 17:29   ` Alistair Strachan
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2018-08-03 10:26 UTC (permalink / raw)
  To: Alistair Strachan
  Cc: linux-kernel, Andy Lutomirski, Ingo Molnar, H. Peter Anvin,
	Greg Kroah-Hartman, x86, kernel-team, joel

On Wed, 18 Jul 2018, Alistair Strachan wrote:
>  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

Aside of the fact that it does not apply to upstream, why is this dropping
the $(DISABLE_LTO) part?

The changelog is utterly silent about that.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86: vdso: Use $LD instead of $CC to link
  2018-08-03 10:26 ` Thomas Gleixner
@ 2018-08-03 17:29   ` Alistair Strachan
  0 siblings, 0 replies; 4+ messages in thread
From: Alistair Strachan @ 2018-08-03 17:29 UTC (permalink / raw)
  To: tglx
  Cc: linux-kernel, luto, mingo, hpa, Greg Kroah-Hartman, x86,
	kernel-team, joel

On Fri, Aug 3, 2018 at 3:26 AM Thomas Gleixner <tglx@linutronix.de> wrote:
>
> On Wed, 18 Jul 2018, Alistair Strachan wrote:
> >  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
>
> Aside of the fact that it does not apply to upstream,

It seems to apply fine to Linus's tree (0585df4), but I'll send a v2
which is rediffed.

> why is this dropping
> the $(DISABLE_LTO) part?
>
> The changelog is utterly silent about that.

$ git grep DISABLE_LTO
arch/sparc/vdso/Makefile:KBUILD_CFLAGS += $(DISABLE_LTO)
arch/sparc/vdso/Makefile:                       $(DISABLE_LTO)
arch/x86/entry/vdso/Makefile:KBUILD_CFLAGS += $(DISABLE_LTO)
arch/x86/entry/vdso/Makefile:                   $(DISABLE_LTO)
kernel/Makefile:CFLAGS_sys_ni.o = $(DISABLE_LTO)
scripts/Makefile.build:cmd_cc_s_c       = $(CC) $(c_flags)
$(DISABLE_LTO) -fverbose-asm -S -o $@ $<

Looks like a dead option to me, but maybe somebody else knows better.
v2 will explain this removal.

> Thanks,
>
>         tglx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-03 17:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-18 22:41 [PATCH] x86: vdso: Use $LD instead of $CC to link Alistair Strachan
2018-07-21 23:28 ` Andy Lutomirski
2018-08-03 10:26 ` Thomas Gleixner
2018-08-03 17:29   ` Alistair Strachan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).