diff mbox series

[meta-mingw] libxcrypt: fix build error for nativesdk

Message ID 20250328084300.2001238-1-yi.zhao@windriver.com
State New
Headers show
Series [meta-mingw] libxcrypt: fix build error for nativesdk | expand

Commit Message

Yi Zhao March 28, 2025, 8:43 a.m. UTC
From: Wenlin Kang <wenlin.kang@windriver.com>

Steps to reproduce
  1) add line in local.conf
     SDKMACHINE = "x86_64-mingw32"
  2) bitbake nativesdk-libxcrypt

Fix:
1. pedantic error
  | ../git/lib/crypt.c:316:24: error: ISO C does not allow extra ';' outside of a function [-Werror=pedantic]
  |   316 | SYMVER_crypt_gensalt_rn;
  |       |

2. conversion error
  | ../git/lib/util-get-random-bytes.c: In function '_crypt_get_random_bytes':
  | ../git/lib/util-get-random-bytes.c:140:42: error: conversion from 'size_t' {aka 'long long unsigned int'} to 'unsigned int' may change value [-Werror=conversion]
  |   140 |           ssize_t nread = read (fd, buf, buflen);

Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>
Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
---
 ...dom-bytes.c-fixed-conversion-error-w.patch | 47 +++++++++++++++++++
 recipes-core/libxcrypt/libxcrypt_%.bbappend   |  7 +++
 2 files changed, 54 insertions(+)
 create mode 100644 recipes-core/libxcrypt/libxcrypt/0001-lib-util-get-random-bytes.c-fixed-conversion-error-w.patch
 create mode 100644 recipes-core/libxcrypt/libxcrypt_%.bbappend
diff mbox series

Patch

diff --git a/recipes-core/libxcrypt/libxcrypt/0001-lib-util-get-random-bytes.c-fixed-conversion-error-w.patch b/recipes-core/libxcrypt/libxcrypt/0001-lib-util-get-random-bytes.c-fixed-conversion-error-w.patch
new file mode 100644
index 0000000..6320494
--- /dev/null
+++ b/recipes-core/libxcrypt/libxcrypt/0001-lib-util-get-random-bytes.c-fixed-conversion-error-w.patch
@@ -0,0 +1,47 @@ 
+From 7c45edc1e55295fc5f45cf8ff9e782febfa7fd84 Mon Sep 17 00:00:00 2001
+From: Wenlin Kang <wenlin.kang@windriver.com>
+Date: Mon, 6 Nov 2023 14:43:28 +0800
+Subject: [PATCH] lib/util-get-random-bytes.c: fixed conversion error with
+ mingw
+
+With x86_64-w64-mingw32-gcc. get below error:
+| ../git/lib/util-get-random-bytes.c: In function '_crypt_get_random_bytes':
+| ../git/lib/util-get-random-bytes.c:140:42: error: conversion from 'size_t' {aka 'long long unsigned int'} to 'unsigned int' may change value [-Werror=conversion]
+|   140 |           ssize_t nread = read (fd, buf, buflen);
+|       |                                          ^~~~~~
+
+In util-get-random-bytes.c, has get_random_bytes(void *buf, size_t buflen),
+but in mingw-w64-mingw-w64/mingw-w64-headers/crt/io.h, read() has "unsigned int"
+read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount), and has:
+ #ifdef _WIN64
+   __MINGW_EXTENSION typedef unsigned __int64 size_t;
+ #else
+   typedef unsigned int size_t;
+ #endif /* _WIN64 */
+
+Upstream-Status: Pending
+
+Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>
+---
+ lib/util-get-random-bytes.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/lib/util-get-random-bytes.c b/lib/util-get-random-bytes.c
+index 79816db..68cd378 100644
+--- a/lib/util-get-random-bytes.c
++++ b/lib/util-get-random-bytes.c
+@@ -137,7 +137,11 @@ get_random_bytes(void *buf, size_t buflen)
+         dev_urandom_doesnt_work = true;
+       else
+         {
++#ifdef _WIN64
++          ssize_t nread = read (fd, buf, (unsigned int)buflen);
++#else
+           ssize_t nread = read (fd, buf, buflen);
++#endif
+           if (nread < 0 || (size_t)nread < buflen)
+             dev_urandom_doesnt_work = true;
+ 
+-- 
+2.34.1
+
diff --git a/recipes-core/libxcrypt/libxcrypt_%.bbappend b/recipes-core/libxcrypt/libxcrypt_%.bbappend
new file mode 100644
index 0000000..97bf008
--- /dev/null
+++ b/recipes-core/libxcrypt/libxcrypt_%.bbappend
@@ -0,0 +1,7 @@ 
+FILESEXTRAPATHS:prepend:mingw32 := "${THISDIR}/${BPN}:"
+
+SRC_URI:append:mingw32 = " \
+                          file://0001-lib-util-get-random-bytes.c-fixed-conversion-error-w.patch \
+                         "
+
+CFLAGS:append:class-nativesdk:mingw32 = " -Wno-pedantic"