Makefile 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Building a vDSO image for AArch64.
  4. #
  5. # Author: Will Deacon <will.deacon@arm.com>
  6. # Heavily based on the vDSO Makefiles for other archs.
  7. #
  8. # Include the generic Makefile to check the built vdso.
  9. include $(srctree)/lib/vdso/Makefile
  10. obj-vdso := vgettimeofday.o note.o sigreturn.o vgetrandom.o vgetrandom-chacha.o
  11. # Build rules
  12. targets := $(obj-vdso) vdso.so vdso.so.dbg
  13. obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
  14. btildflags-$(CONFIG_ARM64_BTI_KERNEL) += -z force-bti
  15. # -Bsymbolic has been added for consistency with arm, the compat vDSO and
  16. # potential future proofing if we end up with internal calls to the exported
  17. # routines, as x86 does (see 6f121e548f83 ("x86, vdso: Reimplement vdso.so
  18. # preparation in build-time C")).
  19. ldflags-y := -shared -soname=linux-vdso.so.1 \
  20. -Bsymbolic --build-id=sha1 -n $(btildflags-y)
  21. ifdef CONFIG_LD_ORPHAN_WARN
  22. ldflags-y += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
  23. endif
  24. ldflags-y += -T
  25. ccflags-y := -fno-common -fno-builtin -fno-stack-protector -ffixed-x18
  26. ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
  27. # -Wmissing-prototypes and -Wmissing-declarations are removed from
  28. # the CFLAGS to make possible to build the kernel with CONFIG_WERROR enabled.
  29. CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \
  30. $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) \
  31. $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
  32. -Wmissing-prototypes -Wmissing-declarations
  33. CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables
  34. CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO)
  35. CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO)
  36. CFLAGS_vgettimeofday.o = $(CC_FLAGS_ADD_VDSO)
  37. CFLAGS_vgetrandom.o = $(CC_FLAGS_ADD_VDSO)
  38. ifneq ($(c-gettimeofday-y),)
  39. CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y)
  40. endif
  41. ifneq ($(c-getrandom-y),)
  42. CFLAGS_vgetrandom.o += -include $(c-getrandom-y)
  43. endif
  44. targets += vdso.lds
  45. CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
  46. # Link rule for the .so file, .lds has to be first
  47. $(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
  48. $(call if_changed,vdsold_and_vdso_check)
  49. # Strip rule for the .so file
  50. $(obj)/%.so: OBJCOPYFLAGS := -S
  51. $(obj)/%.so: $(obj)/%.so.dbg FORCE
  52. $(call if_changed,objcopy)
  53. # Generate VDSO offsets using helper script
  54. gen-vdsosym := $(src)/gen_vdso_offsets.sh
  55. quiet_cmd_vdsosym = VDSOSYM $@
  56. cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
  57. include/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE
  58. $(call if_changed,vdsosym)
  59. # Actual build commands
  60. quiet_cmd_vdsold_and_vdso_check = LD $@
  61. cmd_vdsold_and_vdso_check = $(cmd_ld); $(cmd_vdso_check)