Christophe Leroy
2019-Jan-22 16:42 UTC
[klibc] [PATCH] fix build failure when CONFIG_KLIBC_ZLIB is not set
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
Sam Ravnborg
2019-Jan-22 19:28 UTC
[klibc] [PATCH] fix build failure when CONFIG_KLIBC_ZLIB is not set
Hi Christophe. Thanks for the patch. On Tue, Jan 22, 2019 at 04:42:47PM +0000, Christophe Leroy wrote:> 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 > + { > +#endifThis is a confusing way to implement conditional compilation. Please try something else that is simpler. MAbe move the relevant code parts to a small helper function, and then based on the configuration select one or the other helper function. This makes the main code body much easier to follow. Same comment for the next file you patched. If it is hard to follow the diff (I could not do so in this case), then you probarly have to do it in a different way. If you go for moving to a helper function that could be the first patch, and the second introduced conditional compilation. I hope this make sense and is useful for you. Sam
Possibly Parallel Threads
- [PATCH v2] fix build failure when CONFIG_KLIBC_ZLIB is not set
- [klibc:master] fix build failure when CONFIG_KLIBC_ZLIB is not set
- [PATCH] Kbuild for klibc and nfsmount: add -fcommon
- [PATCH] Kbuild for klibc and nfsmount: fix multiple definitions
- [klibc:master] Clean up clang warnings