Makefile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #
  2. # Building vDSO images for x86.
  3. #
  4. VDSO64-$(CONFIG_X86_64) := y
  5. VDSOX32-$(CONFIG_X86_X32_ABI) := y
  6. VDSO32-$(CONFIG_X86_32) := y
  7. VDSO32-$(CONFIG_COMPAT) := y
  8. vdso-install-$(VDSO64-y) += vdso.so
  9. vdso-install-$(VDSOX32-y) += vdsox32.so
  10. vdso-install-$(VDSO32-y) += $(vdso32-images)
  11. # files to link into the vdso
  12. vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
  13. vobjs-$(VDSOX32-y) += $(vobjx32s-compat)
  14. # Filter out x32 objects.
  15. vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y))
  16. # files to link into kernel
  17. obj-$(VDSO64-y) += vma.o vdso.o
  18. obj-$(VDSOX32-y) += vdsox32.o
  19. obj-$(VDSO32-y) += vdso32.o vdso32-setup.o
  20. vobjs := $(foreach F,$(vobj64s),$(obj)/$F)
  21. $(obj)/vdso.o: $(obj)/vdso.so
  22. targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
  23. export CPPFLAGS_vdso.lds += -P -C
  24. VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
  25. -Wl,--no-undefined \
  26. -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
  27. $(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
  28. $(obj)/vdso.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
  29. $(call if_changed,vdso)
  30. $(obj)/%.so: OBJCOPYFLAGS := -S
  31. $(obj)/%.so: $(obj)/%.so.dbg FORCE
  32. $(call if_changed,objcopy)
  33. #
  34. # Don't omit frame pointers for ease of userspace debugging, but do
  35. # optimize sibling calls.
  36. #
  37. CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
  38. $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
  39. -fno-omit-frame-pointer -foptimize-sibling-calls
  40. $(vobjs): KBUILD_CFLAGS += $(CFL)
  41. #
  42. # vDSO code runs in userspace and -pg doesn't help with profiling anyway.
  43. #
  44. CFLAGS_REMOVE_vdso-note.o = -pg
  45. CFLAGS_REMOVE_vclock_gettime.o = -pg
  46. CFLAGS_REMOVE_vgetcpu.o = -pg
  47. CFLAGS_REMOVE_vvar.o = -pg
  48. targets += vdso-syms.lds
  49. obj-$(VDSO64-y) += vdso-syms.lds
  50. #
  51. # Match symbols in the DSO that look like VDSO*; produce a file of constants.
  52. #
  53. sed-vdsosym := -e 's/^00*/0/' \
  54. -e 's/^\([0-9a-fA-F]*\) . \(VDSO[a-zA-Z0-9_]*\)$$/\2 = 0x\1;/p'
  55. quiet_cmd_vdsosym = VDSOSYM $@
  56. define cmd_vdsosym
  57. $(NM) $< | LC_ALL=C sed -n $(sed-vdsosym) | LC_ALL=C sort > $@
  58. endef
  59. $(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE
  60. $(call if_changed,vdsosym)
  61. #
  62. # X32 processes use x32 vDSO to access 64bit kernel data.
  63. #
  64. # Build x32 vDSO image:
  65. # 1. Compile x32 vDSO as 64bit.
  66. # 2. Convert object files to x32.
  67. # 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
  68. # so that it can reach 64bit address space with 64bit pointers.
  69. #
  70. targets += vdsox32-syms.lds
  71. obj-$(VDSOX32-y) += vdsox32-syms.lds
  72. CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
  73. VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
  74. -Wl,-soname=linux-vdso.so.1 \
  75. -Wl,-z,max-page-size=4096 \
  76. -Wl,-z,common-page-size=4096
  77. vobjx32s-y := $(vobj64s:.o=-x32.o)
  78. vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
  79. # Convert 64bit object file to x32 for x32 vDSO.
  80. quiet_cmd_x32 = X32 $@
  81. cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
  82. $(obj)/%-x32.o: $(obj)/%.o FORCE
  83. $(call if_changed,x32)
  84. targets += vdsox32.so vdsox32.so.dbg vdsox32.lds $(vobjx32s-y)
  85. $(obj)/vdsox32.o: $(src)/vdsox32.S $(obj)/vdsox32.so
  86. $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
  87. $(call if_changed,vdso)
  88. #
  89. # Build multiple 32-bit vDSO images to choose from at boot time.
  90. #
  91. obj-$(VDSO32-y) += vdso32-syms.lds
  92. vdso32.so-$(VDSO32-y) += int80
  93. vdso32.so-$(CONFIG_COMPAT) += syscall
  94. vdso32.so-$(VDSO32-y) += sysenter
  95. vdso32-images = $(vdso32.so-y:%=vdso32-%.so)
  96. CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
  97. VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-soname=linux-gate.so.1
  98. # This makes sure the $(obj) subdirectory exists even though vdso32/
  99. # is not a kbuild sub-make subdirectory.
  100. override obj-dirs = $(dir $(obj)) $(obj)/vdso32/
  101. targets += vdso32/vdso32.lds
  102. targets += $(vdso32-images) $(vdso32-images:=.dbg)
  103. targets += vdso32/note.o $(vdso32.so-y:%=vdso32/%.o)
  104. extra-y += $(vdso32-images)
  105. $(obj)/vdso32.o: $(vdso32-images:%=$(obj)/%)
  106. KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS))
  107. $(vdso32-images:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
  108. $(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32
  109. $(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
  110. $(obj)/vdso32/vdso32.lds \
  111. $(obj)/vdso32/note.o \
  112. $(obj)/vdso32/%.o
  113. $(call if_changed,vdso)
  114. # Make vdso32-*-syms.lds from each image, and then make sure they match.
  115. # The only difference should be that some do not define VDSO32_SYSENTER_RETURN.
  116. targets += vdso32-syms.lds $(vdso32.so-y:%=vdso32-%-syms.lds)
  117. quiet_cmd_vdso32sym = VDSOSYM $@
  118. define cmd_vdso32sym
  119. if LC_ALL=C sort -u $(filter-out FORCE,$^) > $(@D)/.tmp_$(@F) && \
  120. $(foreach H,$(filter-out FORCE,$^),\
  121. if grep -q VDSO32_SYSENTER_RETURN $H; \
  122. then diff -u $(@D)/.tmp_$(@F) $H; \
  123. else sed /VDSO32_SYSENTER_RETURN/d $(@D)/.tmp_$(@F) | \
  124. diff -u - $H; fi &&) : ;\
  125. then mv -f $(@D)/.tmp_$(@F) $@; \
  126. else rm -f $(@D)/.tmp_$(@F); exit 1; \
  127. fi
  128. endef
  129. $(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE
  130. $(call if_changed,vdso32sym)
  131. #
  132. # The DSO images are built using a special linker script.
  133. #
  134. quiet_cmd_vdso = VDSO $@
  135. cmd_vdso = $(CC) -nostdlib -o $@ \
  136. $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
  137. -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
  138. sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
  139. VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
  140. GCOV_PROFILE := n
  141. #
  142. # Install the unstripped copy of vdso*.so listed in $(vdso-install-y).
  143. #
  144. quiet_cmd_vdso_install = INSTALL $@
  145. cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
  146. $(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE
  147. @mkdir -p $(MODLIB)/vdso
  148. $(call cmd,vdso_install)
  149. PHONY += vdso_install $(vdso-install-y)
  150. vdso_install: $(vdso-install-y)
  151. clean-files := vdso32-syscall* vdso32-sysenter* vdso32-int80*