xref: /linux-6.15/arch/powerpc/kernel/vdso/Makefile (revision a6b67eb0)
1# SPDX-License-Identifier: GPL-2.0
2
3# List of files in the vdso, has to be asm only for now
4
5# Include the generic Makefile to check the built vdso.
6include $(srctree)/lib/vdso/Makefile
7
8obj-vdso32 = sigtramp32-32.o gettimeofday-32.o datapage-32.o cacheflush-32.o note-32.o getcpu-32.o
9obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o note-64.o getcpu-64.o
10
11ifneq ($(c-gettimeofday-y),)
12  CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y)
13# Go prior to 1.16.x assumes r30 is not clobbered by any VDSO code. That used to be true
14# by accident when the VDSO was hand-written asm code, but may not be now that the VDSO is
15# compiler generated. To avoid breaking Go tell GCC not to use r30. Impact on code
16# generation is minimal, it will just use r29 instead.
17  CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) $(call cc-option, -ffixed-r30)
18endif
19
20# Build rules
21
22ifdef CROSS32_COMPILE
23    VDSOCC := $(CROSS32_COMPILE)gcc
24else
25    VDSOCC := $(CC)
26endif
27
28targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o
29targets += crtsavres-32.o
30obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32))
31targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o
32obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64))
33
34ccflags-y := -fno-common -fno-builtin
35ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN)
36ccflags-y += $(call cc-option, -fno-stack-protector)
37ccflags-y += -DDISABLE_BRANCH_PROFILING
38ccflags-y += -ffreestanding -fasynchronous-unwind-tables
39ccflags-remove-y := $(CC_FLAGS_FTRACE)
40ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS)
41ldflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld)
42ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
43
44# Filter flags that clang will warn are unused for linking
45ldflags-y += $(filter-out $(CC_AUTO_VAR_INIT_ZERO_ENABLER) $(CC_FLAGS_FTRACE) -Wa$(comma)%, $(KBUILD_CFLAGS))
46
47CC32FLAGS := -m32
48CC32FLAGSREMOVE := -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc
49  # This flag is supported by clang for 64-bit but not 32-bit so it will cause
50  # an unused command line flag warning for this file.
51ifdef CONFIG_CC_IS_CLANG
52CC32FLAGSREMOVE += -fno-stack-clash-protection
53endif
54LD32FLAGS := -Wl,-soname=linux-vdso32.so.1
55AS32FLAGS := -D__VDSO32__
56
57LD64FLAGS := -Wl,-soname=linux-vdso64.so.1
58AS64FLAGS := -D__VDSO64__
59
60targets += vdso32.lds
61CPPFLAGS_vdso32.lds += -P -C -Upowerpc
62targets += vdso64.lds
63CPPFLAGS_vdso64.lds += -P -C
64
65# link rule for the .so file, .lds has to be first
66$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/crtsavres-32.o FORCE
67	$(call if_changed,vdso32ld_and_check)
68$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o FORCE
69	$(call if_changed,vdso64ld_and_check)
70
71# assembly rules for the .S files
72$(obj-vdso32): %-32.o: %.S FORCE
73	$(call if_changed_dep,vdso32as)
74$(obj)/crtsavres-32.o: %-32.o: $(srctree)/arch/powerpc/lib/crtsavres.S FORCE
75	$(call if_changed_dep,vdso32as)
76$(obj)/vgettimeofday-32.o: %-32.o: %.c FORCE
77	$(call if_changed_dep,vdso32cc)
78$(obj-vdso64): %-64.o: %.S FORCE
79	$(call if_changed_dep,vdso64as)
80$(obj)/vgettimeofday-64.o: %-64.o: %.c FORCE
81	$(call if_changed_dep,cc_o_c)
82
83# Generate VDSO offsets using helper script
84gen-vdso32sym := $(src)/gen_vdso32_offsets.sh
85quiet_cmd_vdso32sym = VDSO32SYM $@
86      cmd_vdso32sym = $(NM) $< | $(gen-vdso32sym) | LC_ALL=C sort > $@
87gen-vdso64sym := $(src)/gen_vdso64_offsets.sh
88quiet_cmd_vdso64sym = VDSO64SYM $@
89      cmd_vdso64sym = $(NM) $< | $(gen-vdso64sym) | LC_ALL=C sort > $@
90
91include/generated/vdso32-offsets.h: $(obj)/vdso32.so.dbg FORCE
92	$(call if_changed,vdso32sym)
93include/generated/vdso64-offsets.h: $(obj)/vdso64.so.dbg FORCE
94	$(call if_changed,vdso64sym)
95
96# actual build commands
97quiet_cmd_vdso32ld_and_check = VDSO32L $@
98      cmd_vdso32ld_and_check = $(VDSOCC) $(ldflags-y) $(CC32FLAGS) $(LD32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check)
99quiet_cmd_vdso32as = VDSO32A $@
100      cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) $(AS32FLAGS) -c -o $@ $<
101quiet_cmd_vdso32cc = VDSO32C $@
102      cmd_vdso32cc = $(VDSOCC) $(filter-out $(CC32FLAGSREMOVE), $(c_flags)) $(CC32FLAGS) -c -o $@ $<
103
104quiet_cmd_vdso64ld_and_check = VDSO64L $@
105      cmd_vdso64ld_and_check = $(VDSOCC) $(ldflags-y) $(LD64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check)
106quiet_cmd_vdso64as = VDSO64A $@
107      cmd_vdso64as = $(VDSOCC) $(a_flags) $(AS64FLAGS) -c -o $@ $<
108