From 2a7ea567829eae57fa7b05bf23a57dd13823d56e Mon Sep 17 00:00:00 2001 From: Anton Staaf Date: Tue, 3 Jun 2014 14:56:54 -0700 Subject: [PATCH] build: Move libs after source or object files When not using gold as the linker the ordering of libraries with respect to objects and source files is important. Previously the build placed -l libraries before source and objects on the gcc command line. This doesn't work with the default ld linker because since none of the symbols in the libraries are yet required they are thrown out before their uses are found in the objects and source. BUG=none BRANCH=none TEST=make buildall Change-Id: Ic9f83ba6138d6592d3b6e28de6fb0688e664f480 Reviewed-on: https://chromium-review.googlesource.com/202469 Tested-by: Anton Staaf Reviewed-by: Vincent Palatin Commit-Queue: Anton Staaf Reviewed-by: Randall Spangler --- Makefile.rules | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile.rules b/Makefile.rules index a2c3cb60c4..9319b3bddc 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -40,11 +40,12 @@ cmd_flat_to_obj = $(CC) -T $(out)/firmware_image.lds -nostdlib $(CPPFLAGS) \ -Wl,--build-id=none -o $@ $< cmd_elf_to_flat = $(OBJCOPY) -O binary $^ $@ cmd_elf_to_dis = $(OBJDUMP) -D $< > $@ -cmd_elf = $(LD) $(LDFLAGS) $(objs) -o $@ -T $< -Map $(out)/$*.map -cmd_exe = $(CC) $(HOST_TEST_LDFLAGS) $(objs) -o $@ +cmd_elf = $(LD) $(objs) $(LDFLAGS) -o $@ -T $< -Map $(out)/$*.map +cmd_exe = $(CC) $(objs) $(HOST_TEST_LDFLAGS) -o $@ cmd_c_to_o = $(CC) $(CFLAGS) -MMD -MF $@.d -c $< -o $@ -cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) \ +cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) \ $(sort $(foreach c,$($(*F)-objs),util/$(c:%.o=%.c)) $*.c) \ + $(BUILD_LDFLAGS) \ -MMD -MF $@.d -o $@ cmd_c_to_host = $(HOSTCC) $(HOST_CFLAGS) -MMD -MF $@.d -o $@ \ $(sort $(foreach c,$($(*F)-objs),util/$(c:%.o=%.c)) $*.c)