Skip to contentSkip to conversation

libsepol: make reallocarray check more robust

PATCH In review Stephen Smalley 2 participants 4 messages Jun 8 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libsepol: make reallocarray check more robust

From: Waldemar Brodkorb <[email protected]>

Some cross-compiler toolchains dislike the usage of -o /dev/null and fail
with: ld: final link failed: file truncated

As stdin and stdout is already redirected to /dev/null there is no need for gcc -o /dev/null.

This fixes an Buildroot autobuild failure for libsepol package:
http://autobuild.buildroot.net/results/72b/72baaab4658254f4c5b3348298af1d5c891cacd6/

---
 libsepol/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +1 -1
index c222a8fd..cd6ef442 100644
@@ -31,7 +31,7 @@ endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif
 
Signature · 1 line
2.54.0
author maintainer
#1 lore raw
Quoted 22 lines · Stephen Smalley

From: Waldemar Brodkorb <[email protected]>

Some cross-compiler toolchains dislike the usage of -o /dev/null and fail
with: ld: final link failed: file truncated

As stdin and stdout is already redirected to /dev/null there is no need for gcc -o /dev/null.

This fixes an Buildroot autobuild failure for libsepol package:
http://autobuild.buildroot.net/results/72b/72baaab4658254f4c5b3348298af1d5c891cacd6/

---
 libsepol/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +0 -0
index c222a8fd..cd6ef442 100644

libsepol/src/Makefile endif · line 36

Quoted 7 lines
libsepol/src/Makefile +1 -1
@@ -31,7 +31,7 @@ endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif

This leaves an a.out file which then breaks CI,
https://github.com/stephensmalley/selinux/actions/runs/27141099174/job/80106217168

Must be a better way to fix it.

Quoted 4 lines
libsepol/src/Makefile +0 -1
--

2.54.0

#2 lore raw
Quoted 36 lines · Stephen Smalley
Quoted 22 lines · Stephen Smalley

From: Waldemar Brodkorb <[email protected]>

Some cross-compiler toolchains dislike the usage of -o /dev/null and fail
with: ld: final link failed: file truncated

As stdin and stdout is already redirected to /dev/null there is no need for gcc -o /dev/null.

This fixes an Buildroot autobuild failure for libsepol package:
http://autobuild.buildroot.net/results/72b/72baaab4658254f4c5b3348298af1d5c891cacd6/

---
 libsepol/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +0 -0
index c222a8fd..cd6ef442 100644

libsepol/src/Makefile endif · line 36

Quoted 7 lines
libsepol/src/Makefile +1 -1
@@ -31,7 +31,7 @@ endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif

This leaves an a.out file which then breaks CI,
https://github.com/stephensmalley/selinux/actions/runs/27141099174/job/80106217168

Quoted 2 lines

Must be a better way to fix it.

Maybe use "-fsyntax-only"

 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint
main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS)
$(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o
/dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint
main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS)
$(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration
-fsyntax-only -x c - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif

Jim

Quoted 4 lines
Quoted 4 lines
libsepol/src/Makefile +0 -1
--

2.54.0

author maintainer
#3 lore raw
Quoted 44 lines · James Carter
Quoted 36 lines · Stephen Smalley
Quoted 22 lines · Stephen Smalley

From: Waldemar Brodkorb <[email protected]>

Some cross-compiler toolchains dislike the usage of -o /dev/null and fail
with: ld: final link failed: file truncated

As stdin and stdout is already redirected to /dev/null there is no need for gcc -o /dev/null.

This fixes an Buildroot autobuild failure for libsepol package:
http://autobuild.buildroot.net/results/72b/72baaab4658254f4c5b3348298af1d5c891cacd6/

---
 libsepol/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +0 -0
index c222a8fd..cd6ef442 100644

libsepol/src/Makefile endif · line 36

Quoted 7 lines
libsepol/src/Makefile +1 -1
@@ -31,7 +31,7 @@ endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif

This leaves an a.out file which then breaks CI,
https://github.com/stephensmalley/selinux/actions/runs/27141099174/job/80106217168

Quoted 2 lines

Must be a better way to fix it.

Maybe use "-fsyntax-only"

Quoted 12 lines
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint
main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS)
$(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o
/dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint
main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS)
$(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration
-fsyntax-only -x c - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif

This might be OBE; looks like ld fixed it a decade ago so -o /dev/null is safe now.