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. 9 TARGET_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 # 30 TARGET-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. 40 TARGET_NO_EXECUTE_CFLAGS := -Wa,--noexecstack 41 TARGET_NO_EXECUTE_LDFLAGS := -Wl,-z,noexecstack 42 43 # These flags disable the above security feature 44 TARGET_DISABLE_NO_EXECUTE_CFLAGS := -Wa,--execstack 45 TARGET_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. 51 TARGET_RELRO_LDFLAGS := -Wl,-z,relro -Wl,-z,now 52 53 # These flags disable the above security feature 54 TARGET_DISABLE_RELRO_LDFLAGS := -Wl,-z,norelro -Wl,-z,lazy 55 56 # This flag are used to provide compiler protection against format 57 # string vulnerabilities. 58 TARGET_FORMAT_STRING_CFLAGS := -Wformat -Werror=format-security 59 60 # This flag disables the above security checks 61 TARGET_DISABLE_FORMAT_STRING_CFLAGS := -Wno-error=format-security 62 63 # NOTE: Ensure that TARGET_LIBGCC is placed after all private objects 64 # and static libraries, but before any other library in the link 65 # command line when generating shared libraries and executables. 66 # 67 # This ensures that all libgcc.a functions required by the target 68 # will be included into it, instead of relying on what's available 69 # on other libraries like libc.so, which may change between system 70 # releases due to toolchain or library changes. 71 # 72 define cmd-build-shared-library 73 $(PRIVATE_CXX) \ 74 -Wl,-soname,$(notdir $(LOCAL_BUILT_MODULE)) \ 75 -shared \ 76 --sysroot=$(call host-path,$(PRIVATE_SYSROOT_LINK)) \ 77 $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \ 78 $(PRIVATE_LDFLAGS) \ 79 $(PRIVATE_LDLIBS) \ 80 -o $(call host-path,$(LOCAL_BUILT_MODULE)) 81 endef 82 83 # The following -rpath-link= are needed for ld.bfd (default for MIPS) when 84 # linking executable to supress warning about missing symbol by *so not directly needed. 85 # ld.gold (default for ARM and X86) and ld.mcld don't emulate this buggy behavior, 86 # and ignore -rpath-link completely. 87 define cmd-build-executable 88 $(PRIVATE_CXX) \ 89 -Wl,--gc-sections \ 90 -Wl,-z,nocopyreloc \ 91 --sysroot=$(call host-path,$(PRIVATE_SYSROOT_LINK)) \ 92 -Wl,-rpath-link=$(call host-path,$(PRIVATE_SYSROOT_LINK)/usr/lib) \ 93 -Wl,-rpath-link=$(call host-path,$(TARGET_OUT)) \ 94 $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \ 95 $(PRIVATE_LDFLAGS) \ 96 $(PRIVATE_LDLIBS) \ 97 -o $(call host-path,$(LOCAL_BUILT_MODULE)) 98 endef 99 100 define cmd-build-static-library 101 $(PRIVATE_AR) $(call host-path,$(LOCAL_BUILT_MODULE)) $(PRIVATE_AR_OBJECTS) 102 endef 103 104 # The strip command is only used for shared libraries and executables. 105 # It is thus safe to use --strip-unneeded, which is only dangerous 106 # when applied to static libraries or object files. 107 cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1) 108 109 # The command objcopy --add-gnu-debuglink= will be needed for Valgrind 110 cmd-add-gnu-debuglink = $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$(strip $(call host-path,$2)) $(call host-path,$1) 111 112 TARGET_LIBGCC = -lgcc 113 TARGET_LDLIBS := -lc -lm 114 115 # 116 # IMPORTANT: The following definitions must use lazy assignment because 117 # the value of TOOLCHAIN_PREFIX or TARGET_CFLAGS can be changed later by 118 # the toolchain's setup.mk script. 119 # 120 121 ifneq ($(findstring ccc-analyzer,$(CC)),) 122 TARGET_CC = $(CC) 123 else 124 TARGET_CC = $(TOOLCHAIN_PREFIX)gcc 125 endif 126 TARGET_CFLAGS = 127 TARGET_CONLYFLAGS = 128 129 ifneq ($(findstring c++-analyzer,$(CXX)),) 130 TARGET_CXX = $(CXX) 131 else 132 TARGET_CXX = $(TOOLCHAIN_PREFIX)g++ 133 endif 134 TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti 135 136 TARGET_RS_CC = $(RENDERSCRIPT_TOOLCHAIN_PREFIX)llvm-rs-cc 137 TARGET_RS_BCC = $(RENDERSCRIPT_TOOLCHAIN_PREFIX)bcc_compat 138 TARGET_RS_FLAGS = -Wall -Werror 139 140 TARGET_ASM = $(HOST_PREBUILT)/yasm 141 TARGET_ASMFLAGS = 142 143 TARGET_LD = $(TOOLCHAIN_PREFIX)ld 144 TARGET_LDFLAGS := 145 146 TARGET_AR = $(TOOLCHAIN_PREFIX)ar 147 TARGET_ARFLAGS := crsD 148 149 TARGET_STRIP = $(TOOLCHAIN_PREFIX)strip 150 151 TARGET_OBJCOPY = $(TOOLCHAIN_PREFIX)objcopy 152 153 TARGET_OBJ_EXTENSION := .o 154 TARGET_LIB_EXTENSION := .a 155 TARGET_SONAME_EXTENSION := .so 156