selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libselinux/utils: drop requirement to combine compiling and linking
@ 2021-07-14 18:13 Christian Göttsche
  2021-08-15 18:35 ` Nicolas Iooss
  2021-09-14 13:10 ` [PATCH v2] " Christian Göttsche
  0 siblings, 2 replies; 4+ messages in thread
From: Christian Göttsche @ 2021-07-14 18:13 UTC (permalink / raw)
  To: selinux

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

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/utils/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index b018a08a..f01295fd 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -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)
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] libselinux/utils: drop requirement to combine compiling and linking
  2021-07-14 18:13 [PATCH] libselinux/utils: drop requirement to combine compiling and linking Christian Göttsche
@ 2021-08-15 18:35 ` Nicolas Iooss
  2021-09-14 13:10 ` [PATCH v2] " Christian Göttsche
  1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Iooss @ 2021-08-15 18:35 UTC (permalink / raw)
  To: Christian Göttsche; +Cc: SElinux list

On Wed, Jul 14, 2021 at 8:13 PM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> 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
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
>  libselinux/utils/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
> index b018a08a..f01295fd 100644
> --- a/libselinux/utils/Makefile
> +++ b/libselinux/utils/Makefile
> @@ -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?

diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index b018a08acbe0..086f9cbe91c4 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] libselinux/utils: drop requirement to combine compiling and linking
  2021-07-14 18:13 [PATCH] libselinux/utils: drop requirement to combine compiling and linking Christian Göttsche
  2021-08-15 18:35 ` Nicolas Iooss
@ 2021-09-14 13:10 ` Christian Göttsche
  2021-09-22 11:24   ` Petr Lautrbach
  1 sibling, 1 reply; 4+ messages in thread
From: Christian Göttsche @ 2021-09-14 13:10 UTC (permalink / raw)
  To: selinux

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

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
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(-)

diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index b018a08a..36816155 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -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)
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] libselinux/utils: drop requirement to combine compiling and linking
  2021-09-14 13:10 ` [PATCH v2] " Christian Göttsche
@ 2021-09-22 11:24   ` Petr Lautrbach
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Lautrbach @ 2021-09-22 11:24 UTC (permalink / raw)
  To: Christian Göttsche, selinux

Christian Göttsche <cgzones@googlemail.com> writes:

> 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
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

Acked-by: Petr Lautrbach <plautrba@redhat.com>

Thanks!


> ---
> 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(-)
>
> diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
> index b018a08a..36816155 100644
> --- a/libselinux/utils/Makefile
> +++ b/libselinux/utils/Makefile
> @@ -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)
>  
> -- 
> 2.33.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-22 11:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 18:13 [PATCH] libselinux/utils: drop requirement to combine compiling and linking Christian Göttsche
2021-08-15 18:35 ` Nicolas Iooss
2021-09-14 13:10 ` [PATCH v2] " Christian Göttsche
2021-09-22 11:24   ` Petr Lautrbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).