Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 1 | # |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 2 | # Building vDSO images for x86. |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 3 | # |
| 4 | |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 5 | VDSO64-$(CONFIG_X86_64) := y |
H. J. Lu | 1a21d4e | 2012-02-19 11:38:06 -0800 | [diff] [blame] | 6 | VDSOX32-$(CONFIG_X86_X32_ABI) := y |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 7 | VDSO32-$(CONFIG_X86_32) := y |
| 8 | VDSO32-$(CONFIG_COMPAT) := y |
| 9 | |
| 10 | vdso-install-$(VDSO64-y) += vdso.so |
H. J. Lu | 1a21d4e | 2012-02-19 11:38:06 -0800 | [diff] [blame] | 11 | vdso-install-$(VDSOX32-y) += vdsox32.so |
Roland McGrath | 2c15826 | 2008-02-11 14:38:51 -0800 | [diff] [blame] | 12 | vdso-install-$(VDSO32-y) += $(vdso32-images) |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 13 | |
| 14 | |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 15 | # files to link into the vdso |
Andy Lutomirski | 8c49d9a | 2011-05-23 09:31:24 -0400 | [diff] [blame] | 16 | vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 17 | |
H. J. Lu | 1a21d4e | 2012-02-19 11:38:06 -0800 | [diff] [blame] | 18 | vobjs-$(VDSOX32-y) += $(vobjx32s-compat) |
| 19 | |
| 20 | # Filter out x32 objects. |
| 21 | vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y)) |
| 22 | |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 23 | # files to link into kernel |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 24 | obj-$(VDSO64-y) += vma.o vdso.o |
H. J. Lu | 1a21d4e | 2012-02-19 11:38:06 -0800 | [diff] [blame] | 25 | obj-$(VDSOX32-y) += vdsox32.o |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 26 | obj-$(VDSO32-y) += vdso32.o vdso32-setup.o |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 27 | |
H. J. Lu | 1a21d4e | 2012-02-19 11:38:06 -0800 | [diff] [blame] | 28 | vobjs := $(foreach F,$(vobj64s),$(obj)/$F) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 29 | |
| 30 | $(obj)/vdso.o: $(obj)/vdso.so |
| 31 | |
Roland McGrath | 2b9c97e | 2008-01-30 13:30:41 +0100 | [diff] [blame] | 32 | targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 33 | |
Sam Ravnborg | d746d64 | 2007-11-12 20:14:19 +0100 | [diff] [blame] | 34 | export CPPFLAGS_vdso.lds += -P -C |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 35 | |
H. Peter Anvin | de2a8cf | 2010-12-13 16:01:38 -0800 | [diff] [blame] | 36 | VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \ |
Andy Lutomirski | 7f79ad1 | 2011-07-13 09:24:12 -0400 | [diff] [blame] | 37 | -Wl,--no-undefined \ |
Roland McGrath | 16e48e7 | 2008-01-30 13:30:44 +0100 | [diff] [blame] | 38 | -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 39 | |
| 40 | $(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so |
| 41 | |
Roland McGrath | f79eb83 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 42 | $(obj)/vdso.so.dbg: $(src)/vdso.lds $(vobjs) FORCE |
Roland McGrath | 16e48e7 | 2008-01-30 13:30:44 +0100 | [diff] [blame] | 43 | $(call if_changed,vdso) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 44 | |
Roland McGrath | f79eb83 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 45 | $(obj)/%.so: OBJCOPYFLAGS := -S |
| 46 | $(obj)/%.so: $(obj)/%.so.dbg FORCE |
| 47 | $(call if_changed,objcopy) |
| 48 | |
Andy Lutomirski | 6447fac | 2011-05-23 09:31:29 -0400 | [diff] [blame] | 49 | # |
| 50 | # Don't omit frame pointers for ease of userspace debugging, but do |
| 51 | # optimize sibling calls. |
| 52 | # |
Roland McGrath | 8705a49 | 2008-04-14 12:19:30 -0700 | [diff] [blame] | 53 | CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ |
Andy Lutomirski | 6447fac | 2011-05-23 09:31:29 -0400 | [diff] [blame] | 54 | $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ |
| 55 | -fno-omit-frame-pointer -foptimize-sibling-calls |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 56 | |
Glauber de Oliveira Costa | f6bc402 | 2008-03-19 14:25:53 -0300 | [diff] [blame] | 57 | $(vobjs): KBUILD_CFLAGS += $(CFL) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 58 | |
Andy Lutomirski | 6447fac | 2011-05-23 09:31:29 -0400 | [diff] [blame] | 59 | # |
| 60 | # vDSO code runs in userspace and -pg doesn't help with profiling anyway. |
| 61 | # |
| 62 | CFLAGS_REMOVE_vdso-note.o = -pg |
| 63 | CFLAGS_REMOVE_vclock_gettime.o = -pg |
| 64 | CFLAGS_REMOVE_vgetcpu.o = -pg |
| 65 | CFLAGS_REMOVE_vvar.o = -pg |
| 66 | |
Roland McGrath | 5b93049 | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 67 | targets += vdso-syms.lds |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 68 | obj-$(VDSO64-y) += vdso-syms.lds |
Roland McGrath | 5b93049 | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 69 | |
| 70 | # |
| 71 | # Match symbols in the DSO that look like VDSO*; produce a file of constants. |
| 72 | # |
| 73 | sed-vdsosym := -e 's/^00*/0/' \ |
Roland McGrath | f2dbe03 | 2008-02-27 11:42:15 -0800 | [diff] [blame] | 74 | -e 's/^\([0-9a-fA-F]*\) . \(VDSO[a-zA-Z0-9_]*\)$$/\2 = 0x\1;/p' |
Roland McGrath | 5b93049 | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 75 | quiet_cmd_vdsosym = VDSOSYM $@ |
Roland McGrath | f2dbe03 | 2008-02-27 11:42:15 -0800 | [diff] [blame] | 76 | define cmd_vdsosym |
| 77 | $(NM) $< | LC_ALL=C sed -n $(sed-vdsosym) | LC_ALL=C sort > $@ |
| 78 | endef |
Roland McGrath | 5b93049 | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 79 | |
| 80 | $(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE |
| 81 | $(call if_changed,vdsosym) |
| 82 | |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 83 | # |
H. J. Lu | 1a21d4e | 2012-02-19 11:38:06 -0800 | [diff] [blame] | 84 | # X32 processes use x32 vDSO to access 64bit kernel data. |
| 85 | # |
| 86 | # Build x32 vDSO image: |
| 87 | # 1. Compile x32 vDSO as 64bit. |
| 88 | # 2. Convert object files to x32. |
| 89 | # 3. Build x32 VDSO image with x32 objects, which contains 64bit codes |
| 90 | # so that it can reach 64bit address space with 64bit pointers. |
| 91 | # |
| 92 | |
| 93 | targets += vdsox32-syms.lds |
| 94 | obj-$(VDSOX32-y) += vdsox32-syms.lds |
| 95 | |
| 96 | CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds) |
| 97 | VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \ |
| 98 | -Wl,-soname=linux-vdso.so.1 \ |
| 99 | -Wl,-z,max-page-size=4096 \ |
| 100 | -Wl,-z,common-page-size=4096 |
| 101 | |
| 102 | vobjx32s-y := $(vobj64s:.o=-x32.o) |
| 103 | vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F) |
| 104 | |
| 105 | # Convert 64bit object file to x32 for x32 vDSO. |
| 106 | quiet_cmd_x32 = X32 $@ |
| 107 | cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@ |
| 108 | |
| 109 | $(obj)/%-x32.o: $(obj)/%.o FORCE |
| 110 | $(call if_changed,x32) |
| 111 | |
| 112 | targets += vdsox32.so vdsox32.so.dbg vdsox32.lds $(vobjx32s-y) |
| 113 | |
| 114 | $(obj)/vdsox32.o: $(src)/vdsox32.S $(obj)/vdsox32.so |
| 115 | |
| 116 | $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE |
| 117 | $(call if_changed,vdso) |
| 118 | |
| 119 | # |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 120 | # Build multiple 32-bit vDSO images to choose from at boot time. |
| 121 | # |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 122 | obj-$(VDSO32-y) += vdso32-syms.lds |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 123 | vdso32.so-$(VDSO32-y) += int80 |
Roland McGrath | 00f8b1b | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 124 | vdso32.so-$(CONFIG_COMPAT) += syscall |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 125 | vdso32.so-$(VDSO32-y) += sysenter |
| 126 | |
Roland McGrath | 2c15826 | 2008-02-11 14:38:51 -0800 | [diff] [blame] | 127 | vdso32-images = $(vdso32.so-y:%=vdso32-%.so) |
| 128 | |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 129 | CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds) |
H. Peter Anvin | de2a8cf | 2010-12-13 16:01:38 -0800 | [diff] [blame] | 130 | VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-soname=linux-gate.so.1 |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 131 | |
| 132 | # This makes sure the $(obj) subdirectory exists even though vdso32/ |
| 133 | # is not a kbuild sub-make subdirectory. |
| 134 | override obj-dirs = $(dir $(obj)) $(obj)/vdso32/ |
| 135 | |
| 136 | targets += vdso32/vdso32.lds |
Roland McGrath | 2c15826 | 2008-02-11 14:38:51 -0800 | [diff] [blame] | 137 | targets += $(vdso32-images) $(vdso32-images:=.dbg) |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 138 | targets += vdso32/note.o $(vdso32.so-y:%=vdso32/%.o) |
| 139 | |
Roland McGrath | 2c15826 | 2008-02-11 14:38:51 -0800 | [diff] [blame] | 140 | extra-y += $(vdso32-images) |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 141 | |
Roland McGrath | 2c15826 | 2008-02-11 14:38:51 -0800 | [diff] [blame] | 142 | $(obj)/vdso32.o: $(vdso32-images:%=$(obj)/%) |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 143 | |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 144 | KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) |
Roland McGrath | 2c15826 | 2008-02-11 14:38:51 -0800 | [diff] [blame] | 145 | $(vdso32-images:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) |
| 146 | $(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32 |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 147 | |
Roland McGrath | 2c15826 | 2008-02-11 14:38:51 -0800 | [diff] [blame] | 148 | $(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \ |
| 149 | $(obj)/vdso32/vdso32.lds \ |
| 150 | $(obj)/vdso32/note.o \ |
| 151 | $(obj)/vdso32/%.o |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 152 | $(call if_changed,vdso) |
| 153 | |
| 154 | # Make vdso32-*-syms.lds from each image, and then make sure they match. |
| 155 | # The only difference should be that some do not define VDSO32_SYSENTER_RETURN. |
| 156 | |
| 157 | targets += vdso32-syms.lds $(vdso32.so-y:%=vdso32-%-syms.lds) |
| 158 | |
| 159 | quiet_cmd_vdso32sym = VDSOSYM $@ |
| 160 | define cmd_vdso32sym |
| 161 | if LC_ALL=C sort -u $(filter-out FORCE,$^) > $(@D)/.tmp_$(@F) && \ |
| 162 | $(foreach H,$(filter-out FORCE,$^),\ |
| 163 | if grep -q VDSO32_SYSENTER_RETURN $H; \ |
| 164 | then diff -u $(@D)/.tmp_$(@F) $H; \ |
| 165 | else sed /VDSO32_SYSENTER_RETURN/d $(@D)/.tmp_$(@F) | \ |
| 166 | diff -u - $H; fi &&) : ;\ |
| 167 | then mv -f $(@D)/.tmp_$(@F) $@; \ |
| 168 | else rm -f $(@D)/.tmp_$(@F); exit 1; \ |
| 169 | fi |
| 170 | endef |
| 171 | |
| 172 | $(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE |
| 173 | $(call if_changed,vdso32sym) |
| 174 | |
| 175 | # |
| 176 | # The DSO images are built using a special linker script. |
| 177 | # |
| 178 | quiet_cmd_vdso = VDSO $@ |
| 179 | cmd_vdso = $(CC) -nostdlib -o $@ \ |
| 180 | $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ |
H. Peter Anvin | 05d0b08 | 2010-06-18 14:36:26 -0700 | [diff] [blame] | 181 | -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ |
| 182 | sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 183 | |
Sam Ravnborg | f86fd30 | 2009-09-19 10:14:33 +0200 | [diff] [blame] | 184 | VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) |
Peter Oberparleiter | 7bf99fb | 2009-06-17 16:28:09 -0700 | [diff] [blame] | 185 | GCOV_PROFILE := n |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 186 | |
| 187 | # |
| 188 | # Install the unstripped copy of vdso*.so listed in $(vdso-install-y). |
| 189 | # |
Roland McGrath | f79eb83 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 190 | quiet_cmd_vdso_install = INSTALL $@ |
| 191 | cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@ |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 192 | $(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE |
Roland McGrath | f79eb83 | 2007-10-17 18:04:32 +0200 | [diff] [blame] | 193 | @mkdir -p $(MODLIB)/vdso |
| 194 | $(call cmd,vdso_install) |
| 195 | |
Roland McGrath | 0249c9c | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 196 | PHONY += vdso_install $(vdso-install-y) |
| 197 | vdso_install: $(vdso-install-y) |
Sam Ravnborg | d531b4f | 2008-01-30 13:32:27 +0100 | [diff] [blame] | 198 | |
| 199 | clean-files := vdso32-syscall* vdso32-sysenter* vdso32-int80* |