Skip to contentSkip to conversation

libselinux: Add EXTRA_LD_FLAGS for musl+llvm builds

PATCH In review Stephen Smalley 1 participant 2 messages Jun 16 – Jun 17 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH v2 1/1 libselinux: Add EXTRA_LD_FLAGS for musl+llvm builds

Introduce an optionally defined EXTRA_LD_FLAGS variable for use by musl+llvm builds to pass --undefined-version. This enables such builds to link despite the intentionally omitted matchpathcon_filespec_add64 symbol.

---
v2 fixes the missing comma issue noted by Petr and shortens the new variable name to just EXTRA_LD_FLAGS, moving its use down to only the line where the linker is called.

 README.md               | 4 ++++
 libselinux/src/Makefile | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
README.md +4 -0
index 5e65a049..ea8c4e46 100644
@@ -151,6 +151,10 @@ set when overriding are:
 - -fno-semantic-interposition for gcc or compilers that do not do this. clang does this by default. clang-10 and up
    will support passing this flag, but ignore it. Previous clang versions fail.
 
+## Setting EXTRA_LD_FLAGS
+
+Build with EXTRA_LD_FLAGS=--undefined-version to fix linking against
+musl with llvm.
 
 macOS
 -----
libselinux/src/Makefile +4 -1
index 9982faad..9ecdbd4d 100644
@@ -7,6 +7,9 @@ RUBY ?= ruby
 RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
+# Set EXTRA_LD_FLAGS to --undefined-version to fix
+# linking against musl with llvm.
+
 # Installation directories.
 PREFIX ?= /usr
 LIBDIR ?= $(PREFIX)/lib
@@ -163,7 +166,7 @@ $(LIBA): $(OBJS)
 	$(RANLIB) $@
 
 $(LIBSO): $(LOBJS)
-	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS)
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS)$(EXTRA_LD_FLAGS:%=,%)
 	ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
Signature · 1 line
2.54.0
author maintainer
#1 lore raw
Quoted 6 lines · Stephen Smalley

Introduce an optionally defined EXTRA_LD_FLAGS variable for use by musl+llvm builds to pass --undefined-version. This enables such builds to link despite the intentionally omitted matchpathcon_filespec_add64 symbol.

Quoted 7 lines

Merged.

Quoted 50 lines

---
v2 fixes the missing comma issue noted by Petr and shortens the new variable name to just EXTRA_LD_FLAGS, moving its use down to only the line where the linker is called.

 README.md               | 4 ++++
 libselinux/src/Makefile | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
README.md +4 -0
index 5e65a049..ea8c4e46 100644
@@ -151,6 +151,10 @@ set when overriding are:
 - -fno-semantic-interposition for gcc or compilers that do not do this. clang does this by default. clang-10 and up
    will support passing this flag, but ignore it. Previous clang versions fail.
 
+## Setting EXTRA_LD_FLAGS
+
+Build with EXTRA_LD_FLAGS=--undefined-version to fix linking against
+musl with llvm.
 
 macOS
 -----
libselinux/src/Makefile +4 -2
index 9982faad..9ecdbd4d 100644
@@ -7,6 +7,9 @@ RUBY ?= ruby
 RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
+# Set EXTRA_LD_FLAGS to --undefined-version to fix
+# linking against musl with llvm.
+
 # Installation directories.
 PREFIX ?= /usr
 LIBDIR ?= $(PREFIX)/lib
@@ -163,7 +166,7 @@ $(LIBA): $(OBJS)
        $(RANLIB) $@
 
 $(LIBSO): $(LOBJS)
-       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS)
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $^ $(PCRE_LDLIBS) $(FTS_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS)$(EXTRA_LD_FLAGS:%=,%)
        ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
--

2.54.0