• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# This flag are used to provide compiler protection against format
57# string vulnerabilities.
58TARGET_FORMAT_STRING_CFLAGS := -Wformat -Werror=format-security
59
60# This flag disables the above security checks
61TARGET_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#
72define 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))
81endef
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.
87define 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))
98endef
99
100define cmd-build-static-library
101$(PRIVATE_AR) $(call host-path,$(LOCAL_BUILT_MODULE)) $(PRIVATE_AR_OBJECTS)
102endef
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.
107cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1)
108
109# The command objcopy --add-gnu-debuglink= will be needed for Valgrind
110cmd-add-gnu-debuglink = $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$(strip $(call host-path,$2)) $(call host-path,$1)
111
112TARGET_LIBGCC = -lgcc
113TARGET_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
121ifneq ($(findstring ccc-analyzer,$(CC)),)
122TARGET_CC       = $(CC)
123else
124TARGET_CC       = $(TOOLCHAIN_PREFIX)gcc
125endif
126TARGET_CFLAGS   =
127TARGET_CONLYFLAGS =
128
129ifneq ($(findstring c++-analyzer,$(CXX)),)
130TARGET_CXX      = $(CXX)
131else
132TARGET_CXX      = $(TOOLCHAIN_PREFIX)g++
133endif
134TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti
135
136TARGET_RS_CC    = $(RENDERSCRIPT_TOOLCHAIN_PREFIX)llvm-rs-cc
137TARGET_RS_BCC   = $(RENDERSCRIPT_TOOLCHAIN_PREFIX)bcc_compat
138TARGET_RS_FLAGS = -Wall -Werror
139
140TARGET_ASM      = $(HOST_PREBUILT)/yasm
141TARGET_ASMFLAGS =
142
143TARGET_LD       = $(TOOLCHAIN_PREFIX)ld
144TARGET_LDFLAGS :=
145
146TARGET_AR       = $(TOOLCHAIN_PREFIX)ar
147TARGET_ARFLAGS := crsD
148
149TARGET_STRIP    = $(TOOLCHAIN_PREFIX)strip
150
151TARGET_OBJCOPY  = $(TOOLCHAIN_PREFIX)objcopy
152
153TARGET_OBJ_EXTENSION := .o
154TARGET_LIB_EXTENSION := .a
155TARGET_SONAME_EXTENSION := .so
156