Patchwork link problem solved!

login
register
mail settings
Submitter Tony Breeds
Date Aug. 4, 2011, 4:52 a.m.
Message ID <20110804045245.GX20597@ozlabs.org>
Download mbox | patch
Permalink /patch/108348/
State Rejected
Headers show

Comments

Tony Breeds - Aug. 4, 2011, 4:52 a.m.
On Sat, Jul 16, 2011 at 12:32:50AM +0400, Douglas Mencken wrote:
> Finally, I found a workaround for "undefined reference to `getenv',
> `stdout', `printf', `fputs', ..." problem.
> 
> The solution is to link with libc too (it's not auto-linked in the
> case of static linking, unlike dyn-linking; and e2fsprogs static lib
> doesn't include all the libc stuff in it, even in .a ar, i.e. static
> lib).
> sed -i 's/LLIBS.*=.*-lext2fs/LLIBS = -lext2fs -lc/' ./Makefile

Yes we really don't want to link agasit the system libc.  Please try this patch
(on top of http://patchwork.ozlabs.org/patch/77840/)

It works for me on debian sid.

commit 12b4fd99d0921d202f595ee4e4c3470d889ef250
Author: Tony Breeds <tony@bakeyournoodle.com>
Date:   Thu Aug 4 14:31:46 2011 +1000

    Add some "hacky" workarounds for missing libc functions required by libext2fs
    
    Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>


Yours Tony

Patch

diff --git a/Makefile b/Makefile
index f549977..b46165f 100644
--- a/Makefile
+++ b/Makefile
@@ -84,6 +84,7 @@  OBJS = second/crt0.o second/yaboot.o second/cache.o second/prom.o second/file.o
 	second/partition.o second/fs.o second/cfg.o second/setjmp.o second/cmdline.o \
 	second/fs_of.o second/fs_ext2.o second/fs_iso.o second/fs_swap.o \
 	second/iso_util.o \
+	lib/nonstd.o \
 	lib/nosys.o lib/string.o lib/strtol.o lib/vsprintf.o lib/ctype.o lib/malloc.o lib/strstr.o
 
 ifeq ($(USE_MD5_PASSWORDS),y)
diff --git a/include/nonstd.h b/include/nonstd.h
new file mode 100644
index 0000000..2f49d3e
--- /dev/null
+++ b/include/nonstd.h
@@ -0,0 +1,16 @@ 
+/* Copyright */
+
+#ifndef NONSTD_H
+#define NONSTD_H
+
+typedef int FILE;
+
+extern FILE *stdout;
+
+int printf(const char *format, ...);
+int fprintf(FILE *stream, const char *format, ...);
+int fputs(const char *s, FILE *stream);
+int fflush(FILE *stream);
+char *getenv(const char *name);
+
+#endif
diff --git a/lib/nonstd.c b/lib/nonstd.c
new file mode 100644
index 0000000..aec5b05
--- /dev/null
+++ b/lib/nonstd.c
@@ -0,0 +1,49 @@ 
+/* Copyright */
+
+
+#include "ctype.h"
+#include "types.h"
+#include "stddef.h"
+#include "stdlib.h"
+#include "ctype.h"
+#include "prom.h"
+#include "nonstd.h"
+
+FILE *stdout;
+
+int printf(const char *format, ...)
+{
+	va_list ap;
+	va_start (ap, format);
+	prom_vfprintf (prom_stdout, format, ap);
+	va_end (ap);
+
+	return 0;
+}
+
+int fprintf(FILE *stream, const char *format, ...)
+{
+	va_list ap;
+	va_start (ap, format);
+	prom_vfprintf (prom_stdout, format, ap);
+	va_end (ap);
+
+	return 0;
+}
+
+int fputs(const char *s, FILE *stream)
+{
+	prom_printf("%s", s);
+
+	return 0;
+}
+
+int fflush(FILE *stream)
+{
+	return 0;
+}
+
+char *getenv(const char *name)
+{
+	return NULL;
+}