[mc1322x] linking in math libraries?

Mariano Alvira mar at devl.org
Wed Apr 7 17:37:50 EDT 2010


On Wed, Apr 07, 2010 at 01:05:13PM -0700, Andrew Pullin wrote:
> I just got some RedBee hardware and am familiarizing myself with ARM
> programming. I've been using the libmc1322x project codebase, just because all
> the startup code is already there for the RedBee boards.
> 
> I've noticed that if I #include<math.h> , and add -lm to the makefile, it makes
> the executable really large, about 500K if sqrt() is used. I know it has to
> include a fair bit of code for software floating point support, but that seems
> like a lot. My only point of reference is for the MSP430, where including
> software floats is ~10K of compiled code from msp430libc.
> 
> Is there something I am just overlooking? I know that floating point math will
> be slow, and I should learn fixed pointed properly, but I'm still interested to
> figure this out.
> 
>  
> 
> -Andrew
> 

At the end is a patch that solves this for sqrt(). Using dot2map.pl
and looking at the .map itself, I was able to determine: 1) which
.o were pulling in big trees, and 2) which functions in that trouble
object were getting called.

Those were __assert_fail, fputs, fwrite, and stderr. 

I tested this on printf.c. Our printf doesn't have %f, but you can
convince youself that it's working right.

-Mar.
 
diff --git a/Makefile.include b/Makefile.include
index 885e4a2..fc0ac62 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -76,7 +76,7 @@ $(MC1322X)/src/src.a: $(MC1322X)/src/src.a($(SRCOBJS))
 
 %_$(BOARD).elf:	$(OBJDIR)/%.o $(START) $(ISR) $(SRCOBJS) $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a $(OBJDIR)/board.a $(MC1322X)/src/src.a
 	$(CC) $(LDFLAGS)  \
-	-L $(LIBMC1322X) -L $(MC1322X)/src -L $(OBJDIR)  $< -o $@ $(START) $(MC1322X)/src/src.a --start-group $(OBJDIR)/board.a $(LIBMC1322X)/libmc1322x.a --end-group
+	-L $(LIBMC1322X) -L $(MC1322X)/src -L $(OBJDIR) $< -o $@ $(START) $(MC1322X)/src/src.a --start-group $(OBJDIR)/board.a $(LIBMC1322X)/libmc1322x.a -lm --end-group
 
 %.srec:		%.elf
 		$(OBJCOPY) ${OBJCFLAGS} -O srec $< $@
diff --git a/tests/printf.c b/tests/printf.c
index 0d43f06..d09af1d 100644
--- a/tests/printf.c
+++ b/tests/printf.c
@@ -2,6 +2,7 @@
 #include <board.h>
 
 #include <stdio.h>
+#include <math.h>
 
 #include "tests.h"
 #include "config.h"
@@ -11,7 +12,22 @@
 	printf(#x);				\
 	printf("): %d\n", sizeof(x));		\
 	} while(0)
-	       
+
+FILE *stderr;
+
+void __assert_fail(void) {
+	return;
+}
+	
+int fputs(const char *s, FILE *stream) {
+	return 0;
+}
+
+size_t fwrite(const void *ptr, size_t size, size_t nmemb,
+	      FILE *stream) {       
+	return 0;
+}
+
 int main(void)
 {
 	char *ptr = "Hello world!";
@@ -45,6 +61,9 @@ int main(void)
 	printf("%d %s(s)", 0, "message");
 	printf("\n");
 	printf("%d %s(s) with %%\n", 0, "message");
+
+	printf("sqrt(5) * 100  = %d\n", (int) (sqrt(5)*100));
+
 //	sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
 //	sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
 //	sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);



More information about the mc1322x mailing list