@@ -146,19 +146,10 @@ define TARGET_RT_STARTUP
146146$$(foreach obj,rsbegin rsend, \
147147 $$(eval $$(call TARGET_RUSTRT_STARTUP_OBJ,$(1 ) ,$(2 ) ,$(3 ) ,$$(obj ) ) ) )
148148
149+ # Expand build rules for libc startup objects
149150$$(foreach obj,$$(CFG_LIBC_STARTUP_OBJECTS_$(2 ) ) , \
150- $$(eval $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /stamp.core : $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /$$(obj ) ) \
151- $$(eval $$(call COPY_LIBC_STARTUP,$$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) ,$$(obj ) ) ) )
152- endef
153-
154- # TARGET_RT_STARTUP's helper for copying LibC startup objects
155- # $(1) - target lib directory
156- # $(2) - object name
157- define COPY_LIBC_STARTUP
151+ $$(eval $$(call TARGET_LIBC_STARTUP_OBJ,$(1 ) ,$(2 ) ,$(3 ) ,$$(obj ) ) ) )
158152
159- $(1 ) /$(2 ) : $$(CFG_LIBC_DIR ) /$(2 )
160- @$$(call E, cp: $$@ )
161- @cp $$^ $$@
162153endef
163154
164155# Macro for building runtime startup/shutdown object files;
@@ -167,10 +158,10 @@ endef
167158# $(1) - stage
168159# $(2) - target triple
169160# $(3) - host triple
170- # $(4) - object name
161+ # $(4) - object basename
171162define TARGET_RUSTRT_STARTUP_OBJ
172163
173- $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /$(4 ) .o:\
164+ $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /$(4 ) .o: \
174165 $(S ) src/rtstartup/$(4 ) .rs \
175166 $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /stamp.core \
176167 $$(HSREQ$(1 ) _T_$(2 ) _H_$(3 ) ) \
@@ -183,9 +174,31 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(4).o:\
183174# but before everything else (since they are needed for linking dylib crates).
184175$$(foreach crate, $$(TARGET_CRATES ) , \
185176 $$(if $$(findstring core,$$(DEPS_$$(crate ) ) ) , \
186- $$(eval $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /stamp.$$(crate ) : $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /$(4 ) .o) ) )
177+ $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /stamp.$$(crate ) ) ) : $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /$(4 ) .o
178+
187179endef
188180
181+ # Macro for copying libc startup objects into the target's lib directory.
182+ #
183+ # $(1) - stage
184+ # $(2) - target triple
185+ # $(3) - host triple
186+ # $(4) - object name
187+ define TARGET_LIBC_STARTUP_OBJ
188+
189+ # Ask gcc where the startup object is located
190+ $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /$(4 ) : $$(shell $$(CC_$(2 ) ) -print-file-name=$(4 ) )
191+ @$$(call E, cp: $$@ )
192+ @cp $$^ $$@
193+
194+ # Make sure this is done before libcore has finished building
195+ # (libcore itself does not depend on these objects, but other crates do,
196+ # so might as well do it here)
197+ $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /stamp.core : $$(TLIB$(1 ) _T_$(2 ) _H_$(3 ) ) /$(4 )
198+
199+ endef
200+
201+
189202# Every recipe in RUST_TARGET_STAGE_N outputs to $$(TLIB$(1)_T_$(2)_H_$(3),
190203# a directory that can be cleaned out during the middle of a run of
191204# the get-snapshot.py script. Therefore, every recipe needs to have
0 commit comments