diff mbox series

[v2] libselinux/utils: drop requirement to combine compiling and linking

Message ID 20210914131007.24150-1-cgzones@googlemail.com (mailing list archive)
State Accepted
Headers show
Series [v2] libselinux/utils: drop requirement to combine compiling and linking | expand

Commit Message

Christian Göttsche Sept. 14, 2021, 1:10 p.m. UTC
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(-)

Comments

Petr Lautrbach Sept. 22, 2021, 11:24 a.m. UTC | #1
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
diff mbox series

Patch

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)