• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Define the libc run-time (crt) support object files that must be built,
2# which are needed to build all other objects (shared/static libs and
3# executables)
4# ==========================================================================
5# AArch64, ARM, MIPS, and x86 all need crtbegin_so/crtend_so.
6#
7# For x86, the .init section must point to a function that calls all
8# entries in the .ctors section. (on ARM this is done through the
9# .init_array section instead).
10#
11# For all the platforms, the .fini_array section must point to a function
12# that will call __cxa_finalize(&__dso_handle) in order to ensure that
13# static C++ destructors are properly called on dlclose().
14#
15# Args:
16#     my_2nd_arch_prefix: set to $(TARGET_2ND_ARCH_VAR_PREFIX) if it's
17#                         for the 2nd arch; otherwise empty.
18
19my_arch := $(TARGET_$(my_2nd_arch_prefix)ARCH)
20
21my_libc_crt_target_crtbegin_file := $(libc_crt_target_crtbegin_file_$(my_arch))
22my_libc_crt_target_crtbegin_so_file := $(libc_crt_target_crtbegin_so_file_$(my_arch))
23
24my_libc_crt_target_cflags := \
25    $(libc_crt_target_cflags) \
26    $(libc_crt_target_cflags_$(my_arch))
27
28my_libc_crt_target_so_cflags := \
29    $(libc_crt_target_so_cflags_$(my_arch)) \
30    $(my_libc_crt_target_cflags)
31
32my_libc_crt_target_ldflags := $(libc_crt_target_ldflags_$(my_arch))
33
34# crtbrand.S -> crtbrand.o
35GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
36$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
37$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
38$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtbrand.S
39	@mkdir -p $(dir $@)
40	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
41		-MD -MF $(@:%.o=%.d) -o $@ -c $<
42	$(transform-d-to-p)
43$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
44
45# crtbegin_so.c -> crtbegin_so1.o
46GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so1.o
47$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
48$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
49$(GEN): $(my_libc_crt_target_crtbegin_so_file)
50	@mkdir -p $(dir $@)
51	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
52		-MD -MF $(@:%.o=%.d) -o $@ -c $<
53	$(transform-d-to-p)
54$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
55
56# crtbegin_so1.o + crtbrand.o -> crtbegin_so.o
57GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
58$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
59$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
60$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so1.o \
61    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
62	@mkdir -p $(dir $@)
63	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
64
65# crtend_so.S -> crtend_so.o
66GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
67$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
68$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
69$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend_so.S
70	@mkdir -p $(dir $@)
71	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
72		-MD -MF $(@:%.o=%.d) -o $@ -c $<
73	$(transform-d-to-p)
74$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
75
76# crtbegin_so.o and crtend_so.o are installed to device
77GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtbegin_so.o
78$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
79	$(hide) mkdir -p $(dir $@) && cp -f $< $@
80ALL_GENERATED_SOURCES += $(GEN)
81
82GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtend_so.o
83$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
84	$(hide) mkdir -p $(dir $@) && cp -f $< $@
85ALL_GENERATED_SOURCES += $(GEN)
86
87# crtbegin.c -> crtbegin_static1.o
88GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o
89$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
90$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
91$(GEN): $(my_libc_crt_target_crtbegin_file)
92	@mkdir -p $(dir $@)
93	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
94		-MD -MF $(@:%.o=%.d) -o $@ -c $<
95	$(transform-d-to-p)
96$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
97
98# crtbegin_static1.o + crtbrand.o -> crtbegin_static.o
99GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
100$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
101$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
102$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o \
103    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
104	@mkdir -p $(dir $@)
105	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
106
107# crtbegin.c -> crtbegin_dynamic1.o
108GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o
109$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
110$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
111$(GEN): $(my_libc_crt_target_crtbegin_file)
112	@mkdir -p $(dir $@)
113	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
114		-MD -MF $(@:%.o=%.d) -o $@ -c $<
115	$(transform-d-to-p)
116$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
117
118# crtbegin_dynamic1.o + crtbrand.o -> crtbegin_dynamic.o
119GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
120$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
121$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
122$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o \
123    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
124	@mkdir -p $(dir $@)
125	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
126
127# crtend.S -> crtend_android.o
128# We rename crtend.o to crtend_android.o to avoid a
129# name clash between gcc and bionic.
130GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
131$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
132$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
133$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend.S
134	@mkdir -p $(dir $@)
135	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
136		-MD -MF $(@:%.o=%.d) -o $@ -c $<
137	$(transform-d-to-p)
138$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
139
140# Clear temp vars
141my_libc_crt_target_ldflags :=
142my_libc_crt_target_so_cflags :=
143my_libc_crt_target_cflags :=
144my_libc_crt_target_crtbegin_so_file :=
145my_libc_crt_target_crtbegin_file :=
146my_arch :=
147