libselinux: add --undefined-version to LD_SONAME_FLAGS
Stephen Smalley
maintainerPATCH 1/1 libselinux: add --undefined-version to LD_SONAME_FLAGS
commit 9395cc03226a0 ("Always build for LFS mode on 32-bit archs.") introduced a matchpathcon_filespec_add64 symbol for certain 32-bit configurations but added it to libselinux.map. This was benign under GNU ld but breaks lld due to differing defaults for --no-undefined-version. Add --undefined-version to LD_SONAME_FLAGS to avoid breakage when building with lld.
Fix: #512
Fix: #513
--- libselinux/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/src/Makefile +1 -1
@@ -91,7 +91,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi override CFLAGS += $(LFS_CFLAGS) -LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=libselinux.map,-z,defs,-z,relro +LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=libselinux.map,-z,defs,-z,relro,--undefined-version ifeq ($(OS), Darwin) override CFLAGS += -I/opt/local/include
Signature · 1 line
2.54.0
Quoted 8 lines · Stephen Smalley
commit
9395cc03226a0("Always build for LFS mode on 32-bit archs.") introduced amatchpathcon_filespec_add64symbol for certain 32-bit configurations but added it to libselinux.map. This was benign under GNU ld but breaks lld due to differing defaults for --no-undefined-version. Add --undefined-version toLD_SONAME_FLAGSto avoid breakage when building with lld.
Quoted 5 lines
Fix: #512
Fix: #513Fixes 9395cc03226a0 ("Always build for LFS mode on 32-bit archs.")Reported-by Pepper Gray <[email protected]>Signed-off-by Stephen Smalley <[email protected]>
Personally I liked the fallback wrapper definition of matchpathcon_filespec_add64() more...
Quoted 21 lines
--- libselinux/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libselinux/src/Makefile +1
-2@@ -91,7 +91,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi override CFLAGS += $(LFS_CFLAGS) -LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=libselinux.map,-z,defs,-z,relro +LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=libselinux.map,-z,defs,-z,relro,--undefined-version ifeq ($(OS), Darwin) override CFLAGS += -I/opt/local/include --2.54.0
Stephen Smalley
maintainerQuoted 11 lines · Christian Göttsche
Quoted 8 lines · Stephen Smalley
commit
9395cc03226a0("Always build for LFS mode on 32-bit archs.") introduced amatchpathcon_filespec_add64symbol for certain 32-bit configurations but added it to libselinux.map. This was benign under GNU ld but breaks lld due to differing defaults for --no-undefined-version. Add --undefined-version toLD_SONAME_FLAGSto avoid breakage when building with lld.
Quoted 8 lines
Quoted 5 lines
Fix: #512
Fix: #513Fixes 9395cc03226a0 ("Always build for LFS mode on 32-bit archs.")Reported-by Pepper Gray <[email protected]>Signed-off-by Stephen Smalley <[email protected]>Personally I liked the fallback wrapper definition of
matchpathcon_filespec_add64()more...
I don't strongly care either way. See
https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674610134
and https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674659036
for the argument made against
adding the wrapper definition.
Quoted 19 lines · Stephen Smalley
Quoted 17 lines · Christian Göttsche
Quoted 13 lines · Stephen Smalley
commit
9395cc03226a0("Always build for LFS mode on 32-bit archs.") introduced amatchpathcon_filespec_add64symbol for certain 32-bit configurations but added it to libselinux.map. This was benign under GNU ld but breaks lld due to differing defaults for --no-undefined-version. Add --undefined-version toLD_SONAME_FLAGSto avoid breakage when building with lld.Fix: #512
Fix: #513Fixes 9395cc03226a0 ("Always build for LFS mode on 32-bit archs.")Reported-by Pepper Gray <[email protected]>Signed-off-by Stephen Smalley <[email protected]>
Quoted 8 lines
Quoted 2 lines
Personally I liked the fallback wrapper definition of
matchpathcon_filespec_add64()more...I don't strongly care either way. See
https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674610134
and https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674659036
for the argument made against
adding the wrapper definition.
Could we use libselinux.map.in and generate libselinux.map build time?
Add matchpathcon_filespec_add64@LIBSELINUX_3.8 symbol when bits are lower than 64, add matchpathcon_filespec_add@LIBSELINUX_3.8 when bits are 64
Something like the patch bellow. Would it be too complicated?
1. convert .map to map.in
$ sed 's/matchpathcon_filespec_add64/@matchpathcon_filespec_add64@/' libselinux/src/libselinux.map > libselinux/src/libselinux.map.in
2.
libselinux/Makefile +2 -0
@@ -39,6 +39,8 @@ ifeq ($(USE_LFS),y) LFS_CFLAGS := -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 endif export LFS_CFLAGS +LONG_BIT := $(shell getconf LONG_BIT) +export LONG_BIT OS := $(shell uname) export OS
libselinux/src/Makefile +9 -2
@@ -158,11 +158,18 @@ $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) $(SWIGRUBYSO): $(SWIGRUBYLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $^ -lselinux $(RUBYLIBS) +libselinux.map: libselinux.map.in + if [ ${LONG_BIT} -lt 64 ]; then \ + sed 's/@matchpathcon_filespec_add64@/matchpathcon_filespec_add64/' < $< > $@; \ + else \ + sed 's/@matchpathcon_filespec_add64@/matchpathcon_filespec_add/' < $< > $@; \ + fi + $(LIBA): $(OBJS) $(AR) rcs $@ $^ $(RANLIB) $@ -$(LIBSO): $(LOBJS) +$(LIBSO): $(LOBJS) | libselinux.map $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS) ln -sf $@ $(TARGET)
@@ -212,7 +219,7 @@ clean-rubywrap: -rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO) clean: clean-pywrap clean-rubywrap - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) libselinux.map *.o *.lo *~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)
libselinux/src/libselinux.map.in renamed from libselinux/src/libselinux.map +1 -1
@@ -255,7 +255,7 @@ LIBSELINUX_3.5 { LIBSELINUX_3.8 { global: - matchpathcon_filespec_add64; + @matchpathcon_filespec_add64@; } LIBSELINUX_3.5; LIBSELINUX_3.9 {
Stephen Smalley
maintainerQuoted 32 lines · Petr Lautrbach
Quoted 19 lines · Stephen Smalley
Quoted 17 lines · Christian Göttsche
Quoted 13 lines · Stephen Smalley
commit
9395cc03226a0("Always build for LFS mode on 32-bit archs.") introduced amatchpathcon_filespec_add64symbol for certain 32-bit configurations but added it to libselinux.map. This was benign under GNU ld but breaks lld due to differing defaults for --no-undefined-version. Add --undefined-version toLD_SONAME_FLAGSto avoid breakage when building with lld.Fix: #512
Fix: #513Fixes 9395cc03226a0 ("Always build for LFS mode on 32-bit archs.")Reported-by Pepper Gray <[email protected]>Signed-off-by Stephen Smalley <[email protected]>Quoted 8 lines
Quoted 2 lines
Personally I liked the fallback wrapper definition of
matchpathcon_filespec_add64()more...I don't strongly care either way. See
https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674610134
and https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674659036
for the argument made against
adding the wrapper definition.
Quoted 7 lines
Could we use libselinux.map.in and generate libselinux.map build time?
Add matchpathcon_filespec_add64@LIBSELINUX_3.8 symbol when bits are lower than 64, add matchpathcon_filespec_add@LIBSELINUX_3.8 when bits are 64
Something like the patch bellow. Would it be too complicated?
We would need to match the logic used in selinux.h:
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && \
defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)#define matchpathcon_filespec_add matchpathcon_filespec_add64 #endif
Yet another option would be to allow overriding of LD_SONAME_FLAGS or introduce another Makefile variable that is appended to it that can be overridden so that the build system could inject --undefined-version when linking with lld.
Quoted 69 lines
1. convert .map to map.in
$ sed 's/matchpathcon_filespec_add64/@matchpathcon_filespec_add64@/' libselinux/src/libselinux.map > libselinux/src/libselinux.map.in2.
libselinux/Makefile +2
-0@@ -39,6 +39,8 @@ ifeq ($(USE_LFS),y) LFS_CFLAGS := -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 endif export LFS_CFLAGS +LONG_BIT := $(shell getconf LONG_BIT) +export LONG_BIT OS := $(shell uname) export OSlibselinux/src/Makefile +9
-2@@ -158,11 +158,18 @@ $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) $(SWIGRUBYSO): $(SWIGRUBYLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $^ -lselinux $(RUBYLIBS) +libselinux.map: libselinux.map.in + if [ ${LONG_BIT} -lt 64 ]; then \ + sed 's/@matchpathcon_filespec_add64@/matchpathcon_filespec_add64/' < $< > $@; \ + else \ + sed 's/@matchpathcon_filespec_add64@/matchpathcon_filespec_add/' < $< > $@; \ + fi + $(LIBA): $(OBJS) $(AR) rcs $@ $^ $(RANLIB) $@ -$(LIBSO): $(LOBJS) +$(LIBSO): $(LOBJS) | libselinux.map $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS) ln -sf $@ $(TARGET)@@ -212,7 +219,7 @@ clean-rubywrap: -rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO) clean: clean-pywrap clean-rubywrap - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) libselinux.map *.o *.lo *~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)libselinux/src/libselinux.map.in renamed from libselinux/src/libselinux.map +1
-1@@ -255,7 +255,7 @@ LIBSELINUX_3.5 { LIBSELINUX_3.8 { global: - matchpathcon_filespec_add64; + @matchpathcon_filespec_add64@; } LIBSELINUX_3.5; LIBSELINUX_3.9 {
Quoted 44 lines · Stephen Smalley
Quoted 32 lines · Petr Lautrbach
Quoted 19 lines · Stephen Smalley
Quoted 17 lines · Christian Göttsche
Quoted 13 lines · Stephen Smalley
commit
9395cc03226a0("Always build for LFS mode on 32-bit archs.") introduced amatchpathcon_filespec_add64symbol for certain 32-bit configurations but added it to libselinux.map. This was benign under GNU ld but breaks lld due to differing defaults for --no-undefined-version. Add --undefined-version toLD_SONAME_FLAGSto avoid breakage when building with lld.Fix: #512
Fix: #513Fixes 9395cc03226a0 ("Always build for LFS mode on 32-bit archs.")Reported-by Pepper Gray <[email protected]>Signed-off-by Stephen Smalley <[email protected]>Quoted 8 lines
Quoted 2 lines
Personally I liked the fallback wrapper definition of
matchpathcon_filespec_add64()more...I don't strongly care either way. See
https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674610134
and https://github.com/SELinuxProject/selinux/pull/513#issuecomment-4674659036
for the argument made against
adding the wrapper definition.Quoted 7 lines
Could we use libselinux.map.in and generate libselinux.map build time?
Add matchpathcon_filespec_add64@LIBSELINUX_3.8 symbol when bits are lower than 64, add matchpathcon_filespec_add@LIBSELINUX_3.8 when bits are 64
Something like the patch bellow. Would it be too complicated?
We would need to match the logic used in
selinux.h:#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && \ defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)
Quoted 7 lines
#define
matchpathcon_filespec_addmatchpathcon_filespec_add64#endifYet another option would be to allow overriding of
LD_SONAME_FLAGSor introduce anotherMakefilevariable that is appended to it that can be overridden so that the build system could inject --undefined-version when linking with lld.
This would be my preferred solution together with a note in README.md or somewhere.
Quoted 69 lines
Quoted 69 lines
1. convert .map to map.in
$ sed 's/matchpathcon_filespec_add64/@matchpathcon_filespec_add64@/' libselinux/src/libselinux.map > libselinux/src/libselinux.map.in2.
libselinux/Makefile +2
-0@@ -39,6 +39,8 @@ ifeq ($(USE_LFS),y) LFS_CFLAGS := -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 endif export LFS_CFLAGS +LONG_BIT := $(shell getconf LONG_BIT) +export LONG_BIT OS := $(shell uname) export OSlibselinux/src/Makefile +9
-2@@ -158,11 +158,18 @@ $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) $(SWIGRUBYSO): $(SWIGRUBYLOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L. -fPIC -shared -o $@ $^ -lselinux $(RUBYLIBS) +libselinux.map: libselinux.map.in + if [ ${LONG_BIT} -lt 64 ]; then \ + sed 's/@matchpathcon_filespec_add64@/matchpathcon_filespec_add64/' < $< > $@; \ + else \ + sed 's/@matchpathcon_filespec_add64@/matchpathcon_filespec_add/' < $< > $@; \ + fi + $(LIBA): $(OBJS) $(AR) rcs $@ $^ $(RANLIB) $@ -$(LIBSO): $(LOBJS) +$(LIBSO): $(LOBJS) | libselinux.map $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS) ln -sf $@ $(TARGET)@@ -212,7 +219,7 @@ clean-rubywrap: -rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO) clean: clean-pywrap clean-rubywrap - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) libselinux.map *.o *.lo *~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)libselinux/src/libselinux.map.in renamed from libselinux/src/libselinux.map +1
-1@@ -255,7 +255,7 @@ LIBSELINUX_3.5 { LIBSELINUX_3.8 { global: - matchpathcon_filespec_add64; + @matchpathcon_filespec_add64@; } LIBSELINUX_3.5; LIBSELINUX_3.9 {