Skip to contentSkip to conversation

libselinux/utils: drop requirement to combine compiling and linking

PATCH Superseded Christian Göttsche 3 participants 4 messages Jul 14, 2021 – Sep 22, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux/utils: drop requirement to combine compiling and linking

The extra dependency of sefcontext_compile on its object file causes the compile and link step to be separated.
During the link step the CFLAGS are not passed, which might contain optimization or sanitizer flags.

Current behavior:

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -c -o sefcontext_compile.o sefcontext_compile.c
gcc-11 -L../src sefcontext_compile.o ../src/regex.o -lselinux -lpcre ../src/libselinux.a -lsepol -o sefcontext_compile

Changed:

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -L../src sefcontext_compile.c ../src/regex.o -lselinux -lpcre ../src/libselinux.a -lsepol -o sefcontext_compile

---
 libselinux/utils/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/utils/Makefile +1 -1
index b018a08a..f01295fd 100644
@@ -54,7 +54,7 @@ endif
 
 sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol
 
-sefcontext_compile: sefcontext_compile.o ../src/regex.o
+sefcontext_compile: ../src/regex.o
 
 all: $(TARGETS)
 
Signature · 1 line
2.32.0
#1 lore raw
Quoted 25 lines · Christian Göttsche

The extra dependency of sefcontext_compile on its object file causes the compile and link step to be separated.
During the link step the CFLAGS are not passed, which might contain optimization or sanitizer flags.

Current behavior:

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -c -o sefcontext_compile.o sefcontext_compile.c
gcc-11 -L../src sefcontext_compile.o ../src/regex.o -lselinux -lpcre ../src/libselinux.a -lsepol -o sefcontext_compile

Changed:

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -L../src sefcontext_compile.c ../src/regex.o -lselinux -lpcre ../src/libselinux.a -lsepol -o sefcontext_compile

---
 libselinux/utils/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/utils/Makefile +0 -0
index b018a08a..f01295fd 100644

libselinux/utils/Makefile endif · line 60

Quoted 8 lines
libselinux/utils/Makefile +1 -1
@@ -54,7 +54,7 @@ endif
 
 sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol
 
-sefcontext_compile: sefcontext_compile.o ../src/regex.o
+sefcontext_compile: ../src/regex.o
 
 all: $(TARGETS)
 

Hello,

In my humble opinion, this patch makes reading ilbselinux/utils/Makefile harder: it is no longer clear that sefcontext_compile depends on sefcontext_compile.c. While I prefer adding an explicit rule (such as "$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)"), it seems that your issue can be fixed differently, by completely removing "sefcontext_compile: sefcontext_compile.o ../src/regex.o". Indeed, as regex.o is included in ../src/libselinux.a, it does not need to be included again.

Could you please test that this patch works?

libselinux/utils/Makefile +0 -2
index b018a08acbe0..086f9cbe91c4 100644
@@ -54,8 +54,6 @@ endif
 
 sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol
 
-sefcontext_compile: sefcontext_compile.o ../src/regex.o
-
 all: $(TARGETS)
 
 install: all

--

(It would be even nicer if sefcontext_compile did not depend on libselinux.a, but removing the dependency to libselinux.a is a much harder topic).

Thanks,
Nicolas

#2 lore raw

PATCH v2 1/1 libselinux/utils: drop requirement to combine compiling and linking

In reply to Christian Göttsche

The extra dependency of sefcontext_compile on its object file causes the compile and link step to be separated.
During the link step the CFLAGS are not passed, which might contain optimization or sanitizer flags.

Reorder the LDLIBS requirements to avoid the symbol 'pcre_fullinfo' being unresolvable at link time.

Current behavior:

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -c -o sefcontext_compile.o sefcontext_compile.c
gcc-11 -L../src sefcontext_compile.o ../src/regex.o -lselinux -lpcre ../src/libselinux.a -lsepol -o sefcontext_compile

Changed:

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -L../src sefcontext_compile.c -lselinux ../src/libselinux.a -lpcre -lsepol -o sefcontext_compile

---
v2:
- drop line regarding regex.o, as suggested by Nicolas Iooss.
- order -lpcre after libselinux.a

 libselinux/utils/Makefile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
libselinux/utils/Makefile +1 -3
index b018a08a..36816155 100644
@@ -52,9 +52,7 @@ else
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 endif
 
-sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol
-
-sefcontext_compile: sefcontext_compile.o ../src/regex.o
+sefcontext_compile: LDLIBS += ../src/libselinux.a $(PCRE_LDLIBS) -lsepol
 
 all: $(TARGETS)
 
Signature · 1 line
2.33.0
Acked-by on v2 1/1
#3 lore raw
Quoted 10 lines · Christian Göttsche

The extra dependency of sefcontext_compile on its object file causes the compile and link step to be separated.
During the link step the CFLAGS are not passed, which might contain optimization or sanitizer flags.

Reorder the LDLIBS requirements to avoid the symbol 'pcre_fullinfo' being unresolvable at link time.

Current behavior:

Quoted 8 lines

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -c -o sefcontext_compile.o sefcontext_compile.c
gcc-11 -L../src sefcontext_compile.o ../src/regex.o -lselinux -lpcre ../src/libselinux.a -lsepol -o sefcontext_compile

Changed:

gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE -L../src sefcontext_compile.c -lselinux ../src/libselinux.a -lpcre -lsepol -o sefcontext_compile

Thanks!

Quoted 26 lines

---
v2:
- drop line regarding regex.o, as suggested by Nicolas Iooss.
- order -lpcre after libselinux.a

 libselinux/utils/Makefile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
libselinux/utils/Makefile +1 -3
index b018a08a..36816155 100644
@@ -52,9 +52,7 @@ else
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 endif
 
-sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol
-
-sefcontext_compile: sefcontext_compile.o ../src/regex.o
+sefcontext_compile: LDLIBS += ../src/libselinux.a $(PCRE_LDLIBS) -lsepol
 
 all: $(TARGETS)
 
Signature · 1 line
2.33.0