arm64 descends into each vdso directory twice; first in vdso_prepare,
second during the ordinary build process.
PPC mimicked it and uncovered a problem [1]. In the first descend,
Kbuild directly visits the vdso directories, therefore it does not
inherit subdir-ccflags-y from upper directories.
This means the command line parameters may differ between the two.
If it happens, the offset values in the generated headers might be
different from real offsets of vdso.so in the kernel.
This potential danger should be avoided. The vdso directories are
built in the vdso_prepare stage, so the second descend is unneeded.
[1]: https://lore.kernel.org/linux-kbuild/CAK7LNARAkJ3_-4gX0VA2UkapbOftuzfSTVMBbgbw=HD8n7N+7w@mail.gmail.com/T/#ma10dcb961fda13f36d42d58fa6cb2da988b7e73a
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Link: https://lore.kernel.org/r/20201218024540.1102650-1-masahiroy@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
 # this hack.
 prepare: vdso_prepare
 vdso_prepare: prepare0
-       $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h
-       $(if $(CONFIG_COMPAT_VDSO),$(Q)$(MAKE) \
-               $(build)=arch/arm64/kernel/vdso32  \
-               include/generated/vdso32-offsets.h)
+       $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \
+       include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so
+ifdef CONFIG_COMPAT_VDSO
+       $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
+       include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so
+endif
 endif
 
 define archhelp
 
 obj-$(CONFIG_ARM_SDE_INTERFACE)                += sdei.o
 obj-$(CONFIG_ARM64_PTR_AUTH)           += pointer_auth.o
 obj-$(CONFIG_ARM64_MTE)                        += mte.o
+obj-y                                  += vdso-wrap.o
+obj-$(CONFIG_COMPAT_VDSO)              += vdso32-wrap.o
 
-obj-y                                  += vdso/ probes/
-obj-$(CONFIG_COMPAT_VDSO)              += vdso32/
+obj-y                                  += probes/
 head-y                                 := head.o
 extra-y                                        += $(head-y) vmlinux.lds
 
 
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2012 ARM Limited
+ *
+ * Author: Will Deacon <will.deacon@arm.com>
+ */
+
+#include <linux/init.h>
+#include <linux/linkage.h>
+#include <linux/const.h>
+#include <asm/assembler.h>
+#include <asm/page.h>
+
+       .globl vdso_start, vdso_end
+       .section .rodata
+       .balign PAGE_SIZE
+vdso_start:
+       .incbin "arch/arm64/kernel/vdso/vdso.so"
+       .balign PAGE_SIZE
+vdso_end:
+
+       .previous
+
+emit_aarch64_feature_1_and
 
 # Disable gcov profiling for VDSO code
 GCOV_PROFILE := n
 
-obj-y += vdso.o
 targets += vdso.lds
 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 
 
+++ /dev/null
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2012 ARM Limited
- *
- * Author: Will Deacon <will.deacon@arm.com>
- */
-
-#include <linux/init.h>
-#include <linux/linkage.h>
-#include <linux/const.h>
-#include <asm/assembler.h>
-#include <asm/page.h>
-
-       .globl vdso_start, vdso_end
-       .section .rodata
-       .balign PAGE_SIZE
-vdso_start:
-       .incbin "arch/arm64/kernel/vdso/vdso.so"
-       .balign PAGE_SIZE
-vdso_end:
-
-       .previous
-
-emit_aarch64_feature_1_and
 
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2012 ARM Limited
+ */
+
+#include <linux/init.h>
+#include <linux/linkage.h>
+#include <linux/const.h>
+#include <asm/page.h>
+
+       .globl vdso32_start, vdso32_end
+       .section .rodata
+       .balign PAGE_SIZE
+vdso32_start:
+       .incbin "arch/arm64/kernel/vdso32/vdso.so"
+       .balign PAGE_SIZE
+vdso32_end:
+
+       .previous
 
 asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
 obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
 
-obj-y += vdso.o
 targets += vdso.lds
 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 
 
+++ /dev/null
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Copyright (C) 2012 ARM Limited
- */
-
-#include <linux/init.h>
-#include <linux/linkage.h>
-#include <linux/const.h>
-#include <asm/page.h>
-
-       .globl vdso32_start, vdso32_end
-       .section .rodata
-       .balign PAGE_SIZE
-vdso32_start:
-       .incbin "arch/arm64/kernel/vdso32/vdso.so"
-       .balign PAGE_SIZE
-vdso32_end:
-
-       .previous