-# Compile initfini.c to assembly code, which contains embedded shell
-# commands that prodice crti.s-new and crtn.s-new when run. We need to
-# disable emission of .size directives and debugging information, since
-# they will get confused by the splitting of the output we do.
-$(objpfx)cr%i.s $(objpfx)cr%n.s: initfini.c; $(initfini)
-
-define initfini
--rm -f $(objpfx)crtcommon.tmp
-(echo 'cat > crtcommon.tmp <<\EOF_common'; \
- $(CC) $< $(CPPFLAGS) $(CFLAGS) \
- -fPIC -finhibit-size-directive -g0 -S -o -; \
- echo 'EOF_common') | (cd $(@D); $(SHELL))
-cat $(objpfx)crtcommon.tmp >> $(objpfx)crti.s-new
-cat $(objpfx)crtcommon.tmp >> $(objpfx)crtn.s-new
-rm -f $(objpfx)crtcommon.tmp
-mv -f $(objpfx)crti.s-new $(subst crtn,crti,$@)
-mv -f $(objpfx)crtn.s-new $(subst crti,crtn,$@)
-endef
+# Special rules for the building of crti.o and crtn.o
+$(objpfx)crt%.o: $(objpfx)crt%.S $(objpfx)defs.h
+ $(compile.S) -g0 $(ASFLAGS-.os) -o $@
+
+CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions
+
+$(objpfx)initfini.s: initfini.c
+ $(compile.c) -S $(CFLAGS-initfini.s) -finhibit-size-directive \
+ $(no-exceptions) -o $@
+
+# We only have one kind of startup code files. Static binaries and
+# shared libraries are build using the PIC version.
+$(objpfx)crti.S: $(objpfx)initfini.s
+ sed -n -e '1,/@HEADER_ENDS/p' \
+ -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
+ -e '/@TRAILER_BEGINS/,$$p' $< > $@