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 # 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 # 65 define cmd-build-shared-library 66 $(PRIVATE_CXX) \ 67 -Wl,-soname,$(notdir $(LOCAL_BUILT_MODULE)) \ 68 -shared \ 69 --sysroot=$(call host-path,$(PRIVATE_SYSROOT_LINK)) \ 70 $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \ 71 $(PRIVATE_LDFLAGS) \ 72 $(PRIVATE_LDLIBS) \ 73 -o $(call host-path,$(LOCAL_BUILT_MODULE)) 74 endef 75 76 define cmd-build-executable 77 $(PRIVATE_CXX) \ 78 -Wl,--gc-sections \ 79 -Wl,-z,nocopyreloc \ 80 --sysroot=$(call host-path,$(PRIVATE_SYSROOT_LINK)) \ 81 $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \ 82 $(PRIVATE_LDFLAGS) \ 83 $(PRIVATE_LDLIBS) \ 84 -o $(call host-path,$(LOCAL_BUILT_MODULE)) 85 endef 86 87 define cmd-build-static-library 88 $(PRIVATE_AR) $(call host-path,$(LOCAL_BUILT_MODULE)) $(PRIVATE_AR_OBJECTS) 89 endef 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. 94 cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1) 95 96 TARGET_LIBGCC = -lgcc 97 TARGET_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 105 ifneq ($(findstring ccc-analyzer,$(CC)),) 106 TARGET_CC = $(CC) 107 else 108 TARGET_CC = $(TOOLCHAIN_PREFIX)gcc 109 endif 110 TARGET_CFLAGS = 111 112 ifneq ($(findstring c++-analyzer,$(CXX)),) 113 TARGET_CXX = $(CXX) 114 else 115 TARGET_CXX = $(TOOLCHAIN_PREFIX)g++ 116 endif 117 TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti 118 119 TARGET_LD = $(TOOLCHAIN_PREFIX)ld 120 TARGET_LDFLAGS := 121 122 TARGET_AR = $(TOOLCHAIN_PREFIX)ar 123 TARGET_ARFLAGS := crs 124 125 TARGET_STRIP = $(TOOLCHAIN_PREFIX)strip 126 127 TARGET_OBJ_EXTENSION := .o 128 TARGET_LIB_EXTENSION := .a 129 TARGET_SONAME_EXTENSION := .so 130