Skip to content

Commit 36cc7d6

Browse files
committed
libselinux: Fix cross-compilation
Apply patches for 3.6 to fix detection of available functions when cross-compiling. Use the PKG_CONFIG_LIBDIR to point pkg-config to the correct directory containing Conan's generated pkg-config files. Without this, the pcre2 from the system will be picked up before the one provided by Conan. When cross-compiling, this causes system include directories to poison the build.
1 parent 1c888e8 commit 36cc7d6

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed

recipes/libselinux/all/conandata.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ patches:
4040
base_path: libselinux-3.6
4141
patch_description: "Fix a missing #include <stdint.h>"
4242
patch_type: "portability"
43+
- patch_file: patches/0004-libsepol-src-Makefile-fix-reallocarray-detection.patch
44+
patch_description: "libsepol/src/Makefile: fix reallocarray detection"
45+
patch_source: "https://lore.kernel.org/selinux/[email protected]/"
46+
patch_type: "portability"
47+
base_path: libsepol-3.6
48+
- patch_file: patches/0005-libselinux-libsepol-Add-CFLAGS-and-LDFLAGS.patch
49+
patch_description: "libselinux, libsepol: Add CFLAGS and LDFLAGS to Makefile checks"
50+
patch_source: "https://lore.kernel.org/selinux/[email protected]/T/#u"
51+
patch_type: "portability"
4352
"3.0":
4453
- patch_file: patches/0001-fix-fno-common-3.0.patch
4554
base_path: libsepol-3.0

recipes/libselinux/all/conanfile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def validate(self):
6262
def build_requirements(self):
6363
self.tool_requires("flex/2.6.4")
6464
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
65-
self.tool_requires("pkgconf/2.0.3")
65+
self.tool_requires("pkgconf/2.1.0")
6666

6767
def source(self):
6868
for download in self.conan_data["sources"][self.version]:
@@ -87,7 +87,9 @@ def generate(self):
8787
sepol_lib_folder = os.path.join(self._sepol_source_folder, "src")
8888
tc.extra_ldflags.append(f"-L{sepol_lib_folder}")
8989
tc.make_args.append("USE_PCRE2=y")
90-
tc.generate()
90+
env = tc.environment()
91+
env.append_path("PKG_CONFIG_LIBDIR", self.generators_folder)
92+
tc.generate(env=env)
9193

9294
def build(self):
9395
apply_conandata_patches(self)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From a520f972bce9ec267f4e76b729bc3b7c1bdf13e6 Mon Sep 17 00:00:00 2001
2+
From: Fabrice Fontaine <[email protected]>
3+
Date: Mon, 8 Jan 2024 22:03:14 +0100
4+
Subject: [PATCH 1/3] libsepol/src/Makefile: fix reallocarray detection
5+
6+
Pass LDFLAGS when checking for reallocarray to avoid the following
7+
static build failure with musl raised since version 3.4 and
8+
https://github.com/SELinuxProject/selinux/commit/f0a5f6e33084bd83d409bb7c932256139f471e71
9+
because -static is not passed when checking for reallocarray:
10+
11+
/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
12+
In file included from assertion.c:28:
13+
private.h:88:21: error: static declaration of 'reallocarray' follows non-static declaration
14+
88 | static inline void* reallocarray(void *ptr, size_t nmemb, size_t size) {
15+
| ^~~~~~~~~~~~
16+
In file included from ../include/sepol/policydb/mls_types.h:35,
17+
from ../include/sepol/policydb/context.h:23,
18+
from ../include/sepol/policydb/policydb.h:62,
19+
from assertion.c:24:
20+
/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)'}
21+
150 | void *reallocarray (void *, size_t, size_t);
22+
| ^~~~~~~~~~~~
23+
24+
Fixes:
25+
- http://autobuild.buildroot.org/results/0170032548a38e2c991d62dc5823808458ad03b3
26+
27+
Signed-off-by: Fabrice Fontaine <[email protected]>
28+
Acked-by: James Carter <[email protected]>
29+
---
30+
src/Makefile | 2 +-
31+
1 file changed, 1 insertion(+), 1 deletion(-)
32+
33+
diff --git a/src/Makefile b/src/Makefile
34+
index d80a941f..16b9bd5e 100644
35+
--- a/src/Makefile
36+
+++ b/src/Makefile
37+
@@ -31,7 +31,7 @@ endif
38+
39+
# check for reallocarray(3) availability
40+
H := \#
41+
-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))
42+
+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))
43+
override CFLAGS += -DHAVE_REALLOCARRAY
44+
endif
45+
46+
--
47+
2.44.0
48+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[PATCH] libselinux, libsepol: Add CFLAGS and LDFLAGS to Makefile checks
2+
@ 2024-03-13 22:48 James Carter
3+
0 siblings, 0 replies; only message in thread
4+
From: James Carter @ 2024-03-13 22:48 UTC (permalink / raw)
5+
To: selinux; +Cc: jordan, winfried_mb2, James Carter
6+
7+
In libselinux there is an availability check for strlcpy() and
8+
in both libselinux and libsepol there are availability checks for
9+
reallocarray() in the src Makfiles. CFLAGS and LDFLAGS are needed
10+
for cross-compiling, but, unfortunately, the default CFLAGS cause
11+
all of these availability checks to fail to compile because of
12+
compilationerrors (rather than just the function not being available).
13+
14+
Add CFLAGS and LDFLAGS to the availibility checks, update the checks
15+
so that a compilation error will only happen if the function being
16+
checked for is not available, and make checks for the same function
17+
the same in both libselinux and libsepol.
18+
19+
Suggested-by: Jordan Williams <[email protected]>
20+
Suggested-by: Winfried Dobbe <[email protected]>
21+
Signed-off-by: James Carter <[email protected]>
22+
---
23+
libselinux/src/Makefile | 4 ++--
24+
libsepol/src/Makefile | 2 +-
25+
2 files changed, 3 insertions(+), 3 deletions(-)
26+
27+
diff --git a/libselinux-3.6/src/Makefile b/libselinux-3.6/src/Makefile
28+
index d3b981fc..41cfbdca 100644
29+
--- a/libselinux-3.6/src/Makefile
30+
+++ b/libselinux-3.6/src/Makefile
31+
@@ -104,13 +104,13 @@ override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
32+
33+
# check for strlcpy(3) availability
34+
H := \#
35+
-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))
36+
+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))
37+
override CFLAGS += -DHAVE_STRLCPY
38+
endif
39+
40+
# check for reallocarray(3) availability
41+
H := \#
42+
-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))
43+
+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))
44+
override CFLAGS += -DHAVE_REALLOCARRAY
45+
endif
46+
47+
diff --git a/libsepol-3.6/src/Makefile b/libsepol-3.6/src/Makefile
48+
index 16b9bd5e..7b0e8446 100644
49+
--- a/libsepol-3.6/src/Makefile
50+
+++ b/libsepol-3.6/src/Makefile
51+
@@ -31,7 +31,7 @@ endif
52+
53+
# check for reallocarray(3) availability
54+
H := \#
55+
-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))
56+
+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))
57+
override CFLAGS += -DHAVE_REALLOCARRAY
58+
endif
59+
60+
--
61+
2.44.0

0 commit comments

Comments
 (0)