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

Sam Ravnborg sam at ravnborg.org
Tue Jan 22 11:28:24 PST 2019


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
> +	{
> +#endif

This 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


More information about the klibc mailing list