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