Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libselinux: Fix cross-compilation #22952

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions recipes/libselinux/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ patches:
base_path: libselinux-3.6
patch_description: "Fix a missing #include <stdint.h>"
patch_type: "portability"
- patch_file: patches/0004-libsepol-src-Makefile-fix-reallocarray-detection.patch
patch_description: "libsepol/src/Makefile: fix reallocarray detection"
patch_source: "https://lore.kernel.org/selinux/[email protected]/"
patch_type: "portability"
base_path: libsepol-3.6
- patch_file: patches/0005-libselinux-libsepol-Add-CFLAGS-and-LDFLAGS.patch
patch_description: "libselinux, libsepol: Add CFLAGS and LDFLAGS to Makefile checks"
patch_source: "https://lore.kernel.org/selinux/[email protected]/T/#u"
patch_type: "portability"
"3.0":
- patch_file: patches/0001-fix-fno-common-3.0.patch
base_path: libsepol-3.0
Expand Down
6 changes: 4 additions & 2 deletions recipes/libselinux/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def validate(self):
def build_requirements(self):
self.tool_requires("flex/2.6.4")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/2.0.3")
self.tool_requires("pkgconf/2.1.0")

def source(self):
for download in self.conan_data["sources"][self.version]:
Expand All @@ -87,7 +87,9 @@ def generate(self):
sepol_lib_folder = os.path.join(self._sepol_source_folder, "src")
tc.extra_ldflags.append(f"-L{sepol_lib_folder}")
tc.make_args.append("USE_PCRE2=y")
tc.generate()
env = tc.environment()
env.append_path("PKG_CONFIG_LIBDIR", self.generators_folder)
tc.generate(env=env)
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved

def build(self):
apply_conandata_patches(self)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
From a520f972bce9ec267f4e76b729bc3b7c1bdf13e6 Mon Sep 17 00:00:00 2001
From: Fabrice Fontaine <[email protected]>
Date: Mon, 8 Jan 2024 22:03:14 +0100
Subject: [PATCH 1/3] libsepol/src/Makefile: fix reallocarray detection

Pass LDFLAGS when checking for reallocarray to avoid the following
static build failure with musl raised since version 3.4 and
https://github.com/SELinuxProject/selinux/commit/f0a5f6e33084bd83d409bb7c932256139f471e71
because -static is not passed when checking for reallocarray:

/home/autobuild/autobuild/instance-9/output-1/host/bin/armeb-buildroot-linux-musleabi-gcc -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O0 -g0 -static -I. -I../include -D_GNU_SOURCE -I../cil/include -fPIC -c -o assertion.o assertion.c
In file included from assertion.c:28:
private.h:88:21: error: static declaration of 'reallocarray' follows non-static declaration
88 | static inline void* reallocarray(void *ptr, size_t nmemb, size_t size) {
| ^~~~~~~~~~~~
In file included from ../include/sepol/policydb/mls_types.h:35,
from ../include/sepol/policydb/context.h:23,
from ../include/sepol/policydb/policydb.h:62,
from assertion.c:24:
/home/autobuild/autobuild/instance-9/output-1/host/armeb-buildroot-linux-musleabi/sysroot/usr/include/stdlib.h:150:7: note: previous declaration of 'reallocarray' with type 'void *(void *, size_t, size_t)' {aka 'void *(void *, unsigned int, unsigned int)'}
150 | void *reallocarray (void *, size_t, size_t);
| ^~~~~~~~~~~~

Fixes:
- http://autobuild.buildroot.org/results/0170032548a38e2c991d62dc5823808458ad03b3

Signed-off-by: Fabrice Fontaine <[email protected]>
Acked-by: James Carter <[email protected]>
---
src/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile b/src/Makefile
index d80a941f..16b9bd5e 100644
--- a/src/Makefile
+++ b/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) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+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))
override CFLAGS += -DHAVE_REALLOCARRAY
endif

--
2.44.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[PATCH] libselinux, libsepol: Add CFLAGS and LDFLAGS to Makefile checks
@ 2024-03-13 22:48 James Carter
0 siblings, 0 replies; only message in thread
From: James Carter @ 2024-03-13 22:48 UTC (permalink / raw)
To: selinux; +Cc: jordan, winfried_mb2, James Carter

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 <[email protected]>
Suggested-by: Winfried Dobbe <[email protected]>
Signed-off-by: James Carter <[email protected]>
---
libselinux/src/Makefile | 4 ++--
libsepol/src/Makefile | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libselinux-3.6/src/Makefile b/libselinux-3.6/src/Makefile
index d3b981fc..41cfbdca 100644
--- a/libselinux-3.6/src/Makefile
+++ b/libselinux-3.6/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-3.6/src/Makefile b/libsepol-3.6/src/Makefile
index 16b9bd5e..7b0e8446 100644
--- a/libsepol-3.6/src/Makefile
+++ b/libsepol-3.6/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