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 35# See the comment in crtbrand.c for the reason why we need to generate 36# crtbrand.s before generating crtbrand.o. 37GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s 38$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC) 39$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags) 40$(GEN): $(LOCAL_PATH)/bionic/crtbrand.c 41 @mkdir -p $(dir $@) 42 $(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) -S \ 43 -MD -MF $(@:%.s=%.d) -o $@ $< 44 $(hide) sed -i -e '/\.note\.ABI-tag/s/progbits/note/' $@ 45 $(call transform-d-to-p-args,$(@:%.s=%.d),$(@:%.s=%.P)) 46-include $(GEN:%.s=%.P) 47 48 49GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o 50$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC) 51$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags) 52$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s 53 @mkdir -p $(dir $@) 54 $(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) -o $@ -c $< 55 56 57GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o 58$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC) 59$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags) 60$(GEN): $(my_libc_crt_target_crtbegin_so_file) 61 @mkdir -p $(dir $@) 62 $(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \ 63 -MD -MF $(@:%.o=%.d) -o $@ -c $< 64 $(transform-d-to-p) 65-include $(GEN:%.o=%.P) 66 67 68GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o 69$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC) 70$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags) 71$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend_so.S 72 @mkdir -p $(dir $@) 73 $(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \ 74 -MD -MF $(@:%.o=%.d) -o $@ -c $< 75 $(transform-d-to-p) 76-include $(GEN:%.o=%.P) 77 78 79# The following two are installed to device 80GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtbegin_so.o 81$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o 82 $(hide) mkdir -p $(dir $@) && cp -f $< $@ 83ALL_GENERATED_SOURCES += $(GEN) 84 85GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtend_so.o 86$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o 87 $(hide) mkdir -p $(dir $@) && cp -f $< $@ 88ALL_GENERATED_SOURCES += $(GEN) 89 90 91GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o 92$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC) 93$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags) 94$(GEN): $(my_libc_crt_target_crtbegin_file) 95 @mkdir -p $(dir $@) 96 $(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \ 97 -MD -MF $(@:%.o=%.d) -o $@ -c $< 98 $(transform-d-to-p) 99-include $(GEN:%.o=%.P) 100 101 102GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o 103$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD) 104$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags) 105$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o \ 106 $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o 107 @mkdir -p $(dir $@) 108 $(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^ 109 110 111GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o 112$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC) 113$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags) 114$(GEN): $(my_libc_crt_target_crtbegin_file) 115 @mkdir -p $(dir $@) 116 $(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \ 117 -MD -MF $(@:%.o=%.d) -o $@ -c $< 118 $(transform-d-to-p) 119-include $(GEN:%.o=%.P) 120 121 122GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o 123$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD) 124$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags) 125$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o \ 126 $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o 127 @mkdir -p $(dir $@) 128 $(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^ 129 130 131# We rename crtend.o to crtend_android.o to avoid a 132# name clash between gcc and bionic. 133GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o 134$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC) 135$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags) 136$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend.S 137 @mkdir -p $(dir $@) 138 $(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \ 139 -MD -MF $(@:%.o=%.d) -o $@ -c $< 140 $(transform-d-to-p) 141-include $(GEN:%.o=%.P) 142 143# Clear temp vars 144my_libc_crt_target_ldflags := 145my_libc_crt_target_so_cflags := 146my_libc_crt_target_cflags := 147my_libc_crt_target_crtbegin_so_file := 148my_libc_crt_target_crtbegin_file := 149my_arch := 150