Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # SPDX-License-Identifier: GPL-2.0
  2. purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
  3. ifeq ($(CONFIG_KASAN_GENERIC)$(CONFIG_KASAN_SW_TAGS),)
  4. purgatory-y += strcmp.o strlen.o strncmp.o
  5. endif
  6. targets += $(purgatory-y)
  7. PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
  8. $(obj)/string.o: $(srctree)/lib/string.c FORCE
  9. $(call if_changed_rule,cc_o_c)
  10. $(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE
  11. $(call if_changed_rule,cc_o_c)
  12. $(obj)/memcpy.o: $(srctree)/arch/riscv/lib/memcpy.S FORCE
  13. $(call if_changed_rule,as_o_S)
  14. $(obj)/memset.o: $(srctree)/arch/riscv/lib/memset.S FORCE
  15. $(call if_changed_rule,as_o_S)
  16. $(obj)/strcmp.o: $(srctree)/arch/riscv/lib/strcmp.S FORCE
  17. $(call if_changed_rule,as_o_S)
  18. $(obj)/strlen.o: $(srctree)/arch/riscv/lib/strlen.S FORCE
  19. $(call if_changed_rule,as_o_S)
  20. $(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S FORCE
  21. $(call if_changed_rule,as_o_S)
  22. $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
  23. $(call if_changed_rule,cc_o_c)
  24. CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
  25. CFLAGS_string.o := -D__DISABLE_EXPORTS
  26. CFLAGS_ctype.o := -D__DISABLE_EXPORTS
  27. # When profile-guided optimization is enabled, llvm emits two different
  28. # overlapping text sections, which is not supported by kexec. Remove profile
  29. # optimization flags.
  30. KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
  31. # When linking purgatory.ro with -r unresolved symbols are not checked,
  32. # also link a purgatory.chk binary without -r to check for unresolved symbols.
  33. PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
  34. LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
  35. LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
  36. targets += purgatory.ro purgatory.chk
  37. # These are adjustments to the compiler flags used for objects that
  38. # make up the standalone purgatory.ro
  39. PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
  40. PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss
  41. PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
  42. PURGATORY_CFLAGS += -fno-stack-protector -g0
  43. # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
  44. # in turn leaves some undefined symbols like __fentry__ in purgatory and not
  45. # sure how to relocate those.
  46. ifdef CONFIG_FUNCTION_TRACER
  47. PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE)
  48. endif
  49. ifdef CONFIG_STACKPROTECTOR
  50. PURGATORY_CFLAGS_REMOVE += -fstack-protector
  51. endif
  52. ifdef CONFIG_STACKPROTECTOR_STRONG
  53. PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong
  54. endif
  55. ifdef CONFIG_CFI_CLANG
  56. PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI)
  57. endif
  58. ifdef CONFIG_RELOCATABLE
  59. PURGATORY_CFLAGS_REMOVE += -fPIE
  60. endif
  61. ifdef CONFIG_SHADOW_CALL_STACK
  62. PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_SCS)
  63. endif
  64. CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE)
  65. CFLAGS_purgatory.o += $(PURGATORY_CFLAGS)
  66. CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE)
  67. CFLAGS_sha256.o += $(PURGATORY_CFLAGS)
  68. CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE)
  69. CFLAGS_string.o += $(PURGATORY_CFLAGS)
  70. CFLAGS_REMOVE_ctype.o += $(PURGATORY_CFLAGS_REMOVE)
  71. CFLAGS_ctype.o += $(PURGATORY_CFLAGS)
  72. asflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x))
  73. $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
  74. $(call if_changed,ld)
  75. $(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE
  76. $(call if_changed,ld)
  77. $(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk
  78. obj-y += kexec-purgatory.o