[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH]: 'id -u' bug lives on



The 'id -u' bug did not get fixed in busybox-0.51.  This was due to ld not
knowing which version of getpwuid() etc. we actually wanted.  It was finding
the glibc symbols rather than the libpwd.a symbols. 

One solution is to simply re-order $(LIBBB_LIB) and $(PWD_LIB) on the command
line.

Another solution that may be a better general solution is to perform a
multi-pass incremental link omitting the standard library, followed by a link
including the standard library.  The multi-pass link means order isn't
important, ld will resolve all possible symbols with the object files it is
given.  We do it incrementally so that we can let gcc find the standard
libraries for us when we are done including busybox symbols. The nice thing
about this solution is that the order of objects on the link line will no
longer determine what ends up in our binary.

Following is a patch that implements the multi-pass incremental link.  I also
added the output of a linker map file.  This is just a debugging tool that
helps figure out what is going on.

David

diff -ur busybox-0.51_orig/Makefile busybox-0.51/Makefile
--- busybox-0.51_orig/Makefile	Tue Apr 10 11:35:02 2001
+++ busybox-0.51/Makefile	Sat Apr 14 14:16:24 2001
@@ -144,11 +144,11 @@
 endif
 ifeq ($(strip $(DODEBUG)),true)
     CFLAGS  += $(WARNINGS) -g -D_GNU_SOURCE
-    LDFLAGS += -Wl,-warn-common
+    LDFLAGS += -warn-common
     STRIP    =
 else
     CFLAGS  += $(WARNINGS) $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
-    LDFLAGS += -s -Wl,-warn-common
+    LDFLAGS += -s -warn-common
     STRIP    = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
 endif
 ifeq ($(strip $(DOSTATIC)),true)
@@ -325,9 +325,13 @@
 	- mkdir -p docs
 	(cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
 
+# syntax limits our use of comma in the following patsubst
+comma:=,
 
 busybox: $(PWD_LIB) $(LIBBB_LIB) $(OBJECTS) 
-	$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(PWD_LIB) $(LIBBB_LIB) $(LIBRARIES)
+	$(LD) -i $(LDFLAGS) -o $@.obj --start-group $(OBJECTS) $(PWD_LIB) $(LIBBB_LIB) \
+		$(LIBRARIES) --end-group -Map $@.o.map
+	$(CC) $(patsubst %,-Wl$(comma)%,$(LDFLAGS)) $@.obj -o $@
 	$(STRIP)
 
 # Without VPATH, rule expands to "/bin/sh busybox.mkll Config.h applets.h"
@@ -376,7 +380,7 @@
 	    docs/busybox.pdf docs/busybox.lineo.com/busybox.html
 	- rm -f multibuild.log Config.h.orig
 	- rm -rf docs/busybox _install libpwd.a libbb.a
-	- rm -f busybox.links libbb/loop.h *~ slist.mk core applet_source_list
+	- rm -f busybox.links libbb/loop.h *~ slist.mk core applet_source_list busybox.o*
 	- find -name \*.o -exec rm -f {} \;
 
 distclean: clean



Reply to: