mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-19 05:38:00 +00:00
efdd65cb87
Overriding variables used in both the macros and the headers like setting REPLACE_FCNTL to 0 while invoking Make causes the function aliases like rpl_fcntl() to not be defined, however the object may still be built with the fnctl() function. Usually this is enough for building while avoiding the need to link the resulting libgnu library to every single other build target for a project in order to include the gnulib copy of the function, because in these cases we don't care which version of the function is used. However for functions like fcntl() this doesn't work as it is designed to use either the alias or standard declaration from gnulib headers in order to be a wrapper for the native host copy of fcntl() by containing recursive calls to fcntl() within itself after undefining the gnulib function declaration. Overriding the variables used by the header when invoking Make causes the header's declarations to be blocked, and this results in the gnulib version of fcntl() to call itself recursively and indefinitely leading to segmentation faults. Fix this by using macros defined with those variables in order to exclude the function during preprocessing. While at it, do the same for reallocarray() so that the configure option --avoid=reallocarray and Make variable REPLACE_REALLOCARRAY set to 0 would have a similar effect. In the future this patch can be expanded to include more functions and some version of this may be upstreamable. Signed-off-by: Michael Pratt <mcpratt@pm.me> Link: https://github.com/openwrt/openwrt/pull/15690 Signed-off-by: Robert Marko <robimarko@gmail.com>
57 lines
1.7 KiB
Diff
57 lines
1.7 KiB
Diff
--- a/lib/fcntl.c
|
|
+++ b/lib/fcntl.c
|
|
@@ -198,6 +198,8 @@ static int klibc_fcntl (int fd, int acti
|
|
FD_CLOEXEC is portable, but other flags may be present); otherwise
|
|
return -1 and set errno. */
|
|
|
|
+#if (GNULIB_defined_fcntl || GNULIB_defined_rpl_fcntl)
|
|
+
|
|
int
|
|
fcntl (int fd, int action, /* arg */...)
|
|
#undef fcntl
|
|
@@ -443,6 +445,8 @@ fcntl (int fd, int action, /* arg */...)
|
|
return result;
|
|
}
|
|
|
|
+#endif /* (GNULIB_defined_fcntl || GNULIB_defined_rpl_fcntl) */
|
|
+
|
|
static int
|
|
rpl_fcntl_DUPFD (int fd, int target)
|
|
{
|
|
--- a/lib/stdlib.in.h
|
|
+++ b/lib/stdlib.in.h
|
|
@@ -1447,10 +1447,16 @@ _GL_FUNCDECL_RPL (reallocarray, void *,
|
|
(void *ptr, size_t nmemb, size_t size));
|
|
_GL_CXXALIAS_RPL (reallocarray, void *,
|
|
(void *ptr, size_t nmemb, size_t size));
|
|
+# if !GNULIB_defined_rpl_reallocarray
|
|
+# define GNULIB_defined_rpl_reallocarray 1
|
|
+# endif
|
|
# else
|
|
# if ! @HAVE_REALLOCARRAY@
|
|
_GL_FUNCDECL_SYS (reallocarray, void *,
|
|
(void *ptr, size_t nmemb, size_t size));
|
|
+# if !GNULIB_defined_reallocarray
|
|
+# define GNULIB_defined_reallocarray 1
|
|
+# endif
|
|
# endif
|
|
_GL_CXXALIAS_SYS (reallocarray, void *,
|
|
(void *ptr, size_t nmemb, size_t size));
|
|
--- a/lib/reallocarray.c
|
|
+++ b/lib/reallocarray.c
|
|
@@ -23,6 +23,8 @@
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
|
|
+#if (GNULIB_defined_reallocarray || GNULIB_defined_rpl_reallocarray)
|
|
+
|
|
void *
|
|
reallocarray (void *ptr, size_t nmemb, size_t size)
|
|
{
|
|
@@ -36,3 +38,5 @@ reallocarray (void *ptr, size_t nmemb, s
|
|
/* Rely on the semantics of GNU realloc. */
|
|
return realloc (ptr, nbytes);
|
|
}
|
|
+
|
|
+#endif /* (GNULIB_defined_reallocarray || GNULIB_defined_rpl_reallocarray) */
|