Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: vdso32: Allow ld.lld to properly link the VDSO

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.

Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Link: https://github.com/ClangBuiltLinux/linux/issues/1033
Link: https://lore.kernel.org/r/20201020011406.1818918-1-natechancellor@gmail.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Nathan Chancellor and committed by
Will Deacon
0fa97e94 3650b228

+12 -11
+12 -11
arch/arm64/kernel/vdso32/Makefile
··· 22 22 23 23 CC_COMPAT ?= $(CC) 24 24 CC_COMPAT += $(CC_COMPAT_CLANG_FLAGS) 25 + 26 + ifneq ($(LLVM),) 27 + LD_COMPAT ?= $(LD) 28 + else 29 + LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld 30 + endif 25 31 else 26 32 CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc 33 + LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld 27 34 endif 28 35 29 36 cc32-option = $(call try-run,\ 30 37 $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) 31 38 cc32-disable-warning = $(call try-run,\ 32 39 $(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 33 - cc32-ldoption = $(call try-run,\ 34 - $(CC_COMPAT) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) 35 40 cc32-as-instr = $(call try-run,\ 36 41 printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) 37 42 ··· 127 122 VDSO_CFLAGS += $(dmbinstr) 128 123 VDSO_AFLAGS += $(dmbinstr) 129 124 130 - VDSO_LDFLAGS := $(VDSO_CPPFLAGS) 131 125 # From arm vDSO Makefile 132 - VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1 133 - VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 134 - VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft 135 - VDSO_LDFLAGS += -Wl,--hash-style=sysv 136 - VDSO_LDFLAGS += -Wl,--build-id=sha1 137 - VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd) 126 + VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1 127 + VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096 128 + VDSO_LDFLAGS += -nostdlib -shared --hash-style=sysv --build-id=sha1 138 129 139 130 140 131 # Borrow vdsomunge.c from the arm vDSO ··· 190 189 cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check) 191 190 192 191 quiet_cmd_vdsold = LD32 $@ 193 - cmd_vdsold = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \ 194 - -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@ 192 + cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \ 193 + -T $(filter %.lds,$^) $(filter %.o,$^) -o $@ 195 194 quiet_cmd_vdsocc = CC32 $@ 196 195 cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $< 197 196 quiet_cmd_vdsocc_gettimeofday = CC32 $@