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 define cmd-build-executable 84 $(PRIVATE_CXX) \ 85 -Wl,--gc-sections \ 86 -Wl,-z,nocopyreloc \ 87 --sysroot=$(call host-path,$(PRIVATE_SYSROOT_LINK)) \ 88 $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \ 89 $(PRIVATE_LDFLAGS) \ 90 $(PRIVATE_LDLIBS) \ 91 -o $(call host-path,$(LOCAL_BUILT_MODULE)) 92 endef 93 94 define cmd-build-static-library 95 $(PRIVATE_AR) $(call host-path,$(LOCAL_BUILT_MODULE)) $(PRIVATE_AR_OBJECTS) 96 endef 97 98 # The strip command is only used for shared libraries and executables. 99 # It is thus safe to use --strip-unneeded, which is only dangerous 100 # when applied to static libraries or object files. 101 cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1) 102 103 TARGET_LIBGCC = -lgcc 104 TARGET_LDLIBS := -lc -lm 105 106 # 107 # IMPORTANT: The following definitions must use lazy assignment because 108 # the value of TOOLCHAIN_PREFIX or TARGET_CFLAGS can be changed later by 109 # the toolchain's setup.mk script. 110 # 111 112 ifneq ($(findstring ccc-analyzer,$(CC)),) 113 TARGET_CC = $(CC) 114 else 115 TARGET_CC = $(TOOLCHAIN_PREFIX)gcc 116 endif 117 TARGET_CFLAGS = 118 119 ifneq ($(findstring c++-analyzer,$(CXX)),) 120 TARGET_CXX = $(CXX) 121 else 122 TARGET_CXX = $(TOOLCHAIN_PREFIX)g++ 123 endif 124 TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti 125 126 TARGET_LD = $(TOOLCHAIN_PREFIX)ld 127 TARGET_LDFLAGS := 128 129 TARGET_AR = $(TOOLCHAIN_PREFIX)ar 130 TARGET_ARFLAGS := crs 131 132 TARGET_STRIP = $(TOOLCHAIN_PREFIX)strip 133 134 TARGET_OBJ_EXTENSION := .o 135 TARGET_LIB_EXTENSION := .a 136 TARGET_SONAME_EXTENSION := .so 137