Skip to contentSkip to conversation

Re-link programs after libsepol.a is updated

PATCH In review Nicolas Iooss 2 participants 4 messages Jan 14, 2017 – Jan 18, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Re-link programs after libsepol.a is updated

After libsepol is modified (for example while developing new features or fixing bugs), running "make install" in the top-level directory does not update the programs which use libsepol.a. Add this static library to the target dependencies in order to force their updates. This makes "make" use libsepol.a in the linking command without using LDLIBS.

While at it, copy what commit 14d706434846 ("libselinux: Allow overriding libsepol.a location during build") introduced in libselinux Makefile by using a new LIBSEPOLA variable in all Makefiles.

---
 checkpolicy/Makefile                  | 7 +++----
 checkpolicy/test/Makefile             | 7 +++----
 libselinux/src/Makefile               | 4 ++--
 mcstrans/utils/Makefile               | 7 +++++--
 python/audit2allow/Makefile           | 4 ++--
 semodule-utils/semodule_deps/Makefile | 4 ++--
 6 files changed, 17 insertions(+), 16 deletions(-)
checkpolicy/Makefile +3 -4
index 875cf008cae0..98fa38017583 100644
@@ -6,6 +6,7 @@ BINDIR ?= $(PREFIX)/bin
 MANDIR ?= $(PREFIX)/share/man
 LIBDIR ?= $(PREFIX)/lib
 INCLUDEDIR ?= $(PREFIX)/include
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 TARGETS = checkpolicy checkmodule
 
 LEX = flex
@@ -20,16 +21,14 @@ CHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \
 CHECKPOLOBJS = $(CHECKOBJS) checkpolicy.o
 CHECKMODOBJS = $(CHECKOBJS) checkmodule.o
 
-LDLIBS=$(LIBDIR)/libsepol.a
-
 GENERATED=lex.yy.c y.tab.c y.tab.h
 
 all:  $(TARGETS)
 	$(MAKE) -C test
 
-checkpolicy: $(CHECKPOLOBJS)
+checkpolicy: $(CHECKPOLOBJS) $(LIBSEPOLA)
 
-checkmodule: $(CHECKMODOBJS)
+checkmodule: $(CHECKMODOBJS) $(LIBSEPOLA)
 
 %.o: %.c 
 	$(CC) $(CFLAGS) -o $@ -c $<
checkpolicy/test/Makefile +3 -4
index e7bd717a7c9a..54d07f81a9c7 100644
@@ -5,17 +5,16 @@ PREFIX ?= $(DESTDIR)/usr
 BINDIR=$(PREFIX)/bin
 LIBDIR ?= $(PREFIX)/lib
 INCLUDEDIR ?= $(PREFIX)/include
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
 override CFLAGS += -I$(INCLUDEDIR)
 
-LDLIBS=$(LIBDIR)/libsepol.a -L$(LIBDIR)
-
 all: dispol dismod
 
-dispol: dispol.o
+dispol: dispol.o $(LIBSEPOLA)
 
-dismod: dismod.o
+dismod: dismod.o $(LIBSEPOLA)
 
 clean:
 	-rm -f dispol dismod *.o 
libselinux/src/Makefile +2 -2
index d17792c13350..5640a57d2768 100644
@@ -155,8 +155,8 @@ selinuxswig_python_exception.i: ../include/selinux/selinux.h
 $(AUDIT2WHYLOBJ): audit2why.c
 	$(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<
 
-$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
-	$(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(LIBSEPOLA) $(PYLIBS) -L$(LIBDIR)
+$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
+	$(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(PYLIBS) -L$(LIBDIR)
 
 %.o:  %.c policy.h
 	$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
mcstrans/utils/Makefile +5 -2
index a0f93f548557..043d001d639c 100644
@@ -2,14 +2,17 @@
 PREFIX ?= $(DESTDIR)/usr
 LIBDIR ?= $(PREFIX)/lib
 BINDIR ?= $(PREFIX)/sbin
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -Wall
 override CFLAGS += -I../src -I$(PREFIX)/include -D_GNU_SOURCE
-LDLIBS += -L$(LIBDIR) ../src/mcstrans.o ../src/mls_level.o -lselinux -lpcre $(LIBDIR)/libsepol.a
+LDLIBS += -L$(LIBDIR) -lselinux -lpcre
 
 TARGETS=$(patsubst %.c,%,$(wildcard *.c))
 
-all: $(TARGETS) 
+all: $(TARGETS)
+
+$(TARGETS): ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
 
 install: all
 	-mkdir -p $(BINDIR)
python/audit2allow/Makefile +2 -2
index 16b5cc8dcb59..4f03e956125a 100644
@@ -7,14 +7,14 @@ LIBDIR ?= $(PREFIX)/lib
 MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 INCLUDEDIR ?= $(PREFIX)/include
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I$(INCLUDEDIR)
-LDLIBS = $(LIBDIR)/libsepol.a
 
 all: audit2why sepolgen-ifgen-attr-helper
 
-sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o
+sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o $(LIBSEPOLA)
 
 audit2why:
 	ln -sf audit2allow audit2why
semodule-utils/semodule_deps/Makefile +2 -2
index 28d667e9f4b8..7d8490f2f1a8 100644
@@ -4,14 +4,14 @@ INCLUDEDIR ?= $(PREFIX)/include
 BINDIR ?= $(PREFIX)/bin
 LIBDIR ?= $(PREFIX)/lib
 MANDIR ?= $(PREFIX)/share/man
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I$(INCLUDEDIR)
-LDLIBS = $(LIBDIR)/libsepol.a
 
 all: semodule_deps
 
-semodule_deps:  semodule_deps.o 
+semodule_deps:  semodule_deps.o $(LIBSEPOLA)
 
 install: all
 	-mkdir -p $(BINDIR)
Signature · 1 line
2.11.0
#1 lore raw
Quoted 97 lines · Nicolas Iooss

After libsepol is modified (for example while developing new features or
fixing bugs), running "make install" in the top-level directory does not
update the programs which use libsepol.a. Add this static library to the
target dependencies in order to force their updates. This makes "make"
use libsepol.a in the linking command without using LDLIBS.

While at it, copy what commit 14d706434846 ("libselinux: Allow overriding libsepol.a location during build") introduced in libselinux
Makefile by using a new LIBSEPOLA variable in all Makefiles.

---
 checkpolicy/Makefile                  | 7 +++---- checkpolicy/test/Makefile             | 7 +++---- libselinux/src/Makefile               | 4 ++-- mcstrans/utils/Makefile               | 7 +++++-- python/audit2allow/Makefile           | 4 ++-- semodule-utils/semodule_deps/Makefile | 4 ++--

 6 files changed, 17 insertions(+), 16 deletions(-)
checkpolicy/Makefile +0 -0
index 875cf008cae0..98fa38017583 100644
@@ -6,6 +6,7 @@ BINDIR ?= $(PREFIX)/bin

 MANDIR ?= $(PREFIX)/share/man
 LIBDIR ?= $(PREFIX)/lib
 INCLUDEDIR ?= $(PREFIX)/include
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 TARGETS = checkpolicy checkmodule

 LEX = flex

checkpolicy/Makefile +0 -0
@@ -20,16 +21,14 @@ CHECKOBJS = y.tab.o lex.yy.o queue.o
 module_compiler.o parse_util.o \

 CHECKPOLOBJS = $(CHECKOBJS) checkpolicy.o
 CHECKMODOBJS = $(CHECKOBJS) checkmodule.o

checkpolicy/Makefile +0 -2
-LDLIBS=$(LIBDIR)/libsepol.a
-

 GENERATED=lex.yy.c y.tab.c y.tab.h

 all:  $(TARGETS)
  $(MAKE) -C test

checkpolicy/Makefile +1 -1
-checkpolicy: $(CHECKPOLOBJS)
+checkpolicy: $(CHECKPOLOBJS) $(LIBSEPOLA)

checkpolicy/Makefile +1 -1
-checkmodule: $(CHECKMODOBJS)
+checkmodule: $(CHECKMODOBJS) $(LIBSEPOLA)


 %.o: %.c
  $(CC) $(CFLAGS) -o $@ -c $<

checkpolicy/test/Makefile +0 -0
index e7bd717a7c9a..54d07f81a9c7 100644
@@ -5,17 +5,16 @@ PREFIX ?= $(DESTDIR)/usr

 BINDIR=$(PREFIX)/bin
 LIBDIR ?= $(PREFIX)/lib
 INCLUDEDIR ?= $(PREFIX)/include
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a

 CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
 override CFLAGS += -I$(INCLUDEDIR)

checkpolicy/test/Makefile +0 -2
-LDLIBS=$(LIBDIR)/libsepol.a -L$(LIBDIR)
-

 all: dispol dismod

checkpolicy/test/Makefile +1 -1
-dispol: dispol.o
+dispol: dispol.o $(LIBSEPOLA)

checkpolicy/test/Makefile +1 -1
-dismod: dismod.o
+dismod: dismod.o $(LIBSEPOLA)


 clean:
  -rm -f dispol dismod *.o

libselinux/src/Makefile +0 -0
index d17792c13350..5640a57d2768 100644
@@ -155,8 +155,8 @@ selinuxswig_python_exception.i:

../include/selinux/selinux.h
 $(AUDIT2WHYLOBJ): audit2why.c
  $(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<

-$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)

libselinux/src/Makefile +0 -1
-	$(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux

$(LIBSEPOLA) $(PYLIBS) -L$(LIBDIR)
+$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)

libselinux/src/Makefile +1 -0
+	$(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux
Quoted 1 line

$(PYLIBS) -L$(LIBDIR)

Why did you change this?

Quoted 73 lines


 %.o:  %.c policy.h
  $(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<

mcstrans/utils/Makefile +0 -0
index a0f93f548557..043d001d639c 100644
@@ -2,14 +2,17 @@

 PREFIX ?= $(DESTDIR)/usr
 LIBDIR ?= $(PREFIX)/lib
 BINDIR ?= $(PREFIX)/sbin
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a

 CFLAGS ?= -Wall
 override CFLAGS += -I../src -I$(PREFIX)/include -D_GNU_SOURCE

mcstrans/utils/Makefile +1 -2
-LDLIBS += -L$(LIBDIR) ../src/mcstrans.o ../src/mls_level.o -lselinux
-lpcre $(LIBDIR)/libsepol.a
+LDLIBS += -L$(LIBDIR) -lselinux -lpcre


 TARGETS=$(patsubst %.c,%,$(wildcard *.c))

mcstrans/utils/Makefile +3 -1
-all: $(TARGETS) 
+all: $(TARGETS)
+
+$(TARGETS): ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)


 install: all
  -mkdir -p $(BINDIR)

python/audit2allow/Makefile +0 -0
index 16b5cc8dcb59..4f03e956125a 100644
@@ -7,14 +7,14 @@ LIBDIR ?= $(PREFIX)/lib

 MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 INCLUDEDIR ?= $(PREFIX)/include
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a

 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I$(INCLUDEDIR)
-LDLIBS = $(LIBDIR)/libsepol.a

 all: audit2why sepolgen-ifgen-attr-helper

python/audit2allow/Makefile +1 -1
-sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o
+sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o

$(LIBSEPOLA)

 audit2why:
  ln -sf audit2allow audit2why

semodule- renamed from semodule-utils/semodule_deps/Makefile +0 -0

utils/semodule_deps/Makefile
index 28d667e9f4b8..7d8490f2f1a8 100644

semodule-utils/semodule_deps/Makefile +0 -0
@@ -4,14 +4,14 @@ INCLUDEDIR ?= $(PREFIX)/include

 BINDIR ?= $(PREFIX)/bin
 LIBDIR ?= $(PREFIX)/lib
 MANDIR ?= $(PREFIX)/share/man
+LIBSEPOLA ?= $(LIBDIR)/libsepol.a

 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I$(INCLUDEDIR)
-LDLIBS = $(LIBDIR)/libsepol.a

 all: semodule_deps

semodule-utils/semodule_deps/Makefile +1 -1
-semodule_deps:  semodule_deps.o 
+semodule_deps:  semodule_deps.o $(LIBSEPOLA)


 install: all
  -mkdir -p $(BINDIR)

#2 lore raw
Quoted 27 lines · Stephen Smalley
Quoted 14 lines · Nicolas Iooss

After libsepol is modified (for example while developing new features or
fixing bugs), running "make install" in the top-level directory does not
update the programs which use libsepol.a. Add this static library to the
target dependencies in order to force their updates. This makes "make"
use libsepol.a in the linking command without using LDLIBS.

While at it, copy what commit 14d706434846 ("libselinux: Allow overriding libsepol.a location during build") introduced in libselinux
Makefile by using a new LIBSEPOLA variable in all Makefiles.

libselinux/src/Makefile +0 -0
Quoted 9 lines

index d17792c13350..5640a57d2768 100644

libselinux/src/Makefile +0 -0
@@ -155,8 +155,8 @@ selinuxswig_python_exception.i:

../include/selinux/selinux.h
$(AUDIT2WHYLOBJ): audit2why.c

      $(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC

-DSHARED -c -o $@ $<

Quoted 8 lines
Quoted 6 lines

-$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
- $(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux
$(LIBSEPOLA) $(PYLIBS) -L$(LIBDIR)
+$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
+ $(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux
$(PYLIBS) -L$(LIBDIR)

Why did you change this?

When libsepol.a is updated, $(AUDIT2WHYSO) (which is a Python extension, named something like python3audit2why.so and installed as module "selinux.audit2why") was not rebuilt. Adding $(LIBSEPOLA) to the dependencies (in order to fix this) makes libsepol.a appear in the command line through $^ so I removed $(LIBSEPOLA) from the "$(CC)..." line.

Thanks for your review,
Nicolas

#3 lore raw
Quoted 41 lines · Nicolas Iooss
Quoted 30 lines · Stephen Smalley
Quoted 1 line · Nicolas Iooss

After libsepol is modified (for example while developing new

features

Quoted 2 lines

or
fixing bugs), running "make install" in the top-level directory

does

Quoted 2 lines

not
update the programs which use libsepol.a. Add this static library

to

Quoted 21 lines

the
target dependencies in order to force their updates. This makes "make"
use libsepol.a in the linking command without using LDLIBS.

While at it, copy what commit 14d706434846 ("libselinux: Allow overriding libsepol.a location during build") introduced in libselinux
Makefile by using a new LIBSEPOLA variable in all Makefiles.

libselinux/src/Makefile +0 -0
index d17792c13350..5640a57d2768 100644
@@ -155,8 +155,8 @@ selinuxswig_python_exception.i:

../include/selinux/selinux.h
 $(AUDIT2WHYLOBJ): audit2why.c
      $(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<

Quoted 8 lines
Quoted 6 lines

-$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
-     $(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(LIBSEPOLA) $(PYLIBS) -L$(LIBDIR)
+$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
+     $(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(PYLIBS) -L$(LIBDIR)

Why did you change this?

Quoted 6 lines

When libsepol.a is updated, $(AUDIT2WHYSO) (which is a Python extension, named something like python3audit2why.so and installed as module "selinux.audit2why") was not rebuilt. Adding $(LIBSEPOLA) to the dependencies (in order to fix this) makes libsepol.a appear in the command line through $^ so I removed $(LIBSEPOLA) from the "$(CC)..." line.

Ok, thanks.  Applied.