Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Objects to go into the VDSO.
  3. # Sanitizer runtimes are unavailable and cannot be linked here.
  4. KCSAN_SANITIZE := n
  5. # Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
  6. # the inclusion of generic Makefile.
  7. ARCH_REL_TYPE_ABS := R_MIPS_JUMP_SLOT|R_MIPS_GLOB_DAT
  8. include $(srctree)/lib/vdso/Makefile
  9. obj-vdso-y := elf.o vgettimeofday.o sigreturn.o
  10. # Common compiler flags between ABIs.
  11. ccflags-vdso := \
  12. $(filter -I%,$(KBUILD_CFLAGS)) \
  13. $(filter -E%,$(KBUILD_CFLAGS)) \
  14. $(filter -mmicromips,$(KBUILD_CFLAGS)) \
  15. $(filter -march=%,$(KBUILD_CFLAGS)) \
  16. $(filter -m%-float,$(KBUILD_CFLAGS)) \
  17. $(filter -mno-loongson-%,$(KBUILD_CFLAGS)) \
  18. $(CLANG_FLAGS) \
  19. -D__VDSO__
  20. ifndef CONFIG_64BIT
  21. ccflags-vdso += -DBUILD_VDSO32
  22. endif
  23. #
  24. # The -fno-jump-tables flag only prevents the compiler from generating
  25. # jump tables but does not prevent the compiler from emitting absolute
  26. # offsets.
  27. cflags-vdso := $(ccflags-vdso) \
  28. $(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
  29. -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \
  30. -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \
  31. -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
  32. $(call cc-option, -fno-asynchronous-unwind-tables)
  33. aflags-vdso := $(ccflags-vdso) \
  34. -D__ASSEMBLY__ -Wa,-gdwarf-2
  35. ifneq ($(c-gettimeofday-y),)
  36. CFLAGS_vgettimeofday.o = -include $(c-gettimeofday-y)
  37. # config-n32-o32-env.c prepares the environment to build a 32bit vDSO
  38. # library on a 64bit kernel.
  39. # Note: Needs to be included before than the generic library.
  40. CFLAGS_vgettimeofday-o32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
  41. CFLAGS_vgettimeofday-n32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
  42. endif
  43. CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE)
  44. ifdef CONFIG_MIPS_DISABLE_VDSO
  45. ifndef CONFIG_MIPS_LD_CAN_LINK_VDSO
  46. $(warning MIPS VDSO requires binutils >= 2.25)
  47. endif
  48. obj-vdso-y := $(filter-out vgettimeofday.o, $(obj-vdso-y))
  49. endif
  50. # VDSO linker flags.
  51. ldflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \
  52. $(filter -E%,$(KBUILD_CFLAGS)) -shared \
  53. -G 0 --eh-frame-hdr --hash-style=sysv --build-id=sha1 -T
  54. CFLAGS_REMOVE_vdso.o = $(CC_FLAGS_FTRACE)
  55. GCOV_PROFILE := n
  56. UBSAN_SANITIZE := n
  57. KCOV_INSTRUMENT := n
  58. # Check that we don't have PIC 'jalr t9' calls left
  59. quiet_cmd_vdso_mips_check = VDSOCHK $@
  60. cmd_vdso_mips_check = if $(OBJDUMP) --disassemble $@ | grep -E -h "jalr.*t9" > /dev/null; \
  61. then (echo >&2 "$@: PIC 'jalr t9' calls are not supported"; \
  62. rm -f $@; /bin/false); fi
  63. #
  64. # Shared build commands.
  65. #
  66. quiet_cmd_vdsold_and_vdso_check = LD $@
  67. cmd_vdsold_and_vdso_check = $(cmd_ld); $(cmd_vdso_check); $(cmd_vdso_mips_check)
  68. quiet_cmd_vdsoas_o_S = AS $@
  69. cmd_vdsoas_o_S = $(CC) $(a_flags) -c -o $@ $<
  70. # Strip rule for the raw .so files
  71. $(obj)/%.so.raw: OBJCOPYFLAGS := -S
  72. $(obj)/%.so.raw: $(obj)/%.so.dbg.raw FORCE
  73. $(call if_changed,objcopy)
  74. hostprogs := genvdso
  75. quiet_cmd_genvdso = GENVDSO $@
  76. define cmd_genvdso
  77. $(foreach file,$(filter %.raw,$^),cp $(file) $(file:%.raw=%) &&) \
  78. $(obj)/genvdso $(<:%.raw=%) $(<:%.dbg.raw=%) $@ $(VDSO_NAME)
  79. endef
  80. #
  81. # Build native VDSO.
  82. #
  83. native-abi := $(filter -mabi=%,$(KBUILD_CFLAGS))
  84. targets += $(obj-vdso-y)
  85. targets += vdso.lds
  86. targets += vdso.so.dbg.raw vdso.so.raw
  87. targets += vdso.so.dbg vdso.so
  88. targets += vdso-image.c
  89. obj-vdso := $(obj-vdso-y:%.o=$(obj)/%.o)
  90. $(obj-vdso): KBUILD_CFLAGS := $(cflags-vdso) $(native-abi)
  91. $(obj-vdso): KBUILD_AFLAGS := $(aflags-vdso) $(native-abi)
  92. $(obj)/vdso.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) $(native-abi)
  93. $(obj)/vdso.so.dbg.raw: $(obj)/vdso.lds $(obj-vdso) FORCE
  94. $(call if_changed,vdsold_and_vdso_check)
  95. $(obj)/vdso-image.c: $(obj)/vdso.so.dbg.raw $(obj)/vdso.so.raw \
  96. $(obj)/genvdso FORCE
  97. $(call if_changed,genvdso)
  98. obj-y += vdso-image.o
  99. #
  100. # Build O32 VDSO.
  101. #
  102. # Define these outside the ifdef to ensure they are picked up by clean.
  103. targets += $(obj-vdso-y:%.o=%-o32.o)
  104. targets += vdso-o32.lds
  105. targets += vdso-o32.so.dbg.raw vdso-o32.so.raw
  106. targets += vdso-o32.so.dbg vdso-o32.so
  107. targets += vdso-o32-image.c
  108. ifdef CONFIG_MIPS32_O32
  109. obj-vdso-o32 := $(obj-vdso-y:%.o=$(obj)/%-o32.o)
  110. $(obj-vdso-o32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=32
  111. $(obj-vdso-o32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=32
  112. $(obj)/%-o32.o: $(src)/%.S FORCE
  113. $(call if_changed_dep,vdsoas_o_S)
  114. $(obj)/%-o32.o: $(src)/%.c FORCE
  115. $(call cmd,force_checksrc)
  116. $(call if_changed_rule,cc_o_c)
  117. $(obj)/vdso-o32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=32
  118. $(obj)/vdso-o32.lds: $(src)/vdso.lds.S FORCE
  119. $(call if_changed_dep,cpp_lds_S)
  120. $(obj)/vdso-o32.so.dbg.raw: $(obj)/vdso-o32.lds $(obj-vdso-o32) FORCE
  121. $(call if_changed,vdsold_and_vdso_check)
  122. $(obj)/vdso-o32-image.c: VDSO_NAME := o32
  123. $(obj)/vdso-o32-image.c: $(obj)/vdso-o32.so.dbg.raw $(obj)/vdso-o32.so.raw \
  124. $(obj)/genvdso FORCE
  125. $(call if_changed,genvdso)
  126. obj-y += vdso-o32-image.o
  127. endif
  128. #
  129. # Build N32 VDSO.
  130. #
  131. targets += $(obj-vdso-y:%.o=%-n32.o)
  132. targets += vdso-n32.lds
  133. targets += vdso-n32.so.dbg.raw vdso-n32.so.raw
  134. targets += vdso-n32.so.dbg vdso-n32.so
  135. targets += vdso-n32-image.c
  136. ifdef CONFIG_MIPS32_N32
  137. obj-vdso-n32 := $(obj-vdso-y:%.o=$(obj)/%-n32.o)
  138. $(obj-vdso-n32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=n32
  139. $(obj-vdso-n32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=n32
  140. $(obj)/%-n32.o: $(src)/%.S FORCE
  141. $(call if_changed_dep,vdsoas_o_S)
  142. $(obj)/%-n32.o: $(src)/%.c FORCE
  143. $(call cmd,force_checksrc)
  144. $(call if_changed_rule,cc_o_c)
  145. $(obj)/vdso-n32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=n32
  146. $(obj)/vdso-n32.lds: $(src)/vdso.lds.S FORCE
  147. $(call if_changed_dep,cpp_lds_S)
  148. $(obj)/vdso-n32.so.dbg.raw: $(obj)/vdso-n32.lds $(obj-vdso-n32) FORCE
  149. $(call if_changed,vdsold_and_vdso_check)
  150. $(obj)/vdso-n32-image.c: VDSO_NAME := n32
  151. $(obj)/vdso-n32-image.c: $(obj)/vdso-n32.so.dbg.raw $(obj)/vdso-n32.so.raw \
  152. $(obj)/genvdso FORCE
  153. $(call if_changed,genvdso)
  154. obj-y += vdso-n32-image.o
  155. endif
  156. # FIXME: Need install rule for debug.
  157. # Needs to deal with dependency for generation of dbg by cmd_genvdso...