[klibc] [PATCH] fix build failure when CONFIG_KLIBC_ZLIB is not set

Christophe Leroy christophe.leroy at c-s.fr
Tue Jan 22 08:42:47 PST 2019


When CONFIG_KLIBC_ZLIB is not set, related functions
shall not be called otherwise build failure is encountered:

  KLIBCLD usr/kinit/static/kinit
usr/kinit/ramdisk_load.o: In function `load_ramdisk_compressed':
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:68: undefined reference to `inflateInit2_'
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:116: undefined reference to `inflate'
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:128: undefined reference to `inflateEnd'
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:132: undefined reference to `inflateEnd'
make[2]: *** [usr/kinit/shared/kinit] Error 1

Signed-off-by: Christophe Leroy <christophe.leroy at c-s.fr>
---
 usr/kinit/initrd.c       | 6 ++++++
 usr/kinit/ramdisk_load.c | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/usr/kinit/initrd.c b/usr/kinit/initrd.c
index 7eece2ce..a8385a98 100644
--- a/usr/kinit/initrd.c
+++ b/usr/kinit/initrd.c
@@ -54,11 +54,14 @@ static int rd_copy_image(const char *path)
 {
 	int ffd = open(path, O_RDONLY);
 	int rv = -1;
+#ifdef CONFIG_KLIBC_ZLIB
 	unsigned char gzip_magic[2];
+#endif
 
 	if (ffd < 0)
 		goto barf;
 
+#ifdef CONFIG_KLIBC_ZLIB
 	if (xpread(ffd, gzip_magic, 2, 0) == 2 &&
 	    gzip_magic[0] == 037 && gzip_magic[1] == 0213) {
 		FILE *wfd = fopen("/dev/ram0", "w");
@@ -67,6 +70,9 @@ static int rd_copy_image(const char *path)
 		rv = load_ramdisk_compressed(path, wfd, 0);
 		fclose(wfd);
 	} else {
+#else
+	{
+#endif
 		int dfd = open("/dev/ram0", O_WRONLY);
 		if (dfd < 0)
 			goto barf;
diff --git a/usr/kinit/ramdisk_load.c b/usr/kinit/ramdisk_load.c
index 2b3503ad..c30f61c2 100644
--- a/usr/kinit/ramdisk_load.c
+++ b/usr/kinit/ramdisk_load.c
@@ -13,7 +13,9 @@
 #include "kinit.h"
 #include "do_mounts.h"
 #include "fstype.h"
+#ifdef CONFIG_KLIBC_ZLIB
 #include "zlib.h"
+#endif
 
 #define BUF_SZ		65536
 
@@ -46,6 +48,7 @@ static int change_disk(const char *devpath, int rfd, int disk)
 	return open(devpath, O_RDONLY);
 }
 
+#ifdef CONFIG_KLIBC_ZLIB
 /* Also used in initrd.c */
 int load_ramdisk_compressed(const char *devpath, FILE * wfd,
 			    off_t ramdisk_start)
@@ -133,6 +136,7 @@ err2:
 err1:
 	return -1;
 }
+#endif
 
 static int
 load_ramdisk_raw(const char *devpath, FILE * wfd, off_t ramdisk_start,
@@ -253,9 +257,11 @@ int ramdisk_load(int argc, char *argv[])
 
 	close(rfd);
 
+#ifdef CONFIG_KLIBC_ZLIB
 	if (is_gzip)
 		err = load_ramdisk_compressed("/dev/rddev", wfd, ramdisk_start);
 	else
+#endif
 		err = load_ramdisk_raw("/dev/rddev", wfd,
 				       ramdisk_start, fssize);
 
-- 
2.13.3



More information about the klibc mailing list