Removing dependency to libgcc_s.so

Michael Hunold hunold at linuxtv.org
Mon Jul 24 03:38:10 PDT 2006


Hi Rob,

on 22.07.2006 20:57 Rob Landley said the following:
> On Friday 21 July 2006 8:56 am, Michael Hunold wrote:
>> Is removing the dependency to libgcc a good thing to do?

> Yes.  What does your patch look like?

Very simple. It uses a loop and substract 64bit division I found on the
net. I attached the patch to this mail.

> It's easy to detect this in platform.h, just do an "#if
> sizeof(long)==4" and if so, you need the fix because gcc is _stupid_
> about this, and always has been.  This would be a good job for an
> always_inline function in platform.h, perhaps?

Rich suggested that busybox should not handle this low level stuff. I
think ideally, this kind of stuff should be in a library similar to
libgcc, except for the bloat.

In my case I probably need this kind of stuff in any application in my
environment.

> Ideally I'd like to make it so that the code itself can still just
> use normal division, so we want to provide an implementation of the
> gcc internal function.

I don't have the experience to judge if this is a good thing or not,
this is why I asked. Probably there will be more discussion.

Alternatively, we can substitue offending 64bit arithmetic divison by a
substitute function, ie. div64(). I admit that this is ugly, though.

> Rob

CU
Michael.

-------------- next part --------------
diff -uraN busybox-1.1.2/libbb/Makefile.in busybox-1.1.2-new/libbb/Makefile.in
--- busybox-1.1.2/libbb/Makefile.in	2006-04-10 21:45:46.000000000 +0200
+++ busybox-1.1.2-new/libbb/Makefile.in	2006-07-21 14:47:55.000000000 +0200
@@ -34,7 +34,7 @@
 	getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
 	perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
 	warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c \
-	bb_echo.c bb_do_delay.c
+	bb_echo.c bb_do_delay.c math.c
 
 # conditionally compiled objects:
 LIBBB-$(CONFIG_FEATURE_SHADOWPASSWDS)+=pwd2spwd.c
diff -uraN busybox-1.1.2/libbb/math.c busybox-1.1.2-new/libbb/math.c
--- busybox-1.1.2/libbb/math.c	1970-01-01 01:00:00.000000000 +0100
+++ busybox-1.1.2-new/libbb/math.c	2006-07-21 15:43:31.000000000 +0200
@@ -0,0 +1,90 @@
+#include <stdint.h>
+#include "libbb.h"
+
+/* based on http://groups.google.de/group/alt.os.development/msg/850334f7242db79d?dmode=source */
+
+void __udiv64(uint64_t numerator, uint64_t denominator, uint64_t *quotient, uint64_t *remainder)
+{
+	uint64_t n, d, x, answer;
+
+	if (!denominator) {
+		n = 0 / 0;
+	}
+
+	for(n = numerator, d = denominator, x = 1; n >= d && ((d & 0x8000000000000000LL) == 0); x <<= 1, d <<= 1)
+		;
+
+	for (answer = 0; x != 0; x >>= 1, d >>= 1) {
+		if (n >= d) {
+			n -= d;
+			answer |= x;
+		}
+	}
+
+	*quotient = answer;
+	*remainder = n;
+}
+
+uint64_t __udivdi3(uint64_t numerator, uint64_t denominator)
+{
+	uint64_t quotient, remainder;
+	__udiv64(numerator, denominator, &quotient, &remainder);
+	return quotient;
+
+}
+
+uint64_t __umoddi3(uint64_t numerator, uint64_t denominator)
+{
+	uint64_t quotient, remainder;
+	__udiv64(numerator, denominator, &quotient, &remainder);
+	return remainder;
+
+}
+
+int64_t __divdi3(int64_t numerator, int64_t denominator)
+{
+	uint64_t quotient, remainder;
+	int flg = 0;
+
+	if (numerator < 0) {
+		flg++;
+		numerator = -numerator;
+	}
+
+	if (denominator < 0) {
+		flg++;
+		denominator = -denominator;
+	}
+
+	__udiv64(numerator, denominator, &quotient, &remainder);
+
+	if ((flg & 1) != 0) {
+		return -quotient;
+	}
+
+	return quotient;
+}
+
+uint64_t __moddi3(int64_t numerator, int64_t denominator)
+{
+	uint64_t quotient, remainder;
+	int flg = 0;
+
+	if (numerator < 0) {
+		flg++;
+		numerator = -numerator;
+	}
+
+	if (denominator < 0) {
+		flg++;
+		denominator = -denominator;
+	}
+
+	__udiv64(numerator, denominator, &quotient, &remainder);
+
+	if ((flg & 1) != 0) {
+		return -quotient;
+	}
+
+	return remainder;
+}
diff -uraN busybox-1.1.2/Makefile busybox-1.1.2-new/Makefile
--- busybox-1.1.2/Makefile	2006-04-10 21:45:46.000000000 +0200
+++ busybox-1.1.2-new/Makefile	2006-07-21 14:47:13.000000000 +0200
@@ -295,7 +295,7 @@
 
 busybox_unstripped: .depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(libraries-y)
 	$(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
-	-o $@ -Wl,--start-group  \
+	-o $@ -nodefaultlibs -Wl,--start-group  -lm -lc  \
 	$(APPLETS_DEFINE) $(APPLET_SRC) \
 	$(BUSYBOX_DEFINE) $(BUSYBOX_SRC) $(libraries-y) \
 	$(LDBUSYBOX) $(LIBRARIES) \


More information about the busybox mailing list