Makefile 3.0 KB

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