Makefile 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Makefile for compat_vdso
  4. #
  5. # Symbols present in the compat_vdso
  6. compat_vdso-syms = rt_sigreturn
  7. compat_vdso-syms += getcpu
  8. compat_vdso-syms += flush_icache
  9. COMPAT_CC := $(CC)
  10. COMPAT_LD := $(LD)
  11. # binutils 2.35 does not support the zifencei extension, but in the ISA
  12. # spec 20191213, G stands for IMAFD_ZICSR_ZIFENCEI.
  13. ifdef CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
  14. COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
  15. else
  16. COMPAT_CC_FLAGS := -march=rv32imafd -mabi=ilp32
  17. endif
  18. COMPAT_LD_FLAGS := -melf32lriscv
  19. # Disable attributes, as they're useless and break the build.
  20. COMPAT_CC_FLAGS += $(call cc-option,-mno-riscv-attribute)
  21. COMPAT_CC_FLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
  22. # Files to link into the compat_vdso
  23. obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o
  24. # Build rules
  25. targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds
  26. obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso))
  27. obj-y += compat_vdso.o
  28. CPPFLAGS_compat_vdso.lds += -P -C -U$(ARCH)
  29. # Disable profiling and instrumentation for VDSO code
  30. GCOV_PROFILE := n
  31. KCOV_INSTRUMENT := n
  32. KASAN_SANITIZE := n
  33. UBSAN_SANITIZE := n
  34. # Force dependency
  35. $(obj)/compat_vdso.o: $(obj)/compat_vdso.so
  36. # link rule for the .so file, .lds has to be first
  37. $(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE
  38. $(call if_changed,compat_vdsold)
  39. LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \
  40. --build-id=sha1 --hash-style=both --eh-frame-hdr
  41. $(obj-compat_vdso): %.o: %.S FORCE
  42. $(call if_changed_dep,compat_vdsoas)
  43. # strip rule for the .so file
  44. $(obj)/%.so: OBJCOPYFLAGS := -S
  45. $(obj)/%.so: $(obj)/%.so.dbg FORCE
  46. $(call if_changed,objcopy)
  47. # Generate VDSO offsets using helper script
  48. gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh
  49. quiet_cmd_compat_vdsosym = VDSOSYM $@
  50. cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@
  51. include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE
  52. $(call if_changed,compat_vdsosym)
  53. # actual build commands
  54. # The DSO images are built using a special linker script
  55. # Make sure only to export the intended __compat_vdso_xxx symbol offsets.
  56. quiet_cmd_compat_vdsold = VDSOLD $@
  57. cmd_compat_vdsold = $(COMPAT_LD) $(ld_flags) $(COMPAT_LD_FLAGS) -T $(filter-out FORCE,$^) -o [email protected] && \
  58. $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) [email protected] $@ && \
  59. rm [email protected]
  60. # actual build commands
  61. quiet_cmd_compat_vdsoas = VDSOAS $@
  62. cmd_compat_vdsoas = $(COMPAT_CC) $(a_flags) $(COMPAT_CC_FLAGS) -c -o $@ $<
  63. # install commands for the unstripped file
  64. quiet_cmd_compat_vdso_install = INSTALL $@
  65. cmd_compat_vdso_install = cp $(obj)/[email protected] $(MODLIB)/compat_vdso/$@
  66. compat_vdso.so: $(obj)/compat_vdso.so.dbg
  67. @mkdir -p $(MODLIB)/compat_vdso
  68. $(call cmd,compat_vdso_install)
  69. compat_vdso_install: compat_vdso.so