Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 #
0003 # Makefile for vdso32
0004 #
0005 
0006 # Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
0007 # the inclusion of generic Makefile.
0008 ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
0009 include $(srctree)/lib/vdso/Makefile
0010 
0011 # Same as cc-*option, but using CC_COMPAT instead of CC
0012 ifeq ($(CONFIG_CC_IS_CLANG), y)
0013 CC_COMPAT ?= $(CC)
0014 CC_COMPAT += --target=arm-linux-gnueabi
0015 else
0016 CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
0017 endif
0018 
0019 ifeq ($(CONFIG_LD_IS_LLD), y)
0020 LD_COMPAT ?= $(LD)
0021 else
0022 LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
0023 endif
0024 
0025 cc32-option = $(call try-run,\
0026         $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
0027 cc32-disable-warning = $(call try-run,\
0028         $(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
0029 
0030 # We cannot use the global flags to compile the vDSO files, the main reason
0031 # being that the 32-bit compiler may be older than the main (64-bit) compiler
0032 # and therefore may not understand flags set using $(cc-option ...). Besides,
0033 # arch-specific options should be taken from the arm Makefile instead of the
0034 # arm64 one.
0035 # As a result we set our own flags here.
0036 
0037 # KBUILD_CPPFLAGS and NOSTDINC_FLAGS from top-level Makefile
0038 VDSO_CPPFLAGS := -DBUILD_VDSO -D__KERNEL__ -nostdinc
0039 VDSO_CPPFLAGS += -isystem $(shell $(CC_COMPAT) -print-file-name=include 2>/dev/null)
0040 VDSO_CPPFLAGS += $(LINUXINCLUDE)
0041 
0042 # Common C and assembly flags
0043 # From top-level Makefile
0044 VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
0045 VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
0046 ifdef CONFIG_DEBUG_INFO
0047 VDSO_CAFLAGS += -g
0048 endif
0049 
0050 # From arm Makefile
0051 VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
0052 VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
0053 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
0054 VDSO_CAFLAGS += -mbig-endian
0055 else
0056 VDSO_CAFLAGS += -mlittle-endian
0057 endif
0058 
0059 # From arm vDSO Makefile
0060 VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
0061 VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
0062 VDSO_CAFLAGS += -march=armv8-a
0063 
0064 VDSO_CFLAGS := $(VDSO_CAFLAGS)
0065 VDSO_CFLAGS += -DENABLE_COMPAT_VDSO=1
0066 # KBUILD_CFLAGS from top-level Makefile
0067 VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
0068                -fno-strict-aliasing -fno-common \
0069                -Werror-implicit-function-declaration \
0070                -Wno-format-security \
0071                -Wdeclaration-after-statement \
0072                -std=gnu11
0073 VDSO_CFLAGS  += -O2
0074 # Some useful compiler-dependent flags from top-level Makefile
0075 VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
0076 VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
0077 VDSO_CFLAGS += -fno-strict-overflow
0078 VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
0079 VDSO_CFLAGS += -Werror=date-time
0080 VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
0081 
0082 # The 32-bit compiler does not provide 128-bit integers, which are used in
0083 # some headers that are indirectly included from the vDSO code.
0084 # This hack makes the compiler happy and should trigger a warning/error if
0085 # variables of such type are referenced.
0086 VDSO_CFLAGS += -D__uint128_t='void*'
0087 # Silence some warnings coming from headers that operate on long's
0088 # (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
0089 VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
0090 VDSO_CFLAGS += -Wno-int-to-pointer-cast
0091 
0092 # Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is
0093 # unreliable.
0094 ifeq ($(CONFIG_THUMB2_COMPAT_VDSO), y)
0095 VDSO_CFLAGS += -mthumb -fomit-frame-pointer
0096 else
0097 VDSO_CFLAGS += -marm
0098 endif
0099 
0100 VDSO_AFLAGS := $(VDSO_CAFLAGS)
0101 VDSO_AFLAGS += -D__ASSEMBLY__
0102 
0103 # From arm vDSO Makefile
0104 VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
0105 VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
0106 VDSO_LDFLAGS += -shared --hash-style=sysv --build-id=sha1
0107 VDSO_LDFLAGS += --orphan-handling=warn
0108 
0109 
0110 # Borrow vdsomunge.c from the arm vDSO
0111 # We have to use a relative path because scripts/Makefile.host prefixes
0112 # $(hostprogs) with $(obj)
0113 munge := ../../../arm/vdso/vdsomunge
0114 hostprogs := $(munge)
0115 
0116 c-obj-vdso := note.o
0117 c-obj-vdso-gettimeofday := vgettimeofday.o
0118 
0119 ifneq ($(c-gettimeofday-y),)
0120 VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
0121 endif
0122 
0123 VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
0124 
0125 # Build rules
0126 targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
0127 c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
0128 c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
0129 asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
0130 obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
0131 
0132 targets += vdso.lds
0133 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
0134 
0135 include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
0136         $(call if_changed,vdsosym)
0137 
0138 # Strip rule for vdso.so
0139 $(obj)/vdso.so: OBJCOPYFLAGS := -S
0140 $(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
0141         $(call if_changed,objcopy)
0142 
0143 $(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
0144         $(call if_changed,vdsomunge)
0145 
0146 # Link rule for the .so file, .lds has to be first
0147 $(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
0148         $(call if_changed,vdsold_and_vdso_check)
0149 
0150 # Compilation rules for the vDSO sources
0151 $(c-obj-vdso): %.o: %.c FORCE
0152         $(call if_changed_dep,vdsocc)
0153 $(c-obj-vdso-gettimeofday): %.o: %.c FORCE
0154         $(call if_changed_dep,vdsocc_gettimeofday)
0155 $(asm-obj-vdso): %.o: %.S FORCE
0156         $(call if_changed_dep,vdsoas)
0157 
0158 # Actual build commands
0159 quiet_cmd_vdsold_and_vdso_check = LD32    $@
0160       cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
0161 
0162 quiet_cmd_vdsold = LD32    $@
0163       cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
0164                    -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
0165 quiet_cmd_vdsocc = CC32    $@
0166       cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
0167 quiet_cmd_vdsocc_gettimeofday = CC32    $@
0168       cmd_vdsocc_gettimeofday = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
0169 quiet_cmd_vdsoas = AS32    $@
0170       cmd_vdsoas = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
0171 
0172 quiet_cmd_vdsomunge = MUNGE   $@
0173       cmd_vdsomunge = $(obj)/$(munge) $< $@
0174 
0175 # Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
0176 gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
0177 quiet_cmd_vdsosym = VDSOSYM $@
0178 # The AArch64 nm should be able to read an AArch32 binary
0179       cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
0180 
0181 # Install commands for the unstripped file
0182 quiet_cmd_vdso_install = INSTALL32 $@
0183       cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
0184 
0185 vdso.so: $(obj)/vdso.so.dbg
0186         @mkdir -p $(MODLIB)/vdso
0187         $(call cmd,vdso_install)
0188 
0189 vdso_install: vdso.so