linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO
@ 2020-10-13  3:39 Nathan Chancellor
  2020-10-13 22:37 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nathan Chancellor @ 2020-10-13  3:39 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Masahiro Yamada
  Cc: Vincenzo Frascino, linux-arm-kernel, linux-kbuild, linux-kernel,
	clang-built-linux, Nathan Chancellor, Nick Desaulniers

As it stands now, the vdso32 Makefile hardcodes the linker to ld.bfd
using -fuse-ld=bfd with $(CC). This was taken from the arm vDSO
Makefile, as the comment notes, done in commit d2b30cd4b722 ("ARM:
8384/1: VDSO: force use of BFD linker").

Commit fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to
link VDSO") changed that Makefile to use $(LD) directly instead of
through $(CC), which matches how the rest of the kernel operates. Since
then, LD=ld.lld means that the arm vDSO will be linked with ld.lld,
which has shown no problems so far.

Allow ld.lld to link this vDSO as we do the regular arm vDSO. To do
this, we need to do a few things:

* Add a LD_COMPAT variable, which defaults to $(CROSS_COMPILE_COMPAT)ld
  with gcc and $(LD) if LLVM is 1, which will be ld.lld, or
  $(CROSS_COMPILE_COMPAT)ld if not, which matches the logic of the main
  Makefile. It is overrideable for further customization and avoiding
  breakage.

* Eliminate cc32-ldoption, which matches commit 055efab3120b ("kbuild:
  drop support for cc-ldoption").

With those, we can use $(LD_COMPAT) in cmd_ldvdso and change the flags
from compiler linker flags to linker flags directly. We eliminate
-mfloat-abi=soft because it is not handled by the linker.

Link: https://github.com/ClangBuiltLinux/linux/issues/1033
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

NOTE: This patch is currently based on the kbuild tree due to the
--build-id -> --build-id=sha1 change that Bill did. If the arm64
maintainers would prefer to take this patch, I can rebase it (althought
presumably this won't hit mainline until at least 5.11 so it can
probably just stay as is for now).

 arch/arm64/kernel/vdso32/Makefile | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index 7f96a1a9f68c..1cf00c58805d 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -22,16 +22,21 @@ endif
 
 CC_COMPAT ?= $(CC)
 CC_COMPAT += $(CC_COMPAT_CLANG_FLAGS)
+
+ifeq ($(LLVM),1)
+LD_COMPAT ?= $(LD)
+else
+LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
+endif
 else
 CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
+LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
 endif
 
 cc32-option = $(call try-run,\
         $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
 cc32-disable-warning = $(call try-run,\
 	$(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
-cc32-ldoption = $(call try-run,\
-        $(CC_COMPAT) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
 cc32-as-instr = $(call try-run,\
 	printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
 
@@ -122,14 +127,10 @@ dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
 VDSO_CFLAGS += $(dmbinstr)
 VDSO_AFLAGS += $(dmbinstr)
 
-VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
 # From arm vDSO Makefile
-VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
-VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
-VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
-VDSO_LDFLAGS += -Wl,--hash-style=sysv
-VDSO_LDFLAGS += -Wl,--build-id=sha1
-VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
+VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
+VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
+VDSO_LDFLAGS += -nostdlib -shared --hash-style=sysv --build-id=sha1
 
 
 # Borrow vdsomunge.c from the arm vDSO
@@ -189,8 +190,8 @@ quiet_cmd_vdsold_and_vdso_check = LD32    $@
       cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
 
 quiet_cmd_vdsold = LD32    $@
-      cmd_vdsold = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
-                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
+      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
+                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
 quiet_cmd_vdsocc = CC32    $@
       cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
 quiet_cmd_vdsocc_gettimeofday = CC32    $@

base-commit: 172aad81a882443eefe1bd860c4eddc81b14dd5b
-- 
2.29.0.rc0


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

* Re: [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO
  2020-10-13  3:39 [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO Nathan Chancellor
@ 2020-10-13 22:37 ` Nick Desaulniers
  2020-10-19  9:59 ` Vincenzo Frascino
  2020-10-20  1:14 ` [PATCH v2] " Nathan Chancellor
  2 siblings, 0 replies; 7+ messages in thread
From: Nick Desaulniers @ 2020-10-13 22:37 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Catalin Marinas, Will Deacon, Masahiro Yamada, Vincenzo Frascino,
	Linux ARM, Linux Kbuild mailing list, LKML, clang-built-linux

On Mon, Oct 12, 2020 at 8:41 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> As it stands now, the vdso32 Makefile hardcodes the linker to ld.bfd
> using -fuse-ld=bfd with $(CC). This was taken from the arm vDSO
> Makefile, as the comment notes, done in commit d2b30cd4b722 ("ARM:
> 8384/1: VDSO: force use of BFD linker").
>
> Commit fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to
> link VDSO") changed that Makefile to use $(LD) directly instead of
> through $(CC), which matches how the rest of the kernel operates. Since
> then, LD=ld.lld means that the arm vDSO will be linked with ld.lld,
> which has shown no problems so far.
>
> Allow ld.lld to link this vDSO as we do the regular arm vDSO. To do
> this, we need to do a few things:
>
> * Add a LD_COMPAT variable, which defaults to $(CROSS_COMPILE_COMPAT)ld
>   with gcc and $(LD) if LLVM is 1, which will be ld.lld, or
>   $(CROSS_COMPILE_COMPAT)ld if not, which matches the logic of the main
>   Makefile. It is overrideable for further customization and avoiding
>   breakage.
>
> * Eliminate cc32-ldoption, which matches commit 055efab3120b ("kbuild:
>   drop support for cc-ldoption").
>
> With those, we can use $(LD_COMPAT) in cmd_ldvdso and change the flags
> from compiler linker flags to linker flags directly. We eliminate
> -mfloat-abi=soft because it is not handled by the linker.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1033
> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Thanks for the patch and summary of related changes! This is
immediately useful for Android.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
> NOTE: This patch is currently based on the kbuild tree due to the
> --build-id -> --build-id=sha1 change that Bill did. If the arm64
> maintainers would prefer to take this patch, I can rebase it (althought
> presumably this won't hit mainline until at least 5.11 so it can
> probably just stay as is for now).
>
>  arch/arm64/kernel/vdso32/Makefile | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 7f96a1a9f68c..1cf00c58805d 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -22,16 +22,21 @@ endif
>
>  CC_COMPAT ?= $(CC)
>  CC_COMPAT += $(CC_COMPAT_CLANG_FLAGS)
> +
> +ifeq ($(LLVM),1)
> +LD_COMPAT ?= $(LD)
> +else
> +LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
> +endif
>  else
>  CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
> +LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
>  endif
>
>  cc32-option = $(call try-run,\
>          $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
>  cc32-disable-warning = $(call try-run,\
>         $(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
> -cc32-ldoption = $(call try-run,\
> -        $(CC_COMPAT) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
>  cc32-as-instr = $(call try-run,\
>         printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
>
> @@ -122,14 +127,10 @@ dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
>  VDSO_CFLAGS += $(dmbinstr)
>  VDSO_AFLAGS += $(dmbinstr)
>
> -VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
>  # From arm vDSO Makefile
> -VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
> -VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
> -VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
> -VDSO_LDFLAGS += -Wl,--hash-style=sysv
> -VDSO_LDFLAGS += -Wl,--build-id=sha1
> -VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
> +VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
> +VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
> +VDSO_LDFLAGS += -nostdlib -shared --hash-style=sysv --build-id=sha1
>
>
>  # Borrow vdsomunge.c from the arm vDSO
> @@ -189,8 +190,8 @@ quiet_cmd_vdsold_and_vdso_check = LD32    $@
>        cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
>
>  quiet_cmd_vdsold = LD32    $@
> -      cmd_vdsold = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
> -                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
> +      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
> +                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
>  quiet_cmd_vdsocc = CC32    $@
>        cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
>  quiet_cmd_vdsocc_gettimeofday = CC32    $@
>
> base-commit: 172aad81a882443eefe1bd860c4eddc81b14dd5b
> --
> 2.29.0.rc0
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO
  2020-10-13  3:39 [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO Nathan Chancellor
  2020-10-13 22:37 ` Nick Desaulniers
@ 2020-10-19  9:59 ` Vincenzo Frascino
  2020-10-20  1:07   ` Nathan Chancellor
  2020-10-20  1:14 ` [PATCH v2] " Nathan Chancellor
  2 siblings, 1 reply; 7+ messages in thread
From: Vincenzo Frascino @ 2020-10-19  9:59 UTC (permalink / raw)
  To: Nathan Chancellor, Catalin Marinas, Will Deacon, Masahiro Yamada
  Cc: linux-arm-kernel, linux-kbuild, linux-kernel, clang-built-linux,
	Nick Desaulniers


Hi Nathan,

On 10/13/20 4:39 AM, Nathan Chancellor wrote:
> As it stands now, the vdso32 Makefile hardcodes the linker to ld.bfd
> using -fuse-ld=bfd with $(CC). This was taken from the arm vDSO
> Makefile, as the comment notes, done in commit d2b30cd4b722 ("ARM:
> 8384/1: VDSO: force use of BFD linker").
> 
> Commit fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to
> link VDSO") changed that Makefile to use $(LD) directly instead of
> through $(CC), which matches how the rest of the kernel operates. Since
> then, LD=ld.lld means that the arm vDSO will be linked with ld.lld,
> which has shown no problems so far.
> 
> Allow ld.lld to link this vDSO as we do the regular arm vDSO. To do
> this, we need to do a few things:
> 
> * Add a LD_COMPAT variable, which defaults to $(CROSS_COMPILE_COMPAT)ld
>   with gcc and $(LD) if LLVM is 1, which will be ld.lld, or
>   $(CROSS_COMPILE_COMPAT)ld if not, which matches the logic of the main
>   Makefile. It is overrideable for further customization and avoiding
>   breakage.
> 
> * Eliminate cc32-ldoption, which matches commit 055efab3120b ("kbuild:
>   drop support for cc-ldoption").
> 
> With those, we can use $(LD_COMPAT) in cmd_ldvdso and change the flags
> from compiler linker flags to linker flags directly. We eliminate
> -mfloat-abi=soft because it is not handled by the linker.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/1033
> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Just a small nit on my side (see below) and as you already stated it requires
rebasing if we want to merge it in mainline. Otherwise:

Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>

> ---
> 
> NOTE: This patch is currently based on the kbuild tree due to the
> --build-id -> --build-id=sha1 change that Bill did. If the arm64
> maintainers would prefer to take this patch, I can rebase it (althought
> presumably this won't hit mainline until at least 5.11 so it can
> probably just stay as is for now).
> 
>  arch/arm64/kernel/vdso32/Makefile | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 7f96a1a9f68c..1cf00c58805d 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -22,16 +22,21 @@ endif
>  
>  CC_COMPAT ?= $(CC)
>  CC_COMPAT += $(CC_COMPAT_CLANG_FLAGS)
> +
> +ifeq ($(LLVM),1)

Nit: Here can we check 'ifneq ($(LLVM),)' for consistency with what the main
Makefile does?

> +LD_COMPAT ?= $(LD)
> +else
> +LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
> +endif
>  else
>  CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
> +LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
>  endif
>  
>  cc32-option = $(call try-run,\
>          $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
>  cc32-disable-warning = $(call try-run,\
>  	$(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
> -cc32-ldoption = $(call try-run,\
> -        $(CC_COMPAT) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
>  cc32-as-instr = $(call try-run,\
>  	printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
>  
> @@ -122,14 +127,10 @@ dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
>  VDSO_CFLAGS += $(dmbinstr)
>  VDSO_AFLAGS += $(dmbinstr)
>  
> -VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
>  # From arm vDSO Makefile
> -VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
> -VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
> -VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
> -VDSO_LDFLAGS += -Wl,--hash-style=sysv
> -VDSO_LDFLAGS += -Wl,--build-id=sha1
> -VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
> +VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
> +VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
> +VDSO_LDFLAGS += -nostdlib -shared --hash-style=sysv --build-id=sha1
>  
>  
>  # Borrow vdsomunge.c from the arm vDSO
> @@ -189,8 +190,8 @@ quiet_cmd_vdsold_and_vdso_check = LD32    $@
>        cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
>  
>  quiet_cmd_vdsold = LD32    $@
> -      cmd_vdsold = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
> -                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
> +      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
> +                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
>  quiet_cmd_vdsocc = CC32    $@
>        cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
>  quiet_cmd_vdsocc_gettimeofday = CC32    $@
> 
> base-commit: 172aad81a882443eefe1bd860c4eddc81b14dd5b
> 

-- 
Regards,
Vincenzo

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

* Re: [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO
  2020-10-19  9:59 ` Vincenzo Frascino
@ 2020-10-20  1:07   ` Nathan Chancellor
  0 siblings, 0 replies; 7+ messages in thread
From: Nathan Chancellor @ 2020-10-20  1:07 UTC (permalink / raw)
  To: Vincenzo Frascino
  Cc: Catalin Marinas, Will Deacon, Masahiro Yamada, linux-arm-kernel,
	linux-kbuild, linux-kernel, clang-built-linux, Nick Desaulniers

On Mon, Oct 19, 2020 at 10:59:47AM +0100, Vincenzo Frascino wrote:
> 
> Hi Nathan,
> 
> On 10/13/20 4:39 AM, Nathan Chancellor wrote:
> > As it stands now, the vdso32 Makefile hardcodes the linker to ld.bfd
> > using -fuse-ld=bfd with $(CC). This was taken from the arm vDSO
> > Makefile, as the comment notes, done in commit d2b30cd4b722 ("ARM:
> > 8384/1: VDSO: force use of BFD linker").
> > 
> > Commit fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to
> > link VDSO") changed that Makefile to use $(LD) directly instead of
> > through $(CC), which matches how the rest of the kernel operates. Since
> > then, LD=ld.lld means that the arm vDSO will be linked with ld.lld,
> > which has shown no problems so far.
> > 
> > Allow ld.lld to link this vDSO as we do the regular arm vDSO. To do
> > this, we need to do a few things:
> > 
> > * Add a LD_COMPAT variable, which defaults to $(CROSS_COMPILE_COMPAT)ld
> >   with gcc and $(LD) if LLVM is 1, which will be ld.lld, or
> >   $(CROSS_COMPILE_COMPAT)ld if not, which matches the logic of the main
> >   Makefile. It is overrideable for further customization and avoiding
> >   breakage.
> > 
> > * Eliminate cc32-ldoption, which matches commit 055efab3120b ("kbuild:
> >   drop support for cc-ldoption").
> > 
> > With those, we can use $(LD_COMPAT) in cmd_ldvdso and change the flags
> > from compiler linker flags to linker flags directly. We eliminate
> > -mfloat-abi=soft because it is not handled by the linker.
> > 
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1033
> > Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> 
> Just a small nit on my side (see below) and as you already stated it requires
> rebasing if we want to merge it in mainline. Otherwise:
> 
> Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>

Thank you for the review! I do not have any personal preference on how
fast this goes in. If we want it fast tracked, it can probably wait
until after -rc1 anyways so I am going to keep it rebased on -next since
presumably the kbuild tree will be merged into mainline by that point.
If anyone else feels differently, let me know.

> > ---
> > 
> > NOTE: This patch is currently based on the kbuild tree due to the
> > --build-id -> --build-id=sha1 change that Bill did. If the arm64
> > maintainers would prefer to take this patch, I can rebase it (althought
> > presumably this won't hit mainline until at least 5.11 so it can
> > probably just stay as is for now).
> > 
> >  arch/arm64/kernel/vdso32/Makefile | 23 ++++++++++++-----------
> >  1 file changed, 12 insertions(+), 11 deletions(-)
> > 
> > diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> > index 7f96a1a9f68c..1cf00c58805d 100644
> > --- a/arch/arm64/kernel/vdso32/Makefile
> > +++ b/arch/arm64/kernel/vdso32/Makefile
> > @@ -22,16 +22,21 @@ endif
> >  
> >  CC_COMPAT ?= $(CC)
> >  CC_COMPAT += $(CC_COMPAT_CLANG_FLAGS)
> > +
> > +ifeq ($(LLVM),1)
> 
> Nit: Here can we check 'ifneq ($(LLVM),)' for consistency with what the main
> Makefile does?

Sure, I will fix that up.

> > +LD_COMPAT ?= $(LD)
> > +else
> > +LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
> > +endif
> >  else
> >  CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
> > +LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
> >  endif
> >  
> >  cc32-option = $(call try-run,\
> >          $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
> >  cc32-disable-warning = $(call try-run,\
> >  	$(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
> > -cc32-ldoption = $(call try-run,\
> > -        $(CC_COMPAT) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
> >  cc32-as-instr = $(call try-run,\
> >  	printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
> >  
> > @@ -122,14 +127,10 @@ dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
> >  VDSO_CFLAGS += $(dmbinstr)
> >  VDSO_AFLAGS += $(dmbinstr)
> >  
> > -VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
> >  # From arm vDSO Makefile
> > -VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
> > -VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
> > -VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
> > -VDSO_LDFLAGS += -Wl,--hash-style=sysv
> > -VDSO_LDFLAGS += -Wl,--build-id=sha1
> > -VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
> > +VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
> > +VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
> > +VDSO_LDFLAGS += -nostdlib -shared --hash-style=sysv --build-id=sha1
> >  
> >  
> >  # Borrow vdsomunge.c from the arm vDSO
> > @@ -189,8 +190,8 @@ quiet_cmd_vdsold_and_vdso_check = LD32    $@
> >        cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
> >  
> >  quiet_cmd_vdsold = LD32    $@
> > -      cmd_vdsold = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
> > -                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
> > +      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
> > +                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
> >  quiet_cmd_vdsocc = CC32    $@
> >        cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
> >  quiet_cmd_vdsocc_gettimeofday = CC32    $@
> > 
> > base-commit: 172aad81a882443eefe1bd860c4eddc81b14dd5b
> > 
> 
> -- 
> Regards,
> Vincenzo

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

* [PATCH v2] arm64: vdso32: Allow ld.lld to properly link the VDSO
  2020-10-13  3:39 [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO Nathan Chancellor
  2020-10-13 22:37 ` Nick Desaulniers
  2020-10-19  9:59 ` Vincenzo Frascino
@ 2020-10-20  1:14 ` Nathan Chancellor
  2020-10-20 11:37   ` Will Deacon
  2020-10-26 14:22   ` Will Deacon
  2 siblings, 2 replies; 7+ messages in thread
From: Nathan Chancellor @ 2020-10-20  1:14 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Masahiro Yamada
  Cc: linux-arm-kernel, linux-kbuild, linux-kernel, clang-built-linux,
	Nathan Chancellor, Nick Desaulniers, Vincenzo Frascino

As it stands now, the vdso32 Makefile hardcodes the linker to ld.bfd
using -fuse-ld=bfd with $(CC). This was taken from the arm vDSO
Makefile, as the comment notes, done in commit d2b30cd4b722 ("ARM:
8384/1: VDSO: force use of BFD linker").

Commit fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to
link VDSO") changed that Makefile to use $(LD) directly instead of
through $(CC), which matches how the rest of the kernel operates. Since
then, LD=ld.lld means that the arm vDSO will be linked with ld.lld,
which has shown no problems so far.

Allow ld.lld to link this vDSO as we do the regular arm vDSO. To do
this, we need to do a few things:

* Add a LD_COMPAT variable, which defaults to $(CROSS_COMPILE_COMPAT)ld
  with gcc and $(LD) if LLVM is 1, which will be ld.lld, or
  $(CROSS_COMPILE_COMPAT)ld if not, which matches the logic of the main
  Makefile. It is overrideable for further customization and avoiding
  breakage.

* Eliminate cc32-ldoption, which matches commit 055efab3120b ("kbuild:
  drop support for cc-ldoption").

With those, we can use $(LD_COMPAT) in cmd_ldvdso and change the flags
from compiler linker flags to linker flags directly. We eliminate
-mfloat-abi=soft because it is not handled by the linker.

Link: https://github.com/ClangBuiltLinux/linux/issues/1033
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

v1 -> v2:

* Change ifeq ($(LLVM),1) to ifneq ($(LLVM),) to match the main Makefile
  per Vincenzo.

* Carry forward Nick and Vincenzo's tags.

 arch/arm64/kernel/vdso32/Makefile | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index 7f96a1a9f68c..79280c53b9a6 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -22,16 +22,21 @@ endif
 
 CC_COMPAT ?= $(CC)
 CC_COMPAT += $(CC_COMPAT_CLANG_FLAGS)
+
+ifneq ($(LLVM),)
+LD_COMPAT ?= $(LD)
+else
+LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
+endif
 else
 CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
+LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
 endif
 
 cc32-option = $(call try-run,\
         $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
 cc32-disable-warning = $(call try-run,\
 	$(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
-cc32-ldoption = $(call try-run,\
-        $(CC_COMPAT) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
 cc32-as-instr = $(call try-run,\
 	printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
 
@@ -122,14 +127,10 @@ dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
 VDSO_CFLAGS += $(dmbinstr)
 VDSO_AFLAGS += $(dmbinstr)
 
-VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
 # From arm vDSO Makefile
-VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
-VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
-VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
-VDSO_LDFLAGS += -Wl,--hash-style=sysv
-VDSO_LDFLAGS += -Wl,--build-id=sha1
-VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
+VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
+VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
+VDSO_LDFLAGS += -nostdlib -shared --hash-style=sysv --build-id=sha1
 
 
 # Borrow vdsomunge.c from the arm vDSO
@@ -189,8 +190,8 @@ quiet_cmd_vdsold_and_vdso_check = LD32    $@
       cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
 
 quiet_cmd_vdsold = LD32    $@
-      cmd_vdsold = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
-                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
+      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
+                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
 quiet_cmd_vdsocc = CC32    $@
       cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
 quiet_cmd_vdsocc_gettimeofday = CC32    $@

base-commit: 0fa21cf4489fe11737d56f8056dda1ba0257bd8d
-- 
2.29.0


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

* Re: [PATCH v2] arm64: vdso32: Allow ld.lld to properly link the VDSO
  2020-10-20  1:14 ` [PATCH v2] " Nathan Chancellor
@ 2020-10-20 11:37   ` Will Deacon
  2020-10-26 14:22   ` Will Deacon
  1 sibling, 0 replies; 7+ messages in thread
From: Will Deacon @ 2020-10-20 11:37 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Catalin Marinas, Masahiro Yamada, linux-arm-kernel, linux-kbuild,
	linux-kernel, clang-built-linux, Nick Desaulniers,
	Vincenzo Frascino

On Mon, Oct 19, 2020 at 06:14:07PM -0700, Nathan Chancellor wrote:
> As it stands now, the vdso32 Makefile hardcodes the linker to ld.bfd
> using -fuse-ld=bfd with $(CC). This was taken from the arm vDSO
> Makefile, as the comment notes, done in commit d2b30cd4b722 ("ARM:
> 8384/1: VDSO: force use of BFD linker").
> 
> Commit fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to
> link VDSO") changed that Makefile to use $(LD) directly instead of
> through $(CC), which matches how the rest of the kernel operates. Since
> then, LD=ld.lld means that the arm vDSO will be linked with ld.lld,
> which has shown no problems so far.
> 
> Allow ld.lld to link this vDSO as we do the regular arm vDSO. To do
> this, we need to do a few things:
> 
> * Add a LD_COMPAT variable, which defaults to $(CROSS_COMPILE_COMPAT)ld
>   with gcc and $(LD) if LLVM is 1, which will be ld.lld, or
>   $(CROSS_COMPILE_COMPAT)ld if not, which matches the logic of the main
>   Makefile. It is overrideable for further customization and avoiding
>   breakage.
> 
> * Eliminate cc32-ldoption, which matches commit 055efab3120b ("kbuild:
>   drop support for cc-ldoption").
> 
> With those, we can use $(LD_COMPAT) in cmd_ldvdso and change the flags
> from compiler linker flags to linker flags directly. We eliminate
> -mfloat-abi=soft because it is not handled by the linker.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/1033
> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Tested-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---

Cheers, I'll try to remember to queue this at -rc1 but please feel free to
resend then to remind me :)

Will

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

* Re: [PATCH v2] arm64: vdso32: Allow ld.lld to properly link the VDSO
  2020-10-20  1:14 ` [PATCH v2] " Nathan Chancellor
  2020-10-20 11:37   ` Will Deacon
@ 2020-10-26 14:22   ` Will Deacon
  1 sibling, 0 replies; 7+ messages in thread
From: Will Deacon @ 2020-10-26 14:22 UTC (permalink / raw)
  To: Catalin Marinas, Masahiro Yamada, Nathan Chancellor
  Cc: kernel-team, Will Deacon, Vincenzo Frascino, clang-built-linux,
	linux-arm-kernel, linux-kbuild, linux-kernel, Nick Desaulniers

On Mon, 19 Oct 2020 18:14:07 -0700, Nathan Chancellor wrote:
> As it stands now, the vdso32 Makefile hardcodes the linker to ld.bfd
> using -fuse-ld=bfd with $(CC). This was taken from the arm vDSO
> Makefile, as the comment notes, done in commit d2b30cd4b722 ("ARM:
> 8384/1: VDSO: force use of BFD linker").
> 
> Commit fe00e50b2db8 ("ARM: 8858/1: vdso: use $(LD) instead of $(CC) to
> link VDSO") changed that Makefile to use $(LD) directly instead of
> through $(CC), which matches how the rest of the kernel operates. Since
> then, LD=ld.lld means that the arm vDSO will be linked with ld.lld,
> which has shown no problems so far.
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: vdso32: Allow ld.lld to properly link the VDSO
      https://git.kernel.org/arm64/c/0fa97e9403c7

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

end of thread, other threads:[~2020-10-26 14:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-13  3:39 [PATCH] arm64: vdso32: Allow ld.lld to properly link the VDSO Nathan Chancellor
2020-10-13 22:37 ` Nick Desaulniers
2020-10-19  9:59 ` Vincenzo Frascino
2020-10-20  1:07   ` Nathan Chancellor
2020-10-20  1:14 ` [PATCH v2] " Nathan Chancellor
2020-10-20 11:37   ` Will Deacon
2020-10-26 14:22   ` Will Deacon

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).