Skip to contentSkip to conversation

package/libcap: add upstream patches to bring support to disable thread

PATCH New Heiko Thiery 1 participant 2 messages Nov 2, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 package/libcap: add upstream patches to bring support to disable thread

The latest release is not able to build on environments w/o thread support. This commit adds support for that.

- add PTHREADS to package make flags
- change DYNAMIC with SHARED parameter of package make flags
- add several mainline patches to get support for disabling threads
- modify patch from Thomas to meet current shape of makefile
- drop patch from Thomas Petazzoni and replace with upstream one that introduces supports for SHARED option

Fixes:
http://autobuild.buildroot.net/results/fc1e7573327c7412dfa45b45a96966d993c7fc86/

Cc Thomas Petazzoni <[email protected]>
CC Fabrice Fontaine <[email protected]>
---
 ...ed-library-build-and-linkage-of-lpsx.patch | 257 +++++++++++++++++
 ...disable-building-installing-shared-l.patch |  38 ---
 ...sts-sudotest-for-DYNAMIC-yes-testing.patch | 127 +++++++++
 ...libpsx-is-important-for-multithreade.patch | 236 +++++++++++++++
 ...s-with-no-available-pthreads-support.patch | 269 ++++++++++++++++++
 ...tions-can-t-support-shared-libraries.patch | 123 ++++++++
 package/libcap/libcap.mk                      |   3 +-
 7 files changed, 1014 insertions(+), 39 deletions(-)
 create mode 100644 package/libcap/0001-Support-shared-library-build-and-linkage-of-lpsx.patch
 delete mode 100644 package/libcap/0001-libcap-Makefile-disable-building-installing-shared-l.patch
 create mode 100644 package/libcap/0002-Fix-tests-sudotest-for-DYNAMIC-yes-testing.patch
 create mode 100644 package/libcap/0003-Demonstrate-why-libpsx-is-important-for-multithreade.patch
 create mode 100644 package/libcap/0004-Support-systems-with-no-available-pthreads-support.patch
 create mode 100644 package/libcap/0005-Some-distributions-can-t-support-shared-libraries.patch
package/libcap/0001-Support-shared-library-build-and-linkage-of-lpsx.patch new file +257 -0
new file mode 100644
index 0000000000..72feea5b89
@@ -0,0 +1,257 @@
+From dd1c6c943a5b0de390eeb53bf4034ddfd587ab74 Mon Sep 17 00:00:00 2001
+From: "Andrew G. Morgan" <[email protected]>
+Date: Tue, 13 Oct 2020 06:21:55 -0700
+Subject: [PATCH] Support shared library build and linkage of -lpsx
+
+For now, the dynamic linkage of libpsx.so* is considered alpha.
+The build tree supports it and can successfully run tests but
+I'm hopeful I can get some feedback from third parties that it
+works as expected.
+
+Feature request:
+  https://bugzilla.kernel.org/show_bug.cgi?id=206093
+
+Signed-off-by: Andrew G. Morgan <[email protected]>
+[Taken from upstream]
+Signed-off-by: Heiko Thiery <[email protected]>
+---
+ Make.Rules                    |  3 +-
+ libcap/.gitignore             |  1 +
+ libcap/Makefile               | 53 +++++++++++++++++++++++------------
+ psx/include/sys/psx_syscall.h |  8 ------
+ tests/Makefile                | 30 +++++++++++---------
+ 5 files changed, 54 insertions(+), 41 deletions(-)
+
+diff --git a/Make.Rules b/Make.Rules
+index 5366f2d..6a571c6 100644
+--- a/Make.Rules
++++ b/Make.Rules
+@@ -71,7 +71,8 @@ WARNINGS=-Wall -Wwrite-strings \
+ LD=$(CC) -Wl,-x -shared
+ LDFLAGS ?= #-g
+ LIBCAPLIB := -L$(topdir)/libcap -lcap
+-LIBPSXLIB := -L$(topdir)/libcap -lpsx -lpthread -Wl,-wrap,pthread_create
++PSXLINKFLAGS :=  -lpthread -Wl,-wrap,pthread_create
++LIBPSXLIB := -L$(topdir)/libcap -lpsx $(PSXLINKFLAGS)
+ 
+ BUILD_GPERF := $(shell which gperf >/dev/null 2>/dev/null && echo yes)
+ 
+diff --git a/libcap/.gitignore b/libcap/.gitignore
+index 000c694..8f77a0e 100644
+--- a/libcap/.gitignore
++++ b/libcap/.gitignore
+@@ -4,6 +4,7 @@ _caps_output.gperf
+ libcap.a
+ libcap.so*
+ libpsx.a
++libpsx.so*
+ _makenames
+ cap_test
+ libcap.pc
+diff --git a/libcap/Makefile b/libcap/Makefile
+index de6a28d..51b0059 100644
+--- a/libcap/Makefile
++++ b/libcap/Makefile
+@@ -6,23 +6,27 @@ include ../Make.Rules
+ #
+ # Library version
+ #
+-LIBNAME=$(LIBTITLE).so
++CAPLIBNAME=$(LIBTITLE).so
+ STACAPLIBNAME=$(LIBTITLE).a
+ #
++PSXLIBNAME=libpsx.so
+ STAPSXLIBNAME=libpsx.a
+ 
+ CAPFILES=cap_alloc cap_proc cap_extint cap_flag cap_text cap_file
+ PSXFILES=../psx/psx
+ 
+ INCLS=libcap.h cap_names.h $(INCS)
++GPERF_OUTPUT = _caps_output.gperf
++
+ CAPOBJS=$(addsuffix .o, $(CAPFILES))
+-PSXOBJS=$(addsuffix .o, $(PSXFILES))
++MAJCAPLIBNAME=$(CAPLIBNAME).$(VERSION)
++MINCAPLIBNAME=$(MAJCAPLIBNAME).$(MINOR)
+ 
+-MAJLIBNAME=$(LIBNAME).$(VERSION)
+-MINLIBNAME=$(MAJLIBNAME).$(MINOR)
+-GPERF_OUTPUT = _caps_output.gperf
++PSXOBJS=$(addsuffix .o, $(PSXFILES))
++MAJPSXLIBNAME=$(PSXLIBNAME).$(VERSION)
++MINPSXLIBNAME=$(MAJPSXLIBNAME).$(MINOR)
+ 
+-all: $(MINLIBNAME) $(STACAPLIBNAME) pcs $(STAPSXLIBNAME)
++all: pcs $(MINCAPLIBNAME) $(STACAPLIBNAME) $(MINPSXLIBNAME) $(STAPSXLIBNAME)
+ 
+ pcs: libcap.pc libpsx.pc
+ 
+@@ -76,10 +80,15 @@ $(STAPSXLIBNAME): $(PSXOBJS)
+ 	$(AR) rcs $@ $^
+ 	$(RANLIB) $@
+ 
+-$(MINLIBNAME): $(CAPOBJS)
+-	$(LD) $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(MAJLIBNAME) -o $@ $^
+-	ln -sf $(MINLIBNAME) $(MAJLIBNAME)
+-	ln -sf $(MAJLIBNAME) $(LIBNAME)
++$(MINCAPLIBNAME): $(CAPOBJS)
++	$(LD) $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(MAJCAPLIBNAME) -o $@ $^
++	ln -sf $(MINCAPLIBNAME) $(MAJCAPLIBNAME)
++	ln -sf $(MAJCAPLIBNAME) $(CAPLIBNAME)
++
++$(MINPSXLIBNAME): $(PSXOBJS)
++	$(LD) $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(MAJPSXLIBNAME) -o $@ $^ $(PSXLINKFLAGS)
++	ln -sf $(MINPSXLIBNAME) $(MAJPSXLIBNAME)
++	ln -sf $(MAJPSXLIBNAME) $(PSXLIBNAME)
+ 
+ %.o: %.c $(INCLS)
+ 	$(CC) $(CFLAGS) $(IPATH) -c $< -o $@
+@@ -97,19 +106,19 @@ install: install-static install-shared
+ 
+ install-static: install-static-cap install-static-psx
+ 
+-install-shared: install-shared-cap
++install-shared: install-shared-cap install-shared-psx
+ 
+ install-cap: install-static-cap install-shared-cap
+ 
+-install-psx: install-static-psx
++install-psx: install-static-psx install-shared-psx
+ 
+ install-static-cap: install-common-cap $(STACAPLIBNAME)
+ 	install -m 0644 $(STACAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(STACAPLIBNAME)
+ 
+-install-shared-cap: install-common-cap $(MINLIBNAME)
+-	install -m 0644 $(MINLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MINLIBNAME)
+-	ln -sf $(MINLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MAJLIBNAME)
+-	ln -sf $(MAJLIBNAME) $(FAKEROOT)$(LIBDIR)/$(LIBNAME)
++install-shared-cap: install-common-cap $(MINCAPLIBNAME)
++	install -m 0644 $(MINCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MINCAPLIBNAME)
++	ln -sf $(MINCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MAJCAPLIBNAME)
++	ln -sf $(MAJCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(CAPLIBNAME)
+ ifeq ($(FAKEROOT),)
+ 	-/sbin/ldconfig
+ endif
+@@ -117,6 +126,14 @@ endif
+ install-static-psx: install-common-psx $(STAPSXLIBNAME)
+ 	install -m 0644 $(STAPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(STAPSXLIBNAME)
+ 
++install-shared-psx: install-common-psx $(MINPSXLIBNAME)
++	install -m 0644 $(MINPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MINPSXLIBNAME)
++	ln -sf $(MINPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MAJPSXLIBNAME)
++	ln -sf $(MAJPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(PSXLIBNAME)
++ifeq ($(FAKEROOT),)
++	-/sbin/ldconfig
++endif
++
+ install-common-cap: install-common libcap.pc
+ 	install -m 0644 include/sys/capability.h $(FAKEROOT)$(INCDIR)/sys
+ 	install -m 0644 libcap.pc $(FAKEROOT)$(PKGCONFIGDIR)/libcap.pc
+@@ -132,7 +149,7 @@ install-common:
+ 
+ clean:
+ 	$(LOCALCLEAN)
+-	rm -f $(CAPOBJS) $(LIBNAME)* $(STACAPLIBNAME) libcap.pc libpsx.pc
+-	rm -f $(PSXOBJS) $(STAPSXLIBNAME)
++	rm -f $(CAPOBJS) $(CAPLIBNAME)* $(STACAPLIBNAME) libcap.pc
++	rm -f $(PSXOBJS) $(PSXLIBNAME)* $(STAPSXLIBNAME) libpsx.pc
+ 	rm -f cap_names.h cap_names.list.h _makenames $(GPERF_OUTPUT) cap_test
+ 	cd include/sys && $(LOCALCLEAN)
+diff --git a/psx/include/sys/psx_syscall.h b/psx/include/sys/psx_syscall.h
+index 8044fbd..d1159e2 100644
+--- a/psx/include/sys/psx_syscall.h
++++ b/psx/include/sys/psx_syscall.h
+@@ -25,14 +25,6 @@ extern "C" {
+ 
+ #include <pthread.h>
+ 
+-/*
+- * This function is actually provided by the linker trick:
+- *
+- *   gcc ... -lpsx -lpthread -Wl,-wrap,pthread_create
+- */
+-int __real_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
+-			  void *(*start_routine) (void *), void *arg);
+-
+ /*
+  * psx_syscall performs the specified syscall on all psx registered
+  * threads. The mechanism by which this occurs is much less efficient
+diff --git a/tests/Makefile b/tests/Makefile
+index 8956d5d..476bc63 100644
+--- a/tests/Makefile
++++ b/tests/Makefile
+@@ -1,18 +1,20 @@
+ #
+-# defines
++# NOTE the built tests are all designed to be run from this
++# working directory when built DYNAMIC=yes. That is, they
++# link to the shared libraries in ../libcap/ .
+ #
+ topdir=$(shell pwd)/..
+ include ../Make.Rules
+ #
+ 
+-DEPS=../libcap/libcap.a ../libcap/libpsx.a
+-
+ ifeq ($(DYNAMIC),yes)
+-LDPATH = LD_LIBRARY_PATH=../libcap
+ DEPSBUILD = all
++DEPS=../libcap/libcap.so ../libcap/libpsx.so
++LINKEXTRA=-Wl,-rpath,../libcap
+ else
+ LDFLAGS += --static
+ DEPSBUILD = libcap.a libpsx.a
++DEPS=../libcap/libcap.a ../libcap/libpsx.a
+ endif
+ 
+ all: psx_test libcap_psx_test libcap_launch_test
+@@ -20,36 +22,36 @@ all: psx_test libcap_psx_test libcap_launch_test
+ $(DEPS):
+ 	make -C ../libcap $(DEPSBUILD)
+ 
+-test: run_psx_test run_libcap_psx_test
++test: run_libcap_psx_test
+ 
+-sudotest: test run_libcap_launch_test run_libcap_launch_test
++sudotest: test run_psx_test run_libcap_launch_test run_libcap_psx_test
+ 
+ install: all
+ 
+ run_psx_test: psx_test
+-	$(LDPATH) ./psx_test
++	sudo ./psx_test
+ 
+ psx_test: psx_test.c $(DEPS)
+-	$(CC) $(CFLAGS) $(IPATH) $< -o $@ $(LIBPSXLIB)
++	$(CC) $(CFLAGS) $(IPATH) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LDFLAGS)
+ 
+ run_libcap_psx_test: libcap_psx_test
+-	$(LDPATH) ./libcap_psx_test
++	./libcap_psx_test
+ 
+ libcap_psx_test: libcap_psx_test.c $(DEPS)
+-	$(CC) $(CFLAGS) $(IPATH) $< -o $@ $(LIBCAPLIB) $(LIBPSXLIB) $(LDFLAGS)
++	$(CC) $(CFLAGS) $(IPATH) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB) $(LDFLAGS)
+ 
+ run_libcap_launch_test: libcap_launch_test libcap_psx_launch_test noop
+-	sudo $(LDPATH) ./libcap_launch_test
+-	sudo $(LDPATH) ./libcap_psx_launch_test
++	sudo ./libcap_launch_test
++	sudo ./libcap_psx_launch_test
+ 
+ libcap_launch_test: libcap_launch_test.c $(DEPS)
+-	$(CC) $(CFLAGS) $(IPATH) $< -o $@ $(LIBCAPLIB) $(LDFLAGS)
++	$(CC) $(CFLAGS) $(IPATH) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LDFLAGS)
+ 
+ # this varies only slightly from the above insofar as it currently
+ # only links in the pthreads fork support. TODO() we need to change
+ # the source to do something interesting with pthreads.
+ libcap_psx_launch_test: libcap_launch_test.c $(DEPS)
+-	$(CC) $(CFLAGS) $(IPATH) -DWITH_PTHREADS $< -o $@ $(LIBCAPLIB) $(LIBPSXLIB) $(LDFLAGS)
++	$(CC) $(CFLAGS) $(IPATH) -DWITH_PTHREADS $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB) $(LDFLAGS)
+ 
+ # This one runs in a chroot with no shared library files.
+ noop: noop.c
+-- 
+2.20.1
+
package/libcap/0001-libcap-Makefile-disable-building-installing-shared-l.patch deleted +0 -38
deleted file mode 100644
index 6d49f235a9..0000000000
@@ -1,38 +0,0 @@
-From b7ca9dd97bbd9657c541f749ea6baf1f45b7c98a Mon Sep 17 00:00:00 2001
-From: Thomas Petazzoni <[email protected]>
-Date: Wed, 9 Sep 2020 22:22:18 +0200
-Subject: [PATCH] libcap/Makefile: disable building/installing shared
- library when DYNAMIC is empty
-
-Signed-off-by: Thomas Petazzoni <[email protected]>
-[slightly manual modifications that patch still applies for libcap 2.44]
-Signed-off-by: Heiko Thiery <[email protected]>
----
- libcap/Makefile | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/libcap/Makefile b/libcap/Makefile
-index 81b089e..dfd4dea 100644
---- a/libcap/Makefile
-+++ b/libcap/Makefile
-@@ -22,7 +22,7 @@ MAJLIBNAME=$(LIBNAME).$(VERSION)
- MINLIBNAME=$(MAJLIBNAME).$(MINOR)
- GPERF_OUTPUT = _caps_output.gperf
- 
--all: $(MINLIBNAME) $(STACAPLIBNAME) pcs $(STAPSXLIBNAME)
-+all: $(if $(DYNAMIC),$(MINLIBNAME)) $(STACAPLIBNAME) pcs $(STAPSXLIBNAME)
- 
- pcs: libcap.pc libpsx.pc
- 
-@@ -93,7 +93,7 @@ cap_test: cap_test.c libcap.h
- test: cap_test
- 	./cap_test
- 
--install: install-static install-shared
-+install: $(if $(DYNAMIC),install-shared) install-static
- 
- install-common: pcs
- 	mkdir -p -m 0755 $(FAKEROOT)$(INCDIR)/sys
--- 
-2.26.2
-
package/libcap/0002-Fix-tests-sudotest-for-DYNAMIC-yes-testing.patch new file +127 -0

127 lines not on this page · raw message

package/libcap/0003-Demonstrate-why-libpsx-is-important-for-multithreade.patch new file +236 -0

236 lines not on this page · raw message

package/libcap/0004-Support-systems-with-no-available-pthreads-support.patch new file +269 -0

269 lines not on this page · raw message

package/libcap/0005-Some-distributions-can-t-support-shared-libraries.patch new file +123 -0

123 lines not on this page · raw message

package/libcap/libcap.mk +2 -1
index e09bc1a624..52191d7c6c 100644
@@ -19,7 +19,8 @@ LIBCAP_MAKE_FLAGS = \
 	CROSS_COMPILE="$(TARGET_CROSS)" \
 	BUILD_CC="$(HOSTCC)" \
 	BUILD_CFLAGS="$(HOST_CFLAGS)" \
-	DYNAMIC=$(if $(BR2_STATIC_LIBS),,yes)
+	SHARED=$(if $(BR2_STATIC_LIBS),,yes) \
+	PTHREADS=$(if $(BR2_TOOLCHAIN_HAS_THREADS),yes,)
 
 LIBCAP_MAKE_DIRS = libcap
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/1 package/libcap: add upstream patches to bring support to disable thread

Hi all,

Am Mo., 2. Nov. 2020 um 13:34 Uhr schrieb Heiko Thiery <[email protected]>:

Quoted 11 lines

The latest release is not able to build on environments w/o thread support. This commit adds support for that.

- add PTHREADS to package make flags
- change DYNAMIC with SHARED parameter of package make flags
- add several mainline patches to get support for disabling threads
- modify patch from Thomas to meet current shape of makefile
- drop patch from Thomas Petazzoni and replace with upstream one that introduces supports for SHARED option

Quoted 7 lines

Fixes:
http://autobuild.buildroot.net/results/fc1e7573327c7412dfa45b45a96966d993c7fc86/

Cc Thomas Petazzoni <[email protected]>
CC Fabrice Fontaine <[email protected]>

---

I will drop this patch since libcap 2.45 will be released sometime this week. And work done in this patch is included in the release.

Thank you

--
Heiko