libsemanage: avoid "all" as requirement for SWIGSO/SWIGRUBYSO (bsc#1266385)
PATCH 1/1 libsemanage: avoid "all" as requirement for SWIGSO/SWIGRUBYSO (bsc#1266385)
Commit 49131e5 "libsemanage: Require LIBSO before SWIGSO and SWIGRUBYSO (bsc#1266385)" introduced a regression by requiring "all" in SWIGSO and SWIGRUBYSO. Listing "all" will cause the targets to rebuild every time because
of .PHONY = all.
Explicitly spell out the requirements depending if DISABLE_SHARED is "y" or not.
--- libsemanage/src/Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
libsemanage/src/Makefile +7 -2
@@ -70,6 +70,11 @@ SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ all: $(LIBA) $(LIBPC) ifneq ($(DISABLE_SHARED),y) all: $(LIBSO) +$(SWIGSO): $(LIBSO) +$(SWIGRUBYSO): $(LIBSO) +else +$(SWIGSO): $(LIBA) +$(SWIGRUBYSO): $(LIBA) endif pywrap: all $(SWIGSO)
@@ -82,10 +87,10 @@ $(SWIGLOBJ): $(SWIGCOUT) $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) $(CC) $(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $< -$(SWIGSO): $(SWIGLOBJ) all +$(SWIGSO): $(SWIGLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $< -lsemanage $(PYLIBS) -$(SWIGRUBYSO): $(SWIGRUBYLOBJ) all +$(SWIGRUBYSO): $(SWIGRUBYLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $< -lsemanage $(RUBYLIBS) $(LIBA): $(OBJS)
Signature · 1 line
2.54.0
Stephen Smalley
maintainerQuoted 8 lines · Cathy Hu
Commit 49131e5 "libsemanage: Require LIBSO before SWIGSO and SWIGRUBYSO (bsc#1266385)" introduced a regression by requiring "all" in SWIGSO and SWIGRUBYSO. Listing "all" will cause the targets to rebuild every time because
of .PHONY = all.Explicitly spell out the requirements depending if
DISABLE_SHAREDis "y" or not.
I guess I don't understand these patches - make DISABLE_SHARED=y python-M.N_semanage.so fails for me when it tries to link with libsemanage.a with or without this patch. Maybe we need to revert your previous patch.
Quoted 39 lines
Signed-off-by Cathy Hu <[email protected]>--- libsemanage/src/Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)libsemanage/src/Makefile +7
-3@@ -70,6 +70,11 @@ SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ all: $(LIBA) $(LIBPC) ifneq ($(DISABLE_SHARED),y) all: $(LIBSO) +$(SWIGSO): $(LIBSO) +$(SWIGRUBYSO): $(LIBSO) +else +$(SWIGSO): $(LIBA) +$(SWIGRUBYSO): $(LIBA) endif pywrap: all $(SWIGSO)@@ -82,10 +87,10 @@ $(SWIGLOBJ): $(SWIGCOUT) $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) $(CC) $(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $< -$(SWIGSO): $(SWIGLOBJ) all +$(SWIGSO): $(SWIGLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $< -lsemanage $(PYLIBS) -$(SWIGRUBYSO): $(SWIGRUBYLOBJ) all +$(SWIGRUBYSO): $(SWIGRUBYLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $< -lsemanage $(RUBYLIBS) $(LIBA): $(OBJS) --2.54.0
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Cathy Hu
Commit 49131e5 "libsemanage: Require LIBSO before SWIGSO and SWIGRUBYSO (bsc#1266385)" introduced a regression by requiring "all" in SWIGSO and SWIGRUBYSO. Listing "all" will cause the targets to rebuild every time because
of .PHONY = all.
Quoted 8 lines
Quoted 2 lines
Explicitly spell out the requirements depending if
DISABLE_SHAREDis "y" or not.I guess I don't understand these patches - make DISABLE_SHARED=y python-M.N_semanage.so fails for me when it tries to link with libsemanage.a with or without this patch. Maybe we need to revert your previous patch.
Sorry for the mess, I will try to explain the whole context in more detail...
tldr;
Reverting the previous patch will not fix the build problem as it has been there already
before my patches.
The problem there is that DISABLE_SHARED=y on its own is not compatible with python-M.N_semanage.so, as the static library is built without -fPIC, which is needed for all components of a shared library.
My patches are fixing a race condition unrelated to it.
long:
1. Problem that I am trying to solve with my patches:
So basically, libsemanage builds both a libsemanage.so and libsemanage.a and the shared object for python is linked with "-lsemanage". That prefers .so, but falls back to .a if it exists.
Due to a race condition when building with -j2 it happened on s390x that the .a was built, the python .so is linked against it. Then only after that, the libsemanage.so was built (so the python .so did not link against it!).
So the python .so was silently linked against .a and there was no built failure visible on s390x.
The concrete error can then be seen on the production system:
$ semanage port -a -t http_port_t -p tcp 81
Traceback (most recent call last):
File "/sbin/semanage", line 29, in <module>
import seobject
File "/usr/lib/python3.13/site-packages/seobject.py", line 31, in <module>
from semanage import *
File "/usr/lib64/python3.13/site-packages/semanage.py", line 12, in <module>
import _semanage
ImportError: /usr/lib64/python3.13/site-packages/_semanage.cpython-313-s390x-linux-gnu.so: undefined symbol: sepol_ibendport_modifyAnd when my colleague Fabian checked, the built .so lost the necessary DT_NEEDED, and also gained TEXTREL. This is really weird.
readelf -dW of the working .so:
Dynamic section at offset 0x4a090 contains 28 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libsemanage.so.2] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0xfa80 0x000000000000000d (FINI) 0x32a90 0x0000000000000019 (INIT_ARRAY) 0x4a080 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x4a088 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x0000000000000004 (HASH) 0x1f0 0x000000006ffffef5 (GNU_HASH) 0x1760 0x0000000000000005 (STRTAB) 0x3f00 0x0000000000000006 (SYMTAB) 0x1788 0x000000000000000a (STRSZ) 10147 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x4a290 0x0000000000000002 (PLTRELSZ) 9528 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0xd548 0x0000000000000007 (RELA) 0x6a80 0x0000000000000008 (RELASZ) 27336 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000000000001e (FLAGS) BIND_NOW 0x000000006ffffffb (FLAGS_1) Flags: NOW 0x000000006ffffffe (VERNEED) 0x69f0 0x000000006fffffff (VERNEEDNUM) 2 0x000000006ffffff0 (VERSYM) 0x66a4 0x000000006ffffff9 (RELACOUNT) 1105 0x0000000000000000 (NULL) 0x0
readelf -dW of the broken .so (the one that as linked against .a):
Dynamic section at offset 0x92d40 contains 28 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1b810 0x000000000000000d (FINI) 0x6a770 0x0000000000000019 (INIT_ARRAY) 0x924c0 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x924c8 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x0000000000000004 (HASH) 0x1f0 0x000000006ffffef5 (GNU_HASH) 0x3190 0x0000000000000005 (STRTAB) 0xa2d8 0x0000000000000006 (SYMTAB) 0x4500 0x000000000000000a (STRSZ) 21449 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x92f40 0x0000000000000002 (PLTRELSZ) 12192 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x18870 0x0000000000000007 (RELA) 0xff18 0x0000000000000008 (RELASZ) 35160 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x0000000000000016 (TEXTREL) 0x0 0x000000000000001e (FLAGS) TEXTREL BIND_NOW 0x000000006ffffffb (FLAGS_1) Flags: NOW 0x000000006ffffffe (VERNEED) 0xfe78 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0xf6a2 0x000000006ffffff9 (RELACOUNT) 1219 0x0000000000000000 (NULL) 0x0
IMO the python .so should not silently link against .a when the .so is supposed to be built in the same build. Therefor we need to specify in the target that the libsemanage.so is required by SWIGSO and SWIGRUBYSO, which I tried in 49131e5.
2. What I am doing in this patch:
In my previous patch (commit 49131e5) I added "all" as requirement, however that causes the target to rebuild every time due to "all" being listed in .PHONY, which is not pretty.
To stop it from rebuilding again, we drop "all" from previously and list the dependencies explicitly with this patch and do not depend on the "all" mechanism.
3. The linking problem is unrelated
The python .so links against .a when DISABLE_SHARED=y. This was already the implicit behaviour before any of my patches. So it already was broken.
You can verify that the problem was already there by reverting my patches and running it and seeing it fail as well
$ wget https://raw.githubusercontent.com/SELinuxProject/selinux/6fedd3fbaab440f0657a4d9621741291e7ca96da/libsemanage/src/Makefile -O Makefile (that is the Makefile without my patches) $ make clean $ make DISABLE_SHARED=y install-pywrap ... /usr/bin/ld.bfd: ./libsemanage.a(conf-scan.o): warning: relocation against `semanage_lineno' in read-only section `.text' /usr/bin/ld.bfd: ./libsemanage.a(debug.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld.bfd: final link failed: bad value collect2: error: ld returned 1 exit status make: *** [Makefile:86: python-3.13_semanage.so] Error 1
This is because .a is not built with -fPIC. Likely because the .o is not built with -fPIC:
https://github.com/SELinuxProject/selinux/blob/49131e50ba3a6c16ec5ae41d165dadb7183c05b4/libsemanage/src/Makefile#L114
Therefor it can not be linked, which was the case before my patches already.
Unfortunately, I do not use DISABLE_SHARED as feature and do not know what is intended behavior or not.
If that is something that should work, the user either needs to add -fPIC in the make command or .o needs to be built with -fPIC:
$ make DISABLE_SHARED=y CFLAGS=-fPIC python-3.13_semanage.so
But since -fPIC was added everywhere else in this commit, but not the .o, I assumed it was intended that it shall not be there:
https://github.com/SELinuxProject/selinux/commit/6fedd3fbaab440f0657a4d9621741291e7ca96da
Sidenote: I also not understand if it is even intended that the python .so shall be built in a static only system.
So I am trying to keep the behaviour as before for the parts I do not really understand while trying to fix my problem.
Hope that makes sense, sorry for the wall of text :)
Quoted 39 lines
Quoted 39 lines
Signed-off-by Cathy Hu <[email protected]>--- libsemanage/src/Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)libsemanage/src/Makefile +7
-3@@ -70,6 +70,11 @@ SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ all: $(LIBA) $(LIBPC) ifneq ($(DISABLE_SHARED),y) all: $(LIBSO) +$(SWIGSO): $(LIBSO) +$(SWIGRUBYSO): $(LIBSO) +else +$(SWIGSO): $(LIBA) +$(SWIGRUBYSO): $(LIBA) endif pywrap: all $(SWIGSO)@@ -82,10 +87,10 @@ $(SWIGLOBJ): $(SWIGCOUT) $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) $(CC) $(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $< -$(SWIGSO): $(SWIGLOBJ) all +$(SWIGSO): $(SWIGLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $< -lsemanage $(PYLIBS) -$(SWIGRUBYSO): $(SWIGRUBYLOBJ) all +$(SWIGRUBYSO): $(SWIGRUBYLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $< -lsemanage $(RUBYLIBS) $(LIBA): $(OBJS) --2.54.0
Stephen Smalley
maintainerQuoted 155 lines · Cathy Hu
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Cathy Hu
Commit 49131e5 "libsemanage: Require LIBSO before SWIGSO and SWIGRUBYSO (bsc#1266385)" introduced a regression by requiring "all" in SWIGSO and SWIGRUBYSO. Listing "all" will cause the targets to rebuild every time because
of .PHONY = all.Quoted 8 lines
Quoted 2 lines
Explicitly spell out the requirements depending if
DISABLE_SHAREDis "y" or not.I guess I don't understand these patches - make DISABLE_SHARED=y python-M.N_semanage.so fails for me when it tries to link with libsemanage.a with or without this patch. Maybe we need to revert your previous patch.
Sorry for the mess, I will try to explain the whole context in more detail...
tldr;
Reverting the previous patch will not fix the build problem as it has been there already
before my patches.
The problem there is that DISABLE_SHARED=y on its own is not compatible with python-M.N_semanage.so, as the static library is built without -fPIC, which is needed for all components of a shared library.My patches are fixing a race condition unrelated to it.
long:
1. Problem that I am trying to solve with my patches:So basically, libsemanage builds both a libsemanage.so and libsemanage.a and the shared object for python is linked with "-lsemanage". That prefers .so, but falls back to .a if it exists.
Due to a race condition when building with -j2 it happened on s390x that the .a was built, the python .so is linked against it. Then only after that, the libsemanage.so was built (so the python .so did not link against it!).
So the python .so was silently linked against .a and there was no built failure visible on s390x.The concrete error can then be seen on the production system:
$ semanage port -a -t http_port_t -p tcp 81 Traceback (most recent call last): File "/sbin/semanage", line 29, in <module> import seobject File "/usr/lib/python3.13/site-packages/seobject.py", line 31, in <module> from semanage import * File "/usr/lib64/python3.13/site-packages/semanage.py", line 12, in <module> import _semanage ImportError: /usr/lib64/python3.13/site-packages/_semanage.cpython-313-s390x-linux-gnu.so: undefined symbol: sepol_ibendport_modifyAnd when my colleague Fabian checked, the built .so lost the necessary
DT_NEEDED, and also gained TEXTREL. This is really weird.readelf -dW of the working .so:
Dynamic section at offset
0x4a090contains 28 entries:
Tag Type Name/Value0x0000000000000001 (NEEDED) Shared library: [libsemanage.so.2] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0xfa80 0x000000000000000d (FINI) 0x32a90 0x0000000000000019 (INIT_ARRAY) 0x4a080 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x4a088 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x0000000000000004 (HASH) 0x1f0 0x000000006ffffef5 (GNU_HASH) 0x1760 0x0000000000000005 (STRTAB) 0x3f00 0x0000000000000006 (SYMTAB) 0x1788 0x000000000000000a (STRSZ) 10147 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x4a290 0x0000000000000002 (PLTRELSZ) 9528 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0xd548 0x0000000000000007 (RELA) 0x6a80 0x0000000000000008 (RELASZ) 27336 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000000000001e (FLAGS) BIND_NOW 0x000000006ffffffb (FLAGS_1) Flags: NOW 0x000000006ffffffe (VERNEED) 0x69f0 0x000000006fffffff (VERNEEDNUM) 2 0x000000006ffffff0 (VERSYM) 0x66a4 0x000000006ffffff9 (RELACOUNT) 1105 0x0000000000000000 (NULL) 0x0readelf -dW of the broken .so (the one that as linked against .a):
Dynamic section at offset
0x92d40contains 28 entries:
Tag Type Name/Value0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1b810 0x000000000000000d (FINI) 0x6a770 0x0000000000000019 (INIT_ARRAY) 0x924c0 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x924c8 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x0000000000000004 (HASH) 0x1f0 0x000000006ffffef5 (GNU_HASH) 0x3190 0x0000000000000005 (STRTAB) 0xa2d8 0x0000000000000006 (SYMTAB) 0x4500 0x000000000000000a (STRSZ) 21449 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x92f40 0x0000000000000002 (PLTRELSZ) 12192 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x18870 0x0000000000000007 (RELA) 0xff18 0x0000000000000008 (RELASZ) 35160 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x0000000000000016 (TEXTREL) 0x0 0x000000000000001e (FLAGS) TEXTREL BIND_NOW 0x000000006ffffffb (FLAGS_1) Flags: NOW 0x000000006ffffffe (VERNEED) 0xfe78 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0xf6a2 0x000000006ffffff9 (RELACOUNT) 1219 0x0000000000000000 (NULL) 0x0IMO the python .so should not silently link against .a when the .so is supposed to be built in the same build. Therefor we need to specify in the target that the libsemanage.so is required by SWIGSO and SWIGRUBYSO, which I tried in 49131e5.
2. What I am doing in this patch:
In my previous patch (commit 49131e5) I added "all" as requirement, however that causes the target to rebuild every time due to "all" being listed in .PHONY, which is not pretty.
To stop it from rebuilding again, we drop "all" from previously and list the dependencies explicitly with this patch and do not depend on the "all" mechanism.3. The linking problem is unrelated
The python .so links against .a when DISABLE_SHARED=y. This was already the implicit behaviour before any of my patches. So it already was broken.
You can verify that the problem was already there by reverting my patches and running it and seeing it fail as well
$ wget https://raw.githubusercontent.com/SELinuxProject/selinux/6fedd3fbaab440f0657a4d9621741291e7ca96da/libsemanage/src/Makefile -O Makefile (that is the Makefile without my patches) $ make clean $ make DISABLE_SHARED=y install-pywrap ... /usr/bin/ld.bfd: ./libsemanage.a(conf-scan.o): warning: relocation against `semanage_lineno' in read-only section `.text' /usr/bin/ld.bfd: ./libsemanage.a(debug.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld.bfd: final link failed: bad value collect2: error: ld returned 1 exit status make: *** [Makefile:86: python-3.13_semanage.so] Error 1This is because .a is not built with -fPIC. Likely because the .o is not built with -fPIC:
https://github.com/SELinuxProject/selinux/blob/49131e50ba3a6c16ec5ae41d165dadb7183c05b4/libsemanage/src/Makefile#L114
Therefor it can not be linked, which was the case before my patches already.Unfortunately, I do not use
DISABLE_SHAREDas feature and do not know what is intended behavior or not.
If that is something that should work, the user either needs to add -fPIC in the make command or .o needs to be built with -fPIC:$ make DISABLE_SHARED=y CFLAGS=-fPIC python-3.13_semanage.so
Quoted 8 lines
But since -fPIC was added everywhere else in this commit, but not the .o, I assumed it was intended that it shall not be there:
https://github.com/SELinuxProject/selinux/commit/6fedd3fbaab440f0657a4d9621741291e7ca96daSidenote: I also not understand if it is even intended that the python .so shall be built in a static only system.
So I am trying to keep the behaviour as before for the parts I do not really understand while trying to fix my problem.
Hope that makes sense, sorry for the wall of text :)
Thanks for explaining. I think we should just not build any .so files if DISABLE_SHARED=y but I'll go ahead and merge this.
Stephen Smalley
maintainerQuoted 160 lines · Stephen Smalley
Quoted 158 lines · Cathy Hu
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Cathy Hu
Commit 49131e5 "libsemanage: Require LIBSO before SWIGSO and SWIGRUBYSO (bsc#1266385)" introduced a regression by requiring "all" in SWIGSO and SWIGRUBYSO. Listing "all" will cause the targets to rebuild every time because
of .PHONY = all.Quoted 8 lines
Quoted 2 lines
Explicitly spell out the requirements depending if
DISABLE_SHAREDis "y" or not.I guess I don't understand these patches - make DISABLE_SHARED=y python-M.N_semanage.so fails for me when it tries to link with libsemanage.a with or without this patch. Maybe we need to revert your previous patch.
Sorry for the mess, I will try to explain the whole context in more detail...
tldr;
Reverting the previous patch will not fix the build problem as it has been there already
before my patches.
The problem there is that DISABLE_SHARED=y on its own is not compatible with python-M.N_semanage.so, as the static library is built without -fPIC, which is needed for all components of a shared library.My patches are fixing a race condition unrelated to it.
long:
1. Problem that I am trying to solve with my patches:So basically, libsemanage builds both a libsemanage.so and libsemanage.a and the shared object for python is linked with "-lsemanage". That prefers .so, but falls back to .a if it exists.
Due to a race condition when building with -j2 it happened on s390x that the .a was built, the python .so is linked against it. Then only after that, the libsemanage.so was built (so the python .so did not link against it!).
So the python .so was silently linked against .a and there was no built failure visible on s390x.The concrete error can then be seen on the production system:
$ semanage port -a -t http_port_t -p tcp 81 Traceback (most recent call last): File "/sbin/semanage", line 29, in <module> import seobject File "/usr/lib/python3.13/site-packages/seobject.py", line 31, in <module> from semanage import * File "/usr/lib64/python3.13/site-packages/semanage.py", line 12, in <module> import _semanage ImportError: /usr/lib64/python3.13/site-packages/_semanage.cpython-313-s390x-linux-gnu.so: undefined symbol: sepol_ibendport_modifyAnd when my colleague Fabian checked, the built .so lost the necessary
DT_NEEDED, and also gained TEXTREL. This is really weird.readelf -dW of the working .so:
Dynamic section at offset
0x4a090contains 28 entries:
Tag Type Name/Value0x0000000000000001 (NEEDED) Shared library: [libsemanage.so.2] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0xfa80 0x000000000000000d (FINI) 0x32a90 0x0000000000000019 (INIT_ARRAY) 0x4a080 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x4a088 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x0000000000000004 (HASH) 0x1f0 0x000000006ffffef5 (GNU_HASH) 0x1760 0x0000000000000005 (STRTAB) 0x3f00 0x0000000000000006 (SYMTAB) 0x1788 0x000000000000000a (STRSZ) 10147 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x4a290 0x0000000000000002 (PLTRELSZ) 9528 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0xd548 0x0000000000000007 (RELA) 0x6a80 0x0000000000000008 (RELASZ) 27336 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000000000001e (FLAGS) BIND_NOW 0x000000006ffffffb (FLAGS_1) Flags: NOW 0x000000006ffffffe (VERNEED) 0x69f0 0x000000006fffffff (VERNEEDNUM) 2 0x000000006ffffff0 (VERSYM) 0x66a4 0x000000006ffffff9 (RELACOUNT) 1105 0x0000000000000000 (NULL) 0x0readelf -dW of the broken .so (the one that as linked against .a):
Dynamic section at offset
0x92d40contains 28 entries:
Tag Type Name/Value0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1b810 0x000000000000000d (FINI) 0x6a770 0x0000000000000019 (INIT_ARRAY) 0x924c0 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x924c8 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x0000000000000004 (HASH) 0x1f0 0x000000006ffffef5 (GNU_HASH) 0x3190 0x0000000000000005 (STRTAB) 0xa2d8 0x0000000000000006 (SYMTAB) 0x4500 0x000000000000000a (STRSZ) 21449 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x92f40 0x0000000000000002 (PLTRELSZ) 12192 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x18870 0x0000000000000007 (RELA) 0xff18 0x0000000000000008 (RELASZ) 35160 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x0000000000000016 (TEXTREL) 0x0 0x000000000000001e (FLAGS) TEXTREL BIND_NOW 0x000000006ffffffb (FLAGS_1) Flags: NOW 0x000000006ffffffe (VERNEED) 0xfe78 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0xf6a2 0x000000006ffffff9 (RELACOUNT) 1219 0x0000000000000000 (NULL) 0x0IMO the python .so should not silently link against .a when the .so is supposed to be built in the same build. Therefor we need to specify in the target that the libsemanage.so is required by SWIGSO and SWIGRUBYSO, which I tried in 49131e5.
2. What I am doing in this patch:
In my previous patch (commit 49131e5) I added "all" as requirement, however that causes the target to rebuild every time due to "all" being listed in .PHONY, which is not pretty.
To stop it from rebuilding again, we drop "all" from previously and list the dependencies explicitly with this patch and do not depend on the "all" mechanism.3. The linking problem is unrelated
The python .so links against .a when DISABLE_SHARED=y. This was already the implicit behaviour before any of my patches. So it already was broken.
You can verify that the problem was already there by reverting my patches and running it and seeing it fail as well
$ wget https://raw.githubusercontent.com/SELinuxProject/selinux/6fedd3fbaab440f0657a4d9621741291e7ca96da/libsemanage/src/Makefile -O Makefile (that is the Makefile without my patches) $ make clean $ make DISABLE_SHARED=y install-pywrap ... /usr/bin/ld.bfd: ./libsemanage.a(conf-scan.o): warning: relocation against `semanage_lineno' in read-only section `.text' /usr/bin/ld.bfd: ./libsemanage.a(debug.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld.bfd: final link failed: bad value collect2: error: ld returned 1 exit status make: *** [Makefile:86: python-3.13_semanage.so] Error 1This is because .a is not built with -fPIC. Likely because the .o is not built with -fPIC:
https://github.com/SELinuxProject/selinux/blob/49131e50ba3a6c16ec5ae41d165dadb7183c05b4/libsemanage/src/Makefile#L114
Therefor it can not be linked, which was the case before my patches already.Unfortunately, I do not use
DISABLE_SHAREDas feature and do not know what is intended behavior or not.
If that is something that should work, the user either needs to add -fPIC in the make command or .o needs to be built with -fPIC:$ make DISABLE_SHARED=y CFLAGS=-fPIC python-3.13_semanage.soBut since -fPIC was added everywhere else in this commit, but not the .o, I assumed it was intended that it shall not be there:
https://github.com/SELinuxProject/selinux/commit/6fedd3fbaab440f0657a4d9621741291e7ca96da
Quoted 8 lines
Quoted 5 lines
Sidenote: I also not understand if it is even intended that the python .so shall be built in a static only system.
So I am trying to keep the behaviour as before for the parts I do not really understand while trying to fix my problem.
Hope that makes sense, sorry for the wall of text :)
Thanks for explaining. I think we should just not build any .so files if DISABLE_SHARED=y but I'll go ahead and merge this.
This is merged.