1# The following definitions are the defaults used by all toolchains. 2# This is included in setup-toolchain.mk just before the inclusion 3# of the toolchain's specific setup.mk file which can then override 4# these definitions. 5# 6 7# These flags are used to ensure that a binary doesn't reference undefined 8# flags. 9TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined 10 11 12# Return the list of object, static libraries and shared libraries as they 13# must appear on the final static linker command (order is important). 14# 15# This can be over-ridden by a specific toolchain. Note that by default 16# we always put libgcc _after_ all static libraries and _before_ shared 17# libraries. This ensures that any libgcc function used by the final 18# executable will be copied into it. Otherwise, it could contain 19# symbol references to the same symbols as exported by shared libraries 20# and this causes binary compatibility problems when they come from 21# system libraries (e.g. libc.so and others). 22# 23# IMPORTANT: The result must use the host path convention. 24# 25# $1: object files 26# $2: static libraries 27# $3: whole static libraries 28# $4: shared libraries 29# 30TARGET-get-linker-objects-and-libraries = \ 31 $(call host-path, $1) \ 32 $(call link-whole-archives,$3) \ 33 $(call host-path, $2 $(PRIVATE_LIBGCC) $4) \ 34 35 36# These flags are used to enforce the NX (no execute) security feature in the 37# generated machine code. This adds a special section to the generated shared 38# libraries that instruct the Linux kernel to disable code execution from 39# the stack and the heap. 40TARGET_NO_EXECUTE_CFLAGS := -Wa,--noexecstack 41TARGET_NO_EXECUTE_LDFLAGS := -Wl,-z,noexecstack 42 43# These flags disable the above security feature 44TARGET_DISABLE_NO_EXECUTE_CFLAGS := -Wa,--execstack 45TARGET_DISABLE_NO_EXECUTE_LDFLAGS := -Wl,-z,execstack 46 47# These flags are used to mark certain regions of the resulting 48# executable or shared library as being read-only after the dynamic 49# linker has run. This makes GOT overwrite security attacks harder to 50# exploit. 51TARGET_RELRO_LDFLAGS := -Wl,-z,relro -Wl,-z,now 52 53# These flags disable the above security feature 54TARGET_DISABLE_RELRO_LDFLAGS := -Wl,-z,norelro -Wl,-z,lazy 55 56# NOTE: Ensure that TARGET_LIBGCC is placed after all private objects 57# and static libraries, but before any other library in the link 58# command line when generating shared libraries and executables. 59# 60# This ensures that all libgcc.a functions required by the target 61# will be included into it, instead of relying on what's available 62# on other libraries like libc.so, which may change between system 63# releases due to toolchain or library changes. 64# 65define cmd-build-shared-library 66$(PRIVATE_CXX) \ 67 -Wl,-soname,$(notdir $(LOCAL_BUILT_MODULE)) \ 68 -shared \ 69 --sysroot=$(call host-path,$(PRIVATE_SYSROOT)) \ 70 $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \ 71 $(PRIVATE_LDFLAGS) \ 72 $(PRIVATE_LDLIBS) \ 73 -o $(call host-path,$(LOCAL_BUILT_MODULE)) 74endef 75 76define cmd-build-executable 77$(PRIVATE_CXX) \ 78 -Wl,--gc-sections \ 79 -Wl,-z,nocopyreloc \ 80 --sysroot=$(call host-path,$(PRIVATE_SYSROOT)) \ 81 $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \ 82 $(PRIVATE_LDFLAGS) \ 83 $(PRIVATE_LDLIBS) \ 84 -o $(call host-path,$(LOCAL_BUILT_MODULE)) 85endef 86 87define cmd-build-static-library 88$(PRIVATE_AR) $(call host-path,$(LOCAL_BUILT_MODULE)) $(PRIVATE_AR_OBJECTS) 89endef 90 91# The strip command is only used for shared libraries and executables. 92# It is thus safe to use --strip-unneeded, which is only dangerous 93# when applied to static libraries or object files. 94cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1) 95 96TARGET_LIBGCC = $(shell $(TARGET_CC) -print-libgcc-file-name) 97TARGET_LDLIBS := -lc -lm 98 99# 100# IMPORTANT: The following definitions must use lazy assignment because 101# the value of TOOLCHAIN_PREFIX or TARGET_CFLAGS can be changed later by 102# the toolchain's setup.mk script. 103# 104 105TARGET_CC = $(TOOLCHAIN_PREFIX)gcc 106TARGET_CFLAGS = 107 108TARGET_CXX = $(TOOLCHAIN_PREFIX)g++ 109TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti 110 111TARGET_LD = $(TOOLCHAIN_PREFIX)ld 112TARGET_LDFLAGS := 113 114TARGET_AR = $(TOOLCHAIN_PREFIX)ar 115TARGET_ARFLAGS := crs 116 117TARGET_STRIP = $(TOOLCHAIN_PREFIX)strip 118