Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 -DCOMPAT_VDSO -U$(ARCH)
  29. # Force dependency
  30. $(obj)/compat_vdso.o: $(obj)/compat_vdso.so
  31. # link rule for the .so file, .lds has to be first
  32. $(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE
  33. $(call if_changed,compat_vdsold)
  34. LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \
  35. --build-id=sha1 --hash-style=both --eh-frame-hdr
  36. $(obj-compat_vdso): %.o: %.S FORCE
  37. $(call if_changed_dep,compat_vdsoas)
  38. # strip rule for the .so file
  39. $(obj)/%.so: OBJCOPYFLAGS := -S
  40. $(obj)/%.so: $(obj)/%.so.dbg FORCE
  41. $(call if_changed,objcopy)
  42. # Generate VDSO offsets using helper script
  43. gen-compat_vdsosym := $(src)/gen_compat_vdso_offsets.sh
  44. quiet_cmd_compat_vdsosym = VDSOSYM $@
  45. cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@
  46. include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE
  47. $(call if_changed,compat_vdsosym)
  48. # actual build commands
  49. # The DSO images are built using a special linker script
  50. # Make sure only to export the intended __compat_vdso_xxx symbol offsets.
  51. quiet_cmd_compat_vdsold = VDSOLD $@
  52. cmd_compat_vdsold = $(COMPAT_LD) $(ld_flags) $(COMPAT_LD_FLAGS) -T $(filter-out FORCE,$^) -o $@.tmp && \
  53. $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \
  54. rm $@.tmp
  55. # actual build commands
  56. quiet_cmd_compat_vdsoas = VDSOAS $@
  57. cmd_compat_vdsoas = $(COMPAT_CC) $(a_flags) $(COMPAT_CC_FLAGS) -c -o $@ $<