Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # SPDX-License-Identifier: GPL-2.0
  2. # List of files in the vdso, has to be asm only for now
  3. # Include the generic Makefile to check the built vdso.
  4. include $(srctree)/lib/vdso/Makefile
  5. obj-vdso32 = sigtramp32-32.o gettimeofday-32.o datapage-32.o cacheflush-32.o note-32.o getcpu-32.o
  6. obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o note-64.o getcpu-64.o
  7. obj-vdso32 += getrandom-32.o vgetrandom-chacha-32.o
  8. obj-vdso64 += getrandom-64.o vgetrandom-chacha-64.o
  9. ifneq ($(c-gettimeofday-y),)
  10. CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y)
  11. # Go prior to 1.16.x assumes r30 is not clobbered by any VDSO code. That used to be true
  12. # by accident when the VDSO was hand-written asm code, but may not be now that the VDSO is
  13. # compiler generated. To avoid breaking Go tell GCC not to use r30. Impact on code
  14. # generation is minimal, it will just use r29 instead.
  15. CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) $(call cc-option, -ffixed-r30)
  16. endif
  17. ifneq ($(c-getrandom-y),)
  18. CFLAGS_vgetrandom-32.o += -include $(c-getrandom-y)
  19. CFLAGS_vgetrandom-64.o += -include $(c-getrandom-y)
  20. endif
  21. # Build rules
  22. ifdef CROSS32_COMPILE
  23. VDSOCC := $(CROSS32_COMPILE)gcc
  24. else
  25. VDSOCC := $(CC)
  26. endif
  27. targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o vgetrandom-32.o
  28. targets += crtsavres-32.o
  29. obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32))
  30. targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o vgetrandom-64.o
  31. obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64))
  32. ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO
  33. ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN)
  34. ccflags-y += $(call cc-option, -fno-stack-protector)
  35. ccflags-y += -DDISABLE_BRANCH_PROFILING
  36. ccflags-y += -ffreestanding -fasynchronous-unwind-tables
  37. ccflags-remove-y := $(CC_FLAGS_FTRACE)
  38. ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS)
  39. ldflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld)
  40. ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
  41. # Filter flags that clang will warn are unused for linking
  42. ldflags-y += $(filter-out $(CC_AUTO_VAR_INIT_ZERO_ENABLER) $(CC_FLAGS_FTRACE) -Wa$(comma)%, $(KBUILD_CFLAGS))
  43. CC32FLAGS := -m32
  44. CC32FLAGSREMOVE := -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc -mpcrel
  45. ifdef CONFIG_CC_IS_CLANG
  46. # This flag is supported by clang for 64-bit but not 32-bit so it will cause
  47. # an unused command line flag warning for this file.
  48. CC32FLAGSREMOVE += -fno-stack-clash-protection
  49. # -mstack-protector-guard values from the 64-bit build are not valid for the
  50. # 32-bit one. clang validates the values passed to these arguments during
  51. # parsing, even when -fno-stack-protector is passed afterwards.
  52. CC32FLAGSREMOVE += -mstack-protector-guard%
  53. endif
  54. LD32FLAGS := -Wl,-soname=linux-vdso32.so.1
  55. AS32FLAGS := -D__VDSO32__
  56. LD64FLAGS := -Wl,-soname=linux-vdso64.so.1
  57. AS64FLAGS := -D__VDSO64__
  58. targets += vdso32.lds
  59. CPPFLAGS_vdso32.lds += -P -C -Upowerpc
  60. targets += vdso64.lds
  61. CPPFLAGS_vdso64.lds += -P -C
  62. # link rule for the .so file, .lds has to be first
  63. $(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/vgetrandom-32.o $(obj)/crtsavres-32.o FORCE
  64. $(call if_changed,vdso32ld_and_check)
  65. $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o $(obj)/vgetrandom-64.o FORCE
  66. $(call if_changed,vdso64ld_and_check)
  67. # assembly rules for the .S files
  68. $(obj-vdso32): %-32.o: %.S FORCE
  69. $(call if_changed_dep,vdso32as)
  70. $(obj)/crtsavres-32.o: %-32.o: $(srctree)/arch/powerpc/lib/crtsavres.S FORCE
  71. $(call if_changed_dep,vdso32as)
  72. $(obj)/vgettimeofday-32.o: %-32.o: %.c FORCE
  73. $(call if_changed_dep,vdso32cc)
  74. $(obj)/vgetrandom-32.o: %-32.o: %.c FORCE
  75. $(call if_changed_dep,vdso32cc)
  76. $(obj-vdso64): %-64.o: %.S FORCE
  77. $(call if_changed_dep,vdso64as)
  78. $(obj)/vgettimeofday-64.o: %-64.o: %.c FORCE
  79. $(call if_changed_dep,cc_o_c)
  80. $(obj)/vgetrandom-64.o: %-64.o: %.c FORCE
  81. $(call if_changed_dep,cc_o_c)
  82. # Generate VDSO offsets using helper script
  83. gen-vdso32sym := $(src)/gen_vdso32_offsets.sh
  84. quiet_cmd_vdso32sym = VDSO32SYM $@
  85. cmd_vdso32sym = $(NM) $< | $(gen-vdso32sym) | LC_ALL=C sort > $@
  86. gen-vdso64sym := $(src)/gen_vdso64_offsets.sh
  87. quiet_cmd_vdso64sym = VDSO64SYM $@
  88. cmd_vdso64sym = $(NM) $< | $(gen-vdso64sym) | LC_ALL=C sort > $@
  89. include/generated/vdso32-offsets.h: $(obj)/vdso32.so.dbg FORCE
  90. $(call if_changed,vdso32sym)
  91. include/generated/vdso64-offsets.h: $(obj)/vdso64.so.dbg FORCE
  92. $(call if_changed,vdso64sym)
  93. # actual build commands
  94. quiet_cmd_vdso32ld_and_check = VDSO32L $@
  95. cmd_vdso32ld_and_check = $(VDSOCC) $(ldflags-y) $(CC32FLAGS) $(LD32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check)
  96. quiet_cmd_vdso32as = VDSO32A $@
  97. cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) $(AS32FLAGS) -c -o $@ $<
  98. quiet_cmd_vdso32cc = VDSO32C $@
  99. cmd_vdso32cc = $(VDSOCC) $(filter-out $(CC32FLAGSREMOVE), $(c_flags)) $(CC32FLAGS) -c -o $@ $<
  100. quiet_cmd_vdso64ld_and_check = VDSO64L $@
  101. cmd_vdso64ld_and_check = $(VDSOCC) $(ldflags-y) $(LD64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check)
  102. quiet_cmd_vdso64as = VDSO64A $@
  103. cmd_vdso64as = $(VDSOCC) $(a_flags) $(AS64FLAGS) -c -o $@ $<