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