FROMLIST: [PATCH 4/6] arm64: compat: Add a 32-bit vDSO
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / arch / arm64 / kernel / vdso32 / Makefile
1 #
2 # Building a vDSO image for AArch32.
3 #
4 # Author: Kevin Brodsky <kevin.brodsky@arm.com>
5 # A mix between the arm64 and arm vDSO Makefiles.
6
7 ifeq ($(cc-name),clang)
8 CC_ARM32 := $(cc-name) $(CLANG_TARGET_ARM32) -no-integrated-as
9 else
10 CC_ARM32 := $(CROSS_COMPILE_ARM32)$(cc-name)
11 endif
12
13 # Same as cc-*option, but using CC_ARM32 instead of CC
14 cc32-option = $(call try-run,\
15 $(CC_ARM32) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
16 cc32-disable-warning = $(call try-run,\
17 $(CC_ARM32) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
18 cc32-ldoption = $(call try-run,\
19 $(CC_ARM32) $(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 $(CC_ARM32) -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 $(CC_ARM32)), 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 # 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 VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
94 # From arm vDSO Makefile
95 VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
96 VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
97 VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
98 VDSO_LDFLAGS += $(call cc32-ldoption,-Wl$(comma)--hash-style=sysv)
99 VDSO_LDFLAGS += $(call cc32-ldoption,-Wl$(comma)--build-id)
100 VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
101
102
103 # Borrow vdsomunge.c from the arm vDSO
104 # We have to use a relative path because scripts/Makefile.host prefixes
105 # $(hostprogs-y) with $(obj)
106 munge := ../../../arm/vdso/vdsomunge
107 hostprogs-y := $(munge)
108
109 c-obj-vdso := vgettimeofday.o
110 asm-obj-vdso := sigreturn.o
111
112 # Build rules
113 targets := $(c-obj-vdso) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
114 c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
115 asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
116 obj-vdso := $(c-obj-vdso) $(asm-obj-vdso)
117
118 obj-y += vdso.o
119 extra-y += vdso.lds
120 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
121
122 # Force dependency (vdso.s includes vdso.so through incbin)
123 $(obj)/vdso.o: $(obj)/vdso.so
124
125 include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
126 $(call if_changed,vdsosym)
127
128 # Strip rule for vdso.so
129 $(obj)/vdso.so: OBJCOPYFLAGS := -S
130 $(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
131 $(call if_changed,objcopy)
132
133 $(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
134 $(call if_changed,vdsomunge)
135
136 # Link rule for the .so file, .lds has to be first
137 $(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
138 $(call if_changed,vdsold)
139
140 # Compilation rules for the vDSO sources
141 $(filter-out vgettimeofday.o, $(c-obj-vdso)): %.o: %.c FORCE
142 $(call if_changed_dep,vdsocc)
143 $(asm-obj-vdso): %.o: %.S FORCE
144 $(call if_changed_dep,vdsoas)
145
146 # Actual build commands
147 quiet_cmd_vdsold = VDSOL32 $@
148 cmd_vdsold = $(CC_ARM32) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
149 -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
150 quiet_cmd_vdsocc = VDSOC32 $@
151 cmd_vdsocc = $(CC_ARM32) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
152 quiet_cmd_vdsoas = VDSOA32 $@
153 cmd_vdsoas = $(CC_ARM32) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
154
155 quiet_cmd_vdsomunge = MUNGE $@
156 cmd_vdsomunge = $(obj)/$(munge) $< $@
157
158 # Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
159 gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
160 quiet_cmd_vdsosym = VDSOSYM $@
161 # The AArch64 nm should be able to read an AArch32 binary
162 cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
163
164 # Install commands for the unstripped file
165 quiet_cmd_vdso_install = INSTALL $@
166 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
167
168 vdso.so: $(obj)/vdso.so.dbg
169 @mkdir -p $(MODLIB)/vdso
170 $(call cmd,vdso_install)
171
172 vdso_install: vdso.so