Merge tag 'gpio-v5.3-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux...
[sfrench/cifs-2.6.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 COMPATCC := $(CROSS_COMPILE_COMPAT)gcc
12
13 # Same as cc-*option, but using COMPATCC instead of CC
14 cc32-option = $(call try-run,\
15         $(COMPATCC) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
16 cc32-disable-warning = $(call try-run,\
17         $(COMPATCC) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
18 cc32-ldoption = $(call try-run,\
19         $(COMPATCC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
20
21 # We cannot use the global flags to compile the vDSO files, the main reason
22 # being that the 32-bit compiler may be older than the main (64-bit) compiler
23 # and therefore may not understand flags set using $(cc-option ...). Besides,
24 # arch-specific options should be taken from the arm Makefile instead of the
25 # arm64 one.
26 # As a result we set our own flags here.
27
28 # From top-level Makefile
29 # NOSTDINC_FLAGS
30 VDSO_CPPFLAGS := -nostdinc -isystem $(shell $(COMPATCC) -print-file-name=include)
31 VDSO_CPPFLAGS += $(LINUXINCLUDE)
32 VDSO_CPPFLAGS += $(KBUILD_CPPFLAGS)
33
34 # Common C and assembly flags
35 # From top-level Makefile
36 VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
37 VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
38 ifdef CONFIG_DEBUG_INFO
39 VDSO_CAFLAGS += -g
40 endif
41 ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(COMPATCC)), y)
42 VDSO_CAFLAGS += -DCC_HAVE_ASM_GOTO
43 endif
44
45 # From arm Makefile
46 VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
47 VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
48 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
49 VDSO_CAFLAGS += -mbig-endian
50 else
51 VDSO_CAFLAGS += -mlittle-endian
52 endif
53
54 # From arm vDSO Makefile
55 VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
56 VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
57
58 # Try to compile for ARMv8. If the compiler is too old and doesn't support it,
59 # fall back to v7. There is no easy way to check for what architecture the code
60 # is being compiled, so define a macro specifying that (see arch/arm/Makefile).
61 VDSO_CAFLAGS += $(call cc32-option,-march=armv8-a -D__LINUX_ARM_ARCH__=8,\
62                                    -march=armv7-a -D__LINUX_ARM_ARCH__=7)
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                -std=gnu89
72 VDSO_CFLAGS  += -O2
73 # Some useful compiler-dependent flags from top-level Makefile
74 VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
75 VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
76 VDSO_CFLAGS += $(call cc32-option,-fno-strict-overflow)
77 VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
78 VDSO_CFLAGS += $(call cc32-option,-Werror=date-time)
79 VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
80
81 # The 32-bit compiler does not provide 128-bit integers, which are used in
82 # some headers that are indirectly included from the vDSO code.
83 # This hack makes the compiler happy and should trigger a warning/error if
84 # variables of such type are referenced.
85 VDSO_CFLAGS += -D__uint128_t='void*'
86 # Silence some warnings coming from headers that operate on long's
87 # (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
88 VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
89 VDSO_CFLAGS += -Wno-int-to-pointer-cast
90
91 VDSO_AFLAGS := $(VDSO_CAFLAGS)
92 VDSO_AFLAGS += -D__ASSEMBLY__
93
94 VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
95 # From arm vDSO Makefile
96 VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
97 VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
98 VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
99 VDSO_LDFLAGS += -Wl,--hash-style=sysv
100 VDSO_LDFLAGS += -Wl,--build-id
101 VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
102
103
104 # Borrow vdsomunge.c from the arm vDSO
105 # We have to use a relative path because scripts/Makefile.host prefixes
106 # $(hostprogs-y) with $(obj)
107 munge := ../../../arm/vdso/vdsomunge
108 hostprogs-y := $(munge)
109
110 c-obj-vdso := note.o
111 c-obj-vdso-gettimeofday := vgettimeofday.o
112 asm-obj-vdso := sigreturn.o
113
114 ifneq ($(c-gettimeofday-y),)
115 VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
116 endif
117
118 VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
119
120 # Build rules
121 targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
122 c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
123 c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
124 asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
125 obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
126
127 obj-y += vdso.o
128 extra-y += vdso.lds
129 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
130
131 # Force dependency (vdso.s includes vdso.so through incbin)
132 $(obj)/vdso.o: $(obj)/vdso.so
133
134 include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
135         $(call if_changed,vdsosym)
136
137 # Strip rule for vdso.so
138 $(obj)/vdso.so: OBJCOPYFLAGS := -S
139 $(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
140         $(call if_changed,objcopy)
141
142 $(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
143         $(call if_changed,vdsomunge)
144
145 # Link rule for the .so file, .lds has to be first
146 $(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
147         $(call if_changed,vdsold_and_vdso_check)
148
149 # Compilation rules for the vDSO sources
150 $(c-obj-vdso): %.o: %.c FORCE
151         $(call if_changed_dep,vdsocc)
152 $(c-obj-vdso-gettimeofday): %.o: %.c FORCE
153         $(call if_changed_dep,vdsocc_gettimeofday)
154 $(asm-obj-vdso): %.o: %.S FORCE
155         $(call if_changed_dep,vdsoas)
156
157 # Actual build commands
158 quiet_cmd_vdsold_and_vdso_check = LD32    $@
159       cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
160
161 quiet_cmd_vdsold = LD32    $@
162       cmd_vdsold = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
163                    -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
164 quiet_cmd_vdsocc = CC32    $@
165       cmd_vdsocc = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
166 quiet_cmd_vdsocc_gettimeofday = CC32    $@
167       cmd_vdsocc_gettimeofday = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
168 quiet_cmd_vdsoas = AS32    $@
169       cmd_vdsoas = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
170
171 quiet_cmd_vdsomunge = MUNGE   $@
172       cmd_vdsomunge = $(obj)/$(munge) $< $@
173
174 # Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
175 gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
176 quiet_cmd_vdsosym = VDSOSYM $@
177 # The AArch64 nm should be able to read an AArch32 binary
178       cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
179
180 # Install commands for the unstripped file
181 quiet_cmd_vdso_install = INSTALL $@
182       cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
183
184 vdso.so: $(obj)/vdso.so.dbg
185         @mkdir -p $(MODLIB)/vdso
186         $(call cmd,vdso_install)
187
188 vdso_install: vdso.so