SELinux Archive mirror
 help / color / mirror / Atom feed
From: James Carter <jwcart2@gmail.com>
To: selinux@vger.kernel.org
Cc: jordan@jwillikers.com, winfried_mb2@xmsnet.nl
Subject: Re: [PATCH] libselinux, libsepol: Add CFLAGS and LDFLAGS to Makefile checks
Date: Wed, 20 Mar 2024 16:07:14 -0400	[thread overview]
Message-ID: <CAP+JOzRtHQbB0G_95ODmz3c1U5ZxmQaoA6jnNpFHMCaWRgCwwg@mail.gmail.com> (raw)
In-Reply-To: <20240313224806.2859045-1-jwcart2@gmail.com>

On Wed, Mar 13, 2024 at 6:48 PM James Carter <jwcart2@gmail.com> wrote:
>
> In libselinux there is an availability check for strlcpy() and
> in both libselinux and libsepol there are availability checks for
> reallocarray() in the src Makfiles. CFLAGS and LDFLAGS are needed
> for cross-compiling, but, unfortunately, the default CFLAGS cause
> all of these availability checks to fail to compile because of
> compilationerrors (rather than just the function not being available).
>
> Add CFLAGS and LDFLAGS to the availibility checks, update the checks
> so that a compilation error will only happen if the function being
> checked for is not available, and make checks for the same function
> the same in both libselinux and libsepol.
>
> Suggested-by: Jordan Williams <jordan@jwillikers.com>
> Suggested-by: Winfried Dobbe <winfried_mb2@xmsnet.nl>
> Signed-off-by: James Carter <jwcart2@gmail.com>

This patch has been merged.
Jim

> ---
>  libselinux/src/Makefile | 4 ++--
>  libsepol/src/Makefile   | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> index d3b981fc..41cfbdca 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[2];const char *s="a";return (size_t)strlcpy(d,s,sizeof(d))>=sizeof(d);}' | $(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){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
>  override CFLAGS += -DHAVE_REALLOCARRAY
>  endif
>
> diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
> index 16b9bd5e..7b0e8446 100644
> --- a/libsepol/src/Makefile
> +++ b/libsepol/src/Makefile
> @@ -31,7 +31,7 @@ endif
>
>  # check for reallocarray(3) availability
>  H := \#
> -ifeq (yes,$(shell printf '${H}define _GNU_SOURCE\n${H}include <stdlib.h>\nint main(void){void*p=reallocarray(NULL, 1, sizeof(char));return 0;}' | $(CC) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
> +ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
>  override CFLAGS += -DHAVE_REALLOCARRAY
>  endif
>
> --
> 2.44.0
>

      parent reply	other threads:[~2024-03-20 20:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 22:48 [PATCH] libselinux, libsepol: Add CFLAGS and LDFLAGS to Makefile checks James Carter
2024-03-14 13:59 ` Jordan Williams
2024-03-14 15:11   ` Winfried
2024-03-20 20:07 ` James Carter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAP+JOzRtHQbB0G_95ODmz3c1U5ZxmQaoA6jnNpFHMCaWRgCwwg@mail.gmail.com \
    --to=jwcart2@gmail.com \
    --cc=jordan@jwillikers.com \
    --cc=selinux@vger.kernel.org \
    --cc=winfried_mb2@xmsnet.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).