xref: /linux/arch/x86/entry/vdso/Makefile (revision 78c3925c048c752334873f56c3a3d1c9d53e0416)
1# SPDX-License-Identifier: GPL-2.0
2#
3# Building vDSO images for x86.
4#
5
6# Include the generic Makefile to check the built vDSO:
7include $(srctree)/lib/vdso/Makefile
8
9# Sanitizer runtimes are unavailable and cannot be linked here.
10KASAN_SANITIZE			:= n
11KMSAN_SANITIZE_vclock_gettime.o := n
12KMSAN_SANITIZE_vgetcpu.o	:= n
13
14UBSAN_SANITIZE			:= n
15KCSAN_SANITIZE			:= n
16OBJECT_FILES_NON_STANDARD	:= y
17
18# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
19KCOV_INSTRUMENT		:= n
20
21# Files to link into the vDSO:
22vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
23vobjs32-y := vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o
24vobjs32-y += vdso32/vclock_gettime.o vdso32/vgetcpu.o
25vobjs-$(CONFIG_X86_SGX)	+= vsgx.o
26
27# Files to link into the kernel:
28obj-y						+= vma.o extable.o
29KASAN_SANITIZE_vma.o				:= y
30UBSAN_SANITIZE_vma.o				:= y
31KCSAN_SANITIZE_vma.o				:= y
32
33OBJECT_FILES_NON_STANDARD_vma.o			:= n
34OBJECT_FILES_NON_STANDARD_extable.o		:= n
35
36# vDSO images to build:
37obj-$(CONFIG_X86_64)				+= vdso-image-64.o
38obj-$(CONFIG_X86_X32_ABI)			+= vdso-image-x32.o
39obj-$(CONFIG_COMPAT_32)				+= vdso-image-32.o vdso32-setup.o
40
41OBJECT_FILES_NON_STANDARD_vdso-image-32.o	:= n
42OBJECT_FILES_NON_STANDARD_vdso-image-64.o	:= n
43OBJECT_FILES_NON_STANDARD_vdso32-setup.o	:= n
44
45vobjs := $(addprefix $(obj)/, $(vobjs-y))
46vobjs32 := $(addprefix $(obj)/, $(vobjs32-y))
47
48$(obj)/vdso.o: $(obj)/vdso.so
49
50targets += vdso.lds $(vobjs-y)
51targets += vdso32/vdso32.lds $(vobjs32-y)
52
53targets += $(foreach x, 64 x32 32, vdso-image-$(x).c vdso$(x).so vdso$(x).so.dbg)
54
55CPPFLAGS_vdso.lds += -P -C
56
57VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
58			-z max-page-size=4096
59
60$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
61	$(call if_changed,vdso_and_check)
62
63HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/$(SUBARCH)/include/uapi
64hostprogs += vdso2c
65
66quiet_cmd_vdso2c = VDSO2C  $@
67      cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@
68
69$(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
70	$(call if_changed,vdso2c)
71
72#
73# Don't omit frame pointers for ease of userspace debugging, but do
74# optimize sibling calls.
75#
76CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
77       $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
78       -fno-omit-frame-pointer -foptimize-sibling-calls \
79       -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
80
81ifdef CONFIG_MITIGATION_RETPOLINE
82ifneq ($(RETPOLINE_VDSO_CFLAGS),)
83  CFL += $(RETPOLINE_VDSO_CFLAGS)
84endif
85endif
86
87$(vobjs): KBUILD_CFLAGS := $(filter-out $(PADDING_CFLAGS) $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
88$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO
89
90#
91# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
92#
93CFLAGS_REMOVE_vclock_gettime.o = -pg
94CFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg
95CFLAGS_REMOVE_vgetcpu.o = -pg
96CFLAGS_REMOVE_vdso32/vgetcpu.o = -pg
97CFLAGS_REMOVE_vsgx.o = -pg
98
99#
100# X32 processes use x32 vDSO to access 64bit kernel data.
101#
102# Build x32 vDSO image:
103# 1. Compile x32 vDSO as 64bit.
104# 2. Convert object files to x32.
105# 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
106# so that it can reach 64bit address space with 64bit pointers.
107#
108
109CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
110VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
111			   -z max-page-size=4096
112
113# x32-rebranded versions
114vobjx32s-y := $(vobjs-y:.o=-x32.o)
115
116# same thing, but in the output directory
117vobjx32s := $(addprefix $(obj)/, $(vobjx32s-y))
118
119# Convert 64bit object file to x32 for x32 vDSO.
120quiet_cmd_x32 = X32     $@
121      cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
122
123$(obj)/%-x32.o: $(obj)/%.o FORCE
124	$(call if_changed,x32)
125
126targets += vdsox32.lds $(vobjx32s-y)
127
128$(obj)/%.so: OBJCOPYFLAGS := -S --remove-section __ex_table
129$(obj)/%.so: $(obj)/%.so.dbg FORCE
130	$(call if_changed,objcopy)
131
132$(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE
133	$(call if_changed,vdso_and_check)
134
135CPPFLAGS_vdso32/vdso32.lds = $(CPPFLAGS_vdso.lds)
136VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1
137
138KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO
139$(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
140$(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32
141
142KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
143KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
144KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
145KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
146KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32))
147KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
148KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
149KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS_32))
150KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_CFI),$(KBUILD_CFLAGS_32))
151KBUILD_CFLAGS_32 := $(filter-out $(PADDING_CFLAGS),$(KBUILD_CFLAGS_32))
152KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
153KBUILD_CFLAGS_32 += -fno-stack-protector
154KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
155KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
156KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
157
158ifdef CONFIG_MITIGATION_RETPOLINE
159ifneq ($(RETPOLINE_VDSO_CFLAGS),)
160  KBUILD_CFLAGS_32 += $(RETPOLINE_VDSO_CFLAGS)
161endif
162endif
163
164$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
165
166$(obj)/vdso32.so.dbg: $(obj)/vdso32/vdso32.lds $(vobjs32) FORCE
167	$(call if_changed,vdso_and_check)
168
169#
170# The DSO images are built using a special linker script.
171#
172quiet_cmd_vdso = VDSO    $@
173      cmd_vdso = $(LD) -o $@ \
174		       $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
175		       -T $(filter %.lds,$^) $(filter %.o,$^) && \
176		 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
177
178VDSO_LDFLAGS = -shared --hash-style=both --build-id=sha1 \
179	$(call ld-option, --eh-frame-hdr) -Bsymbolic -z noexecstack
180GCOV_PROFILE := n
181
182quiet_cmd_vdso_and_check = VDSO    $@
183      cmd_vdso_and_check = $(cmd_vdso); $(cmd_vdso_check)
184