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