• 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# These flags are used to enfore the NX (no execute) security feature in the
12# generated machine code. This adds a special section to the generated shared
13# libraries that instruct the Linux kernel to disable code execution from
14# the stack and the heap.
15TARGET_NO_EXECUTE_CFLAGS  := -Wa,--noexecstack
16TARGET_NO_EXECUTE_LDFLAGS := -Wl,-z,noexecstack
17
18# NOTE: Ensure that TARGET_LIBGCC is placed after all private objects
19#       and static libraries, but before any other library in the link
20#       command line when generating shared libraries and executables.
21#
22#       This ensures that all libgcc.a functions required by the target
23#       will be included into it, instead of relying on what's available
24#       on other libraries like libc.so, which may change between system
25#       releases due to toolchain or library changes.
26#
27define cmd-build-shared-library
28$(PRIVATE_CXX) \
29    -nostdlib -Wl,-soname,$(notdir $@) \
30    -Wl,-shared,-Bsymbolic \
31    $(call host-path,\
32        $(TARGET_CRTBEGIN_SO_O) \
33        $(PRIVATE_OBJECTS)) \
34    $(call link-whole-archives,$(PRIVATE_WHOLE_STATIC_LIBRARIES))\
35    $(call host-path,\
36        $(PRIVATE_STATIC_LIBRARIES) \
37        $(PRIVATE_LIBGCC) \
38        $(PRIVATE_SHARED_LIBRARIES)) \
39    $(PRIVATE_LDFLAGS) \
40    $(PRIVATE_LDLIBS) \
41    $(call host-path,\
42        $(TARGET_CRTEND_SO_O)) \
43    -o $(call host-path,$@)
44endef
45
46define cmd-build-executable
47$(PRIVATE_CXX) \
48    -nostdlib -Bdynamic \
49    -Wl,-dynamic-linker,/system/bin/linker \
50    -Wl,--gc-sections \
51    -Wl,-z,nocopyreloc \
52    $(call host-path,\
53        $(TARGET_CRTBEGIN_DYNAMIC_O) \
54        $(PRIVATE_OBJECTS)) \
55    $(call link-whole-archives,$(PRIVATE_WHOLE_STATIC_LIBRARIES))\
56    $(call host-path,\
57        $(PRIVATE_STATIC_LIBRARIES) \
58        $(PRIVATE_LIBGCC) \
59        $(PRIVATE_SHARED_LIBRARIES)) \
60    $(PRIVATE_LDFLAGS) \
61    $(PRIVATE_LDLIBS) \
62    $(call host-path,\
63        $(TARGET_CRTEND_O)) \
64    -o $(call host-path,$@)
65endef
66
67define cmd-build-static-library
68$(PRIVATE_AR) $(call host-path,$@) $(call host-path,$(PRIVATE_OBJECTS))
69endef
70
71# The strip command is only used for shared libraries and executables.
72# It is thus safe to use --strip-unneeded, which is only dangerous
73# when applied to static libraries or object files.
74cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1)
75
76TARGET_LIBGCC = $(shell $(TARGET_CC) -print-libgcc-file-name)
77TARGET_LDLIBS := -lc -lm
78
79#
80# IMPORTANT: The following definitions must use lazy assignment because
81# the value of TOOLCHAIN_PREFIX or TARGET_CFLAGS can be changed later by
82# the toolchain's setup.mk script.
83#
84
85TARGET_CC       = $(TOOLCHAIN_PREFIX)gcc
86TARGET_CFLAGS   =
87
88TARGET_CXX      = $(TOOLCHAIN_PREFIX)g++
89TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti
90
91TARGET_LD       = $(TOOLCHAIN_PREFIX)ld
92TARGET_LDFLAGS :=
93
94TARGET_AR       = $(TOOLCHAIN_PREFIX)ar
95TARGET_ARFLAGS := crs
96
97TARGET_STRIP    = $(TOOLCHAIN_PREFIX)strip
98