Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Makefile for vdso32
  4. #
  5. include $(srctree)/lib/vdso/Makefile
  6. # Same as cc-*option, but using CC_COMPAT instead of CC
  7. ifeq ($(CONFIG_CC_IS_CLANG), y)
  8. CC_COMPAT ?= $(CC)
  9. CC_COMPAT += --target=arm-linux-gnueabi
  10. else
  11. CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
  12. endif
  13. ifeq ($(CONFIG_LD_IS_LLD), y)
  14. LD_COMPAT ?= $(LD)
  15. else
  16. LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
  17. endif
  18. cc32-option = $(call try-run,\
  19. $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
  20. cc32-disable-warning = $(call try-run,\
  21. $(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
  22. # We cannot use the global flags to compile the vDSO files, the main reason
  23. # being that the 32-bit compiler may be older than the main (64-bit) compiler
  24. # and therefore may not understand flags set using $(cc-option ...). Besides,
  25. # arch-specific options should be taken from the arm Makefile instead of the
  26. # arm64 one.
  27. # As a result we set our own flags here.
  28. # KBUILD_CPPFLAGS and NOSTDINC_FLAGS from top-level Makefile
  29. VDSO_CPPFLAGS := -DBUILD_VDSO -D__KERNEL__ -nostdinc
  30. VDSO_CPPFLAGS += -isystem $(shell $(CC_COMPAT) -print-file-name=include 2>/dev/null)
  31. VDSO_CPPFLAGS += $(LINUXINCLUDE)
  32. # Common C and assembly flags
  33. # From top-level Makefile
  34. VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
  35. VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
  36. ifdef CONFIG_DEBUG_INFO
  37. VDSO_CAFLAGS += -g
  38. endif
  39. # From arm Makefile
  40. VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
  41. VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
  42. ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
  43. VDSO_CAFLAGS += -mbig-endian
  44. else
  45. VDSO_CAFLAGS += -mlittle-endian
  46. endif
  47. # From arm vDSO Makefile
  48. VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
  49. VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
  50. VDSO_CAFLAGS += -march=armv8-a
  51. VDSO_CFLAGS := $(VDSO_CAFLAGS)
  52. VDSO_CFLAGS += -DENABLE_COMPAT_VDSO=1
  53. # KBUILD_CFLAGS from top-level Makefile
  54. VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
  55. -fno-strict-aliasing -fno-common \
  56. -Werror-implicit-function-declaration \
  57. -Wno-format-security \
  58. -std=gnu11
  59. VDSO_CFLAGS += -O2
  60. # Some useful compiler-dependent flags from top-level Makefile
  61. VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
  62. VDSO_CFLAGS += -fno-strict-overflow
  63. VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
  64. VDSO_CFLAGS += -Werror=date-time
  65. VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
  66. # The 32-bit compiler does not provide 128-bit integers, which are used in
  67. # some headers that are indirectly included from the vDSO code.
  68. # This hack makes the compiler happy and should trigger a warning/error if
  69. # variables of such type are referenced.
  70. VDSO_CFLAGS += -D__uint128_t='void*'
  71. # Silence some warnings coming from headers that operate on long's
  72. # (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
  73. VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
  74. VDSO_CFLAGS += -Wno-int-to-pointer-cast
  75. # Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is
  76. # unreliable.
  77. ifeq ($(CONFIG_THUMB2_COMPAT_VDSO), y)
  78. VDSO_CFLAGS += -mthumb -fomit-frame-pointer
  79. else
  80. VDSO_CFLAGS += -marm
  81. endif
  82. VDSO_AFLAGS := $(VDSO_CAFLAGS)
  83. VDSO_AFLAGS += -D__ASSEMBLY__
  84. # From arm vDSO Makefile
  85. VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
  86. VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
  87. VDSO_LDFLAGS += -shared --build-id=sha1
  88. VDSO_LDFLAGS += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
  89. # Borrow vdsomunge.c from the arm vDSO
  90. # We have to use a relative path because scripts/Makefile.host prefixes
  91. # $(hostprogs) with $(obj)
  92. munge := ../../../arm/vdso/vdsomunge
  93. hostprogs := $(munge)
  94. c-obj-vdso := note.o
  95. c-obj-vdso-gettimeofday := vgettimeofday.o
  96. ifneq ($(c-gettimeofday-y),)
  97. VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
  98. endif
  99. VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
  100. # Build rules
  101. targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso32.so.dbg vdso.so.raw
  102. c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
  103. c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
  104. asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
  105. obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
  106. targets += vdso.lds
  107. CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
  108. # Strip rule for vdso.so
  109. $(obj)/vdso.so: OBJCOPYFLAGS := -S
  110. $(obj)/vdso.so: $(obj)/vdso32.so.dbg FORCE
  111. $(call if_changed,objcopy)
  112. $(obj)/vdso32.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
  113. $(call if_changed,vdsomunge)
  114. # Link rule for the .so file, .lds has to be first
  115. $(obj)/vdso.so.raw: $(obj)/vdso.lds $(obj-vdso) FORCE
  116. $(call if_changed,vdsold_and_vdso_check)
  117. # Compilation rules for the vDSO sources
  118. $(c-obj-vdso): %.o: %.c FORCE
  119. $(call if_changed_dep,vdsocc)
  120. $(c-obj-vdso-gettimeofday): %.o: %.c FORCE
  121. $(call if_changed_dep,vdsocc_gettimeofday)
  122. $(asm-obj-vdso): %.o: %.S FORCE
  123. $(call if_changed_dep,vdsoas)
  124. # Actual build commands
  125. quiet_cmd_vdsold_and_vdso_check = LD32 $@
  126. cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
  127. quiet_cmd_vdsold = LD32 $@
  128. cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
  129. -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
  130. quiet_cmd_vdsocc = CC32 $@
  131. cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
  132. quiet_cmd_vdsocc_gettimeofday = CC32 $@
  133. cmd_vdsocc_gettimeofday = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
  134. quiet_cmd_vdsoas = AS32 $@
  135. cmd_vdsoas = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
  136. quiet_cmd_vdsomunge = MUNGE $@
  137. cmd_vdsomunge = $(obj)/$(munge) $< $@