Merge tag 'lsm-pr-20220801' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
[platform/kernel/linux-starfive.git] / arch / arm64 / kernel / vdso32 / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 #
3 # Makefile for vdso32
4 #
5
6 # Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
7 # the inclusion of generic Makefile.
8 ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
9 include $(srctree)/lib/vdso/Makefile
10
11 # Same as cc-*option, but using CC_COMPAT instead of CC
12 ifeq ($(CONFIG_CC_IS_CLANG), y)
13 CC_COMPAT ?= $(CC)
14 CC_COMPAT += --target=arm-linux-gnueabi
15 else
16 CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
17 endif
18
19 ifeq ($(CONFIG_LD_IS_LLD), y)
20 LD_COMPAT ?= $(LD)
21 else
22 LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
23 endif
24
25 cc32-option = $(call try-run,\
26         $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
27 cc32-disable-warning = $(call try-run,\
28         $(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
29
30 # We cannot use the global flags to compile the vDSO files, the main reason
31 # being that the 32-bit compiler may be older than the main (64-bit) compiler
32 # and therefore may not understand flags set using $(cc-option ...). Besides,
33 # arch-specific options should be taken from the arm Makefile instead of the
34 # arm64 one.
35 # As a result we set our own flags here.
36
37 # KBUILD_CPPFLAGS and NOSTDINC_FLAGS from top-level Makefile
38 VDSO_CPPFLAGS := -DBUILD_VDSO -D__KERNEL__ -nostdinc
39 VDSO_CPPFLAGS += -isystem $(shell $(CC_COMPAT) -print-file-name=include 2>/dev/null)
40 VDSO_CPPFLAGS += $(LINUXINCLUDE)
41
42 # Common C and assembly flags
43 # From top-level Makefile
44 VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
45 VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
46 ifdef CONFIG_DEBUG_INFO
47 VDSO_CAFLAGS += -g
48 endif
49
50 # From arm Makefile
51 VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
52 VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
53 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
54 VDSO_CAFLAGS += -mbig-endian
55 else
56 VDSO_CAFLAGS += -mlittle-endian
57 endif
58
59 # From arm vDSO Makefile
60 VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
61 VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
62 VDSO_CAFLAGS += -march=armv8-a
63
64 VDSO_CFLAGS := $(VDSO_CAFLAGS)
65 VDSO_CFLAGS += -DENABLE_COMPAT_VDSO=1
66 # KBUILD_CFLAGS from top-level Makefile
67 VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
68                -fno-strict-aliasing -fno-common \
69                -Werror-implicit-function-declaration \
70                -Wno-format-security \
71                -Wdeclaration-after-statement \
72                -std=gnu11
73 VDSO_CFLAGS  += -O2
74 # Some useful compiler-dependent flags from top-level Makefile
75 VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
76 VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
77 VDSO_CFLAGS += -fno-strict-overflow
78 VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
79 VDSO_CFLAGS += -Werror=date-time
80 VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
81
82 # The 32-bit compiler does not provide 128-bit integers, which are used in
83 # some headers that are indirectly included from the vDSO code.
84 # This hack makes the compiler happy and should trigger a warning/error if
85 # variables of such type are referenced.
86 VDSO_CFLAGS += -D__uint128_t='void*'
87 # Silence some warnings coming from headers that operate on long's
88 # (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
89 VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
90 VDSO_CFLAGS += -Wno-int-to-pointer-cast
91
92 # Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is
93 # unreliable.
94 ifeq ($(CONFIG_THUMB2_COMPAT_VDSO), y)
95 VDSO_CFLAGS += -mthumb -fomit-frame-pointer
96 else
97 VDSO_CFLAGS += -marm
98 endif
99
100 VDSO_AFLAGS := $(VDSO_CAFLAGS)
101 VDSO_AFLAGS += -D__ASSEMBLY__
102
103 # From arm vDSO Makefile
104 VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
105 VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
106 VDSO_LDFLAGS += -shared --hash-style=sysv --build-id=sha1
107 VDSO_LDFLAGS += --orphan-handling=warn
108
109
110 # Borrow vdsomunge.c from the arm vDSO
111 # We have to use a relative path because scripts/Makefile.host prefixes
112 # $(hostprogs) with $(obj)
113 munge := ../../../arm/vdso/vdsomunge
114 hostprogs := $(munge)
115
116 c-obj-vdso := note.o
117 c-obj-vdso-gettimeofday := vgettimeofday.o
118
119 ifneq ($(c-gettimeofday-y),)
120 VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
121 endif
122
123 VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
124
125 # Build rules
126 targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
127 c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
128 c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
129 asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
130 obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
131
132 targets += vdso.lds
133 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
134
135 include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
136         $(call if_changed,vdsosym)
137
138 # Strip rule for vdso.so
139 $(obj)/vdso.so: OBJCOPYFLAGS := -S
140 $(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
141         $(call if_changed,objcopy)
142
143 $(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
144         $(call if_changed,vdsomunge)
145
146 # Link rule for the .so file, .lds has to be first
147 $(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
148         $(call if_changed,vdsold_and_vdso_check)
149
150 # Compilation rules for the vDSO sources
151 $(c-obj-vdso): %.o: %.c FORCE
152         $(call if_changed_dep,vdsocc)
153 $(c-obj-vdso-gettimeofday): %.o: %.c FORCE
154         $(call if_changed_dep,vdsocc_gettimeofday)
155 $(asm-obj-vdso): %.o: %.S FORCE
156         $(call if_changed_dep,vdsoas)
157
158 # Actual build commands
159 quiet_cmd_vdsold_and_vdso_check = LD32    $@
160       cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
161
162 quiet_cmd_vdsold = LD32    $@
163       cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
164                    -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
165 quiet_cmd_vdsocc = CC32    $@
166       cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
167 quiet_cmd_vdsocc_gettimeofday = CC32    $@
168       cmd_vdsocc_gettimeofday = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
169 quiet_cmd_vdsoas = AS32    $@
170       cmd_vdsoas = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
171
172 quiet_cmd_vdsomunge = MUNGE   $@
173       cmd_vdsomunge = $(obj)/$(munge) $< $@
174
175 # Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
176 gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
177 quiet_cmd_vdsosym = VDSOSYM $@
178 # The AArch64 nm should be able to read an AArch32 binary
179       cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
180
181 # Install commands for the unstripped file
182 quiet_cmd_vdso_install = INSTALL32 $@
183       cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
184
185 vdso.so: $(obj)/vdso.so.dbg
186         @mkdir -p $(MODLIB)/vdso
187         $(call cmd,vdso_install)
188
189 vdso_install: vdso.so