blob: 47bc2760e6a8a9fd7913b669a758e203682c11cf [file] [log] [blame]
Andi Kleen2aae9502007-07-21 17:10:01 +02001#
Roland McGrath0249c9c2008-01-30 13:30:42 +01002# Building vDSO images for x86.
Andi Kleen2aae9502007-07-21 17:10:01 +02003#
4
Roland McGrath0249c9c2008-01-30 13:30:42 +01005VDSO64-$(CONFIG_X86_64) := y
6VDSO32-$(CONFIG_X86_32) := y
7VDSO32-$(CONFIG_COMPAT) := y
8
9vdso-install-$(VDSO64-y) += vdso.so
10vdso-install-$(VDSO32-y) += $(vdso32-y:=.so)
11
12
Andi Kleen2aae9502007-07-21 17:10:01 +020013# files to link into the vdso
Roland McGrath7f3646a2008-01-30 13:30:41 +010014vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o vvar.o
Andi Kleen2aae9502007-07-21 17:10:01 +020015
16# files to link into kernel
Roland McGrath6c3652e2008-01-30 13:30:42 +010017obj-$(VDSO64-y) += vma.o vdso.o
Roland McGrathaf65d642008-01-30 13:30:43 +010018obj-$(VDSO32-y) += vdso32.o vdso32-setup.o
Andi Kleen2aae9502007-07-21 17:10:01 +020019
20vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
21
22$(obj)/vdso.o: $(obj)/vdso.so
23
Roland McGrath2b9c97e2008-01-30 13:30:41 +010024targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
Andi Kleen2aae9502007-07-21 17:10:01 +020025
26# The DSO images are built using a special linker script.
27quiet_cmd_syscall = SYSCALL $@
28 cmd_syscall = $(CC) -m elf_x86_64 -nostdlib $(SYSCFLAGS_$(@F)) \
29 -Wl,-T,$(filter-out FORCE,$^) -o $@
30
Sam Ravnborgd746d642007-11-12 20:14:19 +010031export CPPFLAGS_vdso.lds += -P -C
Andi Kleen2aae9502007-07-21 17:10:01 +020032
33vdso-flags = -fPIC -shared -Wl,-soname=linux-vdso.so.1 \
34 $(call ld-option, -Wl$(comma)--hash-style=sysv) \
35 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
36SYSCFLAGS_vdso.so = $(vdso-flags)
Roland McGrathf79eb832007-10-17 18:04:32 +020037SYSCFLAGS_vdso.so.dbg = $(vdso-flags)
Andi Kleen2aae9502007-07-21 17:10:01 +020038
39$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
40
41$(obj)/vdso.so: $(src)/vdso.lds $(vobjs) FORCE
Roland McGrathf79eb832007-10-17 18:04:32 +020042
43$(obj)/vdso.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
Andi Kleen2aae9502007-07-21 17:10:01 +020044 $(call if_changed,syscall)
45
Roland McGrathf79eb832007-10-17 18:04:32 +020046$(obj)/%.so: OBJCOPYFLAGS := -S
47$(obj)/%.so: $(obj)/%.so.dbg FORCE
48 $(call if_changed,objcopy)
49
Andi Kleen037e20a2007-07-22 21:13:11 +020050CFL := $(PROFILING) -mcmodel=small -fPIC -g0 -O2 -fasynchronous-unwind-tables -m64
Andi Kleen2aae9502007-07-21 17:10:01 +020051
Sam Ravnborga0f97e02007-10-14 22:21:35 +020052$(obj)/vclock_gettime.o: KBUILD_CFLAGS = $(CFL)
53$(obj)/vgetcpu.o: KBUILD_CFLAGS = $(CFL)
Andi Kleen2aae9502007-07-21 17:10:01 +020054
Roland McGrath5b930492008-01-30 13:30:40 +010055targets += vdso-syms.lds
Roland McGrath6c3652e2008-01-30 13:30:42 +010056obj-$(VDSO64-y) += vdso-syms.lds
Roland McGrath5b930492008-01-30 13:30:40 +010057
58#
59# Match symbols in the DSO that look like VDSO*; produce a file of constants.
60#
61sed-vdsosym := -e 's/^00*/0/' \
62 -e 's/^\([0-9a-fA-F]*\) . \(VDSO[a-zA-Z0-9_]*\)$$/\2 = 0x\1;/p'
63quiet_cmd_vdsosym = VDSOSYM $@
64 cmd_vdsosym = $(NM) $< | sed -n $(sed-vdsosym) | LC_ALL=C sort > $@
65
66$(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE
67 $(call if_changed,vdsosym)
68
Roland McGrath0249c9c2008-01-30 13:30:42 +010069#
70# Build multiple 32-bit vDSO images to choose from at boot time.
71#
Roland McGrath6c3652e2008-01-30 13:30:42 +010072obj-$(VDSO32-y) += vdso32-syms.lds
Roland McGrath0249c9c2008-01-30 13:30:42 +010073vdso32.so-$(CONFIG_X86_32) += int80
Roland McGrath00f8b1b2008-01-30 13:30:43 +010074vdso32.so-$(CONFIG_COMPAT) += syscall
Roland McGrath0249c9c2008-01-30 13:30:42 +010075vdso32.so-$(VDSO32-y) += sysenter
76
77CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
78VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -Wl,-soname=linux-gate.so.1
79
80# This makes sure the $(obj) subdirectory exists even though vdso32/
81# is not a kbuild sub-make subdirectory.
82override obj-dirs = $(dir $(obj)) $(obj)/vdso32/
83
84targets += vdso32/vdso32.lds
85targets += $(vdso32.so-y:%=vdso32-%.so.dbg) $(vdso32.so-y:%=vdso32-%.so)
86targets += vdso32/note.o $(vdso32.so-y:%=vdso32/%.o)
87
88extra-y += $(vdso32.so-y:%=vdso32-%.so)
89
Roland McGrath6c3652e2008-01-30 13:30:42 +010090$(obj)/vdso32.o: $(vdso32.so-y:%=$(obj)/vdso32-%.so)
91
Roland McGrath0249c9c2008-01-30 13:30:42 +010092KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS))
93$(vdso32.so-y:%=$(obj)/vdso32-%.so.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
94$(vdso32.so-y:%=$(obj)/vdso32-%.so.dbg): asflags-$(CONFIG_X86_64) += -m32
95
96$(vdso32.so-y:%=$(obj)/vdso32-%.so.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
97 $(obj)/vdso32/vdso32.lds \
98 $(obj)/vdso32/note.o \
99 $(obj)/vdso32/%.o
100 $(call if_changed,vdso)
101
102# Make vdso32-*-syms.lds from each image, and then make sure they match.
103# The only difference should be that some do not define VDSO32_SYSENTER_RETURN.
104
105targets += vdso32-syms.lds $(vdso32.so-y:%=vdso32-%-syms.lds)
106
107quiet_cmd_vdso32sym = VDSOSYM $@
108define cmd_vdso32sym
109 if LC_ALL=C sort -u $(filter-out FORCE,$^) > $(@D)/.tmp_$(@F) && \
110 $(foreach H,$(filter-out FORCE,$^),\
111 if grep -q VDSO32_SYSENTER_RETURN $H; \
112 then diff -u $(@D)/.tmp_$(@F) $H; \
113 else sed /VDSO32_SYSENTER_RETURN/d $(@D)/.tmp_$(@F) | \
114 diff -u - $H; fi &&) : ;\
115 then mv -f $(@D)/.tmp_$(@F) $@; \
116 else rm -f $(@D)/.tmp_$(@F); exit 1; \
117 fi
118endef
119
120$(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE
121 $(call if_changed,vdso32sym)
122
123#
124# The DSO images are built using a special linker script.
125#
126quiet_cmd_vdso = VDSO $@
127 cmd_vdso = $(CC) -nostdlib -o $@ \
128 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
129 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
130
131VDSO_LDFLAGS = -fPIC -shared $(call ld-option, -Wl$(comma)--hash-style=sysv)
132
133#
134# Install the unstripped copy of vdso*.so listed in $(vdso-install-y).
135#
Roland McGrathf79eb832007-10-17 18:04:32 +0200136quiet_cmd_vdso_install = INSTALL $@
137 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
Roland McGrath0249c9c2008-01-30 13:30:42 +0100138$(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE
Roland McGrathf79eb832007-10-17 18:04:32 +0200139 @mkdir -p $(MODLIB)/vdso
140 $(call cmd,vdso_install)
141
Roland McGrath0249c9c2008-01-30 13:30:42 +0100142PHONY += vdso_install $(vdso-install-y)
143vdso_install: $(vdso-install-y)