diff mbox series

libselinux/src/Makefile: fix reallocarray strlcpy detection

Message ID d5120a64-04f3-444d-aaf8-3cfc6c1d9953@jwillikers.com (mailing list archive)
State New
Delegated to: Petr Lautrbach
Headers show
Series libselinux/src/Makefile: fix reallocarray strlcpy detection | expand

Commit Message

Jordan Williams March 1, 2024, 4:32 p.m. UTC
Pass CFLAGS and LDFLAGS when checking for realocarray and strlcpy.
This brings things inline with the fixes for libsepol/src/Makefile.
This better supports cross-compiling scenarios.
There, flags like -sysroot need to included when running these checks.

Signed-off-by: Jordan Williams <jordan@jwillikers.com>

  H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint 
main(void){reallocarray(NULL, 0, 0);return 0;}' | $(CC) -x c -o 
/dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint 
main(void){reallocarray(NULL, 0, 0);return 0;}' | $(CC) $(CFLAGS) 
$(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
  override CFLAGS += -DHAVE_REALLOCARRAY
  endif

Comments

James Carter March 13, 2024, 10:52 p.m. UTC | #1
On Fri, Mar 1, 2024 at 12:03 PM Jordan Williams <jordan@jwillikers.com> wrote:
>
> Pass CFLAGS and LDFLAGS when checking for realocarray and strlcpy.
> This brings things inline with the fixes for libsepol/src/Makefile.
> This better supports cross-compiling scenarios.
> There, flags like -sysroot need to included when running these checks.
>
> Signed-off-by: Jordan Williams <jordan@jwillikers.com>
>
> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> index d3b981fc..3a9b5300 100644
> --- a/libselinux/src/Makefile
> +++ b/libselinux/src/Makefile
> @@ -104,13 +104,13 @@ override CFLAGS += -I../include -D_GNU_SOURCE
> $(DISABLE_FLAGS) $(PCRE_CFLAGS)
>
>   # check for strlcpy(3) availability
>   H := \#
> -ifeq (yes,$(shell printf '${H}include <string.h>\nint
> main(void){char*d,*s;strlcpy(d, s, 0);return 0;}' | $(CC) -x c -o
> /dev/null - >/dev/null 2>&1 && echo yes))
> +ifeq (yes,$(shell printf '${H}include <string.h>\nint
> main(void){char*d,*s;strlcpy(d, s, 0);return 0;}' | $(CC) $(CFLAGS)
> $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
>   override CFLAGS += -DHAVE_STRLCPY
>   endif
>
>   # check for reallocarray(3) availability
>   H := \#
> -ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint
> main(void){reallocarray(NULL, 0, 0);return 0;}' | $(CC) -x c -o
> /dev/null - >/dev/null 2>&1 && echo yes))
> +ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint
> main(void){reallocarray(NULL, 0, 0);return 0;}' | $(CC) $(CFLAGS)
> $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
>   override CFLAGS += -DHAVE_REALLOCARRAY
>   endif
>

The default CFLAGS causes the compilation to fail even if strlcpy() or
reallocarray() exist.
See if the patch I sent to the list works for you.
Thanks,
Jim


> --
> 2.44.0
>
>
diff mbox series

Patch

diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index d3b981fc..3a9b5300 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -104,13 +104,13 @@  override CFLAGS += -I../include -D_GNU_SOURCE 
$(DISABLE_FLAGS) $(PCRE_CFLAGS)

  # check for strlcpy(3) availability
  H := \#
-ifeq (yes,$(shell printf '${H}include <string.h>\nint 
main(void){char*d,*s;strlcpy(d, s, 0);return 0;}' | $(CC) -x c -o 
/dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <string.h>\nint 
main(void){char*d,*s;strlcpy(d, s, 0);return 0;}' | $(CC) $(CFLAGS) 
$(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
  override CFLAGS += -DHAVE_STRLCPY
  endif

  # check for reallocarray(3) availability