Improve Makefile portability and debugging
v2 cover Improve Makefile portability and debugging
This patch series improves the stalld build system to be more portable across different architectures and compiler toolchains while adding better debugging capabilities. The main motivation is to eliminate hard-coded compiler version checks that were brittle and could fail on non-standard toolchains or different architectures.
The changes replace minimum version checks with direct compiler feature detection tests, ensuring that compiler flags are only used when actually supported. This approach tests each flag by attempting to compile a minimal test program, making the build system resilient to variations in compiler implementations across architectures like x86_64, aarch64, s390x, i686, and powerpc. Additionally, the series adds build environment information output and cleans up redundant checks to improve maintainability.
The series also includes minor improvements to explicitly specify the test target invocation and exclude development environment metadata from version control.
Wander Lairson Costa (6):
Makefile: Conditionally add -mno-omit-leaf-frame-pointer
Makefile: Improve compiler flag detection for -fcf-protection
Makefile: Explicitly run the 'test' target in the tests directory
Makefile: Remove redundant GCC version check
Makefile: Print BPF tool versions for debugging
gitignore: Exclude Serena and Claude Code metadata
.gitignore | 2 ++ Makefile | 42 ++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 18 deletions(-)
---
Signature · 1 line
2.51.1
PATCH v2 1/6 Makefile: Conditionally add -mno-omit-leaf-frame-pointer
The -mno-omit-leaf-frame-pointer option is not available on all architectures (e.g., s390x) or with older compiler versions. To avoid compilation errors on such systems, this change adds a check to ensure the option is only used when the compiler supports it.
This approach is similar to the existing check for -fcf-protection.
--- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Makefile +7 -1
@@ -60,7 +60,13 @@ FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer \ $(strip $(FCF_PROTECTION)) -fpie -MOPTS := $(strip $(MTUNE)) $(strip $(M64)) -mno-omit-leaf-frame-pointer +# Test if compiler supports -mno-omit-leaf-frame-pointer +OMIT_LEAF_FP := $(shell echo 'int main(void){return 0;}' | \ + $(CC) -x c -mno-omit-leaf-frame-pointer - \ + -o /dev/null 2>/dev/null && \ + echo '-mno-omit-leaf-frame-pointer') + +MOPTS := $(strip $(MTUNE)) $(strip $(M64)) $(strip $(OMIT_LEAF_FP)) WOPTS := -Wall -Werror=format-security
Signature · 1 line
2.51.1
Re: [stalld v2 1/6] Makefile: Conditionally add -mno-omit-leaf-frame-pointer
Quoted 38 lines · Wander Lairson Costa
The -mno-omit-leaf-frame-pointer option is not available on all architectures (e.g., s390x) or with older compiler versions. To avoid compilation errors on such systems, this change adds a check to ensure the option is only used when the compiler supports it.
This approach is similar to the existing check for -fcf-protection.
Signed-off-by Wander Lairson Costa <[email protected]>Cc Derek Barbosa <[email protected]>Cc John Kacur <[email protected]>Cc Juri Lelli <[email protected]>Cc Chunsheng Luo <[email protected]>--- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Makefile +7
-1@@ -60,7 +60,13 @@ FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer \ $(strip $(FCF_PROTECTION)) -fpie -MOPTS := $(strip $(MTUNE)) $(strip $(M64)) -mno-omit-leaf-frame-pointer +# Test if compiler supports -mno-omit-leaf-frame-pointer +OMIT_LEAF_FP := $(shell echo 'int main(void){return 0;}' | \ + $(CC) -x c -mno-omit-leaf-frame-pointer - \ + -o /dev/null 2>/dev/null && \ + echo '-mno-omit-leaf-frame-pointer') + +MOPTS := $(strip $(MTUNE)) $(strip $(M64)) $(strip $(OMIT_LEAF_FP)) WOPTS := -Wall -Werror=format-securitySignature · 1 line
2.51.1
Signature · 2 lines
The United States Coast Guard Ruining Natural Selection since 1790
PATCH v2 2/6 Makefile: Improve compiler flag detection for -fcf-protection
In reply to Wander Lairson CostaThe previous method of detecting support for -fcf-protection relied on a minimum GCC version check, which was not always accurate and could fail on different architectures or compiler toolchains.
This commit replaces the version check with a more robust method that directly tests if the compiler supports the -fcf-protection flag. This ensures better portability and avoids compilation errors on systems where the flag is not available.
This change mirrors the recently added detection logic for the -mno-omit-leaf-frame-pointer flag.
--- Makefile | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
Makefile +12 -11
@@ -20,17 +20,14 @@ IS_MINVER := $(intcmp $(GCC_VER), $(MIN_GCC_VER), false, true, true) $(info IS_MINVER=$(IS_MINVER)) USE_BPF := 1 -FCF_PROTECTION := -fcf-protection MTUNE := -mtune=generic M64 := -m64 ifeq ($(ARCH),aarch64) -FCF_PROTECTION := "-fcf-protection=none" M64 := endif ifeq ($(ARCH),i686) USE_BPF := 0 -FCF_PROTECTION := "-fcf-protection=branch" endif ifeq ($(ARCH),s390x) MTUNE := -mtune=z13
@@ -43,23 +40,23 @@ ifeq ($(ARCH),powerpc) USE_BPF := 0 MTUNE := -mtune=powerpc endif -ifeq ($(strip $(IS_MINVER)), false) -FCF_PROTECTION := -endif - - -$(info USE_BPF=$(USE_BPF)) -$(info FCF_PROTECTION=$(FCF_PROTECTION)) -$(info MTUNE=$(MTUNE)) DEBUG ?= 0 INSTALL = install CC := gcc + +# Test if compiler supports -fcf-protection +FCF_PROTECTION := $(shell echo 'int main(void){return 0;}' | \ + $(CC) -x c -fcf-protection - \ + -o /dev/null 2>/dev/null && \ + echo '-fcf-protection') + FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer \ $(strip $(FCF_PROTECTION)) -fpie + # Test if compiler supports -mno-omit-leaf-frame-pointer OMIT_LEAF_FP := $(shell echo 'int main(void){return 0;}' | \ $(CC) -x c -mno-omit-leaf-frame-pointer - \
@@ -74,6 +71,10 @@ DEFS := -DUSE_BPF=$(USE_BPF) -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -DDEBUG_S CFLAGS := -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(DEFS) +$(info USE_BPF=$(USE_BPF)) +$(info FCF_PROTECTION=$(FCF_PROTECTION)) +$(info MTUNE=$(MTUNE)) + ifeq ($(DEBUG),0) CFLAGS += -g -O2 else
Signature · 1 line
2.51.1
Re: [stalld v2 2/6] Makefile: Improve compiler flag detection for -fcf-protection
Quoted 89 lines · Wander Lairson Costa
The previous method of detecting support for -fcf-protection relied on a minimum GCC version check, which was not always accurate and could fail on different architectures or compiler toolchains.
This commit replaces the version check with a more robust method that directly tests if the compiler supports the -fcf-protection flag. This ensures better portability and avoids compilation errors on systems where the flag is not available.
This change mirrors the recently added detection logic for the -mno-omit-leaf-frame-pointer flag.
Signed-off-by Wander Lairson Costa <[email protected]>Cc Derek Barbosa <[email protected]>Cc John Kacur <[email protected]>Cc Juri Lelli <[email protected]>Cc Chunsheng Luo <[email protected]>--- Makefile | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)Makefile +12
-11@@ -20,17 +20,14 @@ IS_MINVER := $(intcmp $(GCC_VER), $(MIN_GCC_VER), false, true, true) $(info IS_MINVER=$(IS_MINVER)) USE_BPF := 1 -FCF_PROTECTION := -fcf-protection MTUNE := -mtune=generic M64 := -m64 ifeq ($(ARCH),aarch64) -FCF_PROTECTION := "-fcf-protection=none" M64 := endif ifeq ($(ARCH),i686) USE_BPF := 0 -FCF_PROTECTION := "-fcf-protection=branch" endif ifeq ($(ARCH),s390x) MTUNE := -mtune=z13@@ -43,23 +40,23 @@ ifeq ($(ARCH),powerpc) USE_BPF := 0 MTUNE := -mtune=powerpc endif -ifeq ($(strip $(IS_MINVER)), false) -FCF_PROTECTION := -endif - - -$(info USE_BPF=$(USE_BPF)) -$(info FCF_PROTECTION=$(FCF_PROTECTION)) -$(info MTUNE=$(MTUNE)) DEBUG ?= 0 INSTALL = install CC := gcc + +# Test if compiler supports -fcf-protection +FCF_PROTECTION := $(shell echo 'int main(void){return 0;}' | \ + $(CC) -x c -fcf-protection - \ + -o /dev/null 2>/dev/null && \ + echo '-fcf-protection') + FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer \ $(strip $(FCF_PROTECTION)) -fpie + # Test if compiler supports -mno-omit-leaf-frame-pointer OMIT_LEAF_FP := $(shell echo 'int main(void){return 0;}' | \ $(CC) -x c -mno-omit-leaf-frame-pointer - \@@ -74,6 +71,10 @@ DEFS := -DUSE_BPF=$(USE_BPF) -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -DDEBUG_S CFLAGS := -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(DEFS) +$(info USE_BPF=$(USE_BPF)) +$(info FCF_PROTECTION=$(FCF_PROTECTION)) +$(info MTUNE=$(MTUNE)) + ifeq ($(DEBUG),0) CFLAGS += -g -O2 elseSignature · 1 line
2.51.1
Signature · 2 lines
The United States Coast Guard Ruining Natural Selection since 1790
PATCH v2 3/6 Makefile: Explicitly run the 'test' target in the tests directory
In reply to Wander Lairson CostaThe 'tests' target in the main Makefile was invoking 'make' in the 'tests' subdirectory without specifying a target. This relied on the default target in the tests/Makefile, which is not explicit.
This commit adds the 'test' target to the make command, making the build process clearer and more robust.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -183,7 +183,7 @@ static: $(OBJ) $(CC) -o stalld-static $(LDFLAGS) --static $(OBJ) $(LIBS) tests: - make -C tests VERSION=$(VERSION) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" + make -C tests VERSION=$(VERSION) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" test .PHONY: install install: stalld
Signature · 1 line
2.51.1
Re: [stalld v2 3/6] Makefile: Explicitly run the 'test' target in the tests directory
Quoted 21 lines · Wander Lairson Costa
The 'tests' target in the main
Makefilewas invoking 'make' in the 'tests' subdirectory without specifying a target. This relied on the default target in the tests/Makefile, which is not explicit.This commit adds the 'test' target to the make command, making the build process clearer and more robust.
Signed-off-by Wander Lairson Costa <[email protected]>Cc Derek Barbosa <[email protected]>Cc John Kacur <[email protected]>Cc Juri Lelli <[email protected]>Cc Chunsheng Luo <[email protected]>--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +0
-0
Makefile static: $(OBJ) · line 187
Quoted 6 lines
Makefile +1
-1@@ -183,7 +183,7 @@ static: $(OBJ) $(CC) -o stalld-static $(LDFLAGS) --static $(OBJ) $(LIBS) tests: - make -C tests VERSION=$(VERSION) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" + make -C tests VERSION=$(VERSION) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" test
How do you feel about adding a 'sudo' to the make invocation, either here or in the tests/Makefile?
If you don't then the tests run and all pass. If you run it as sudo you find that there are still a couple of failures.
Clark
Signature · 2 lines
The United States Coast Guard Ruining Natural Selection since 1790
PATCH v2 4/6 Makefile: Remove redundant GCC version check
In reply to Wander Lairson CostaThe minimum GCC version check was introduced to handle the -fcf-protection flag, which was not available in older compiler versions. However, a more robust method that directly tests for compiler support for this flag has been implemented.
This commit removes the now-redundant GCC version check, simplifying the Makefile and relying on the more accurate feature detection.
--- Makefile | 5 ----- 1 file changed, 5 deletions(-)
Makefile +0 -5
@@ -14,11 +14,6 @@ GCC_VER=$(shell gcc --version | grep ^gcc | cut -f 3 -d ' ' | cut -f 1 -d '.') endif $(info GCC_VER=$(GCC_VER)) -# Does the current GCC compiler have fcf-protection and c99+ as default? -MIN_GCC_VER := 8 -IS_MINVER := $(intcmp $(GCC_VER), $(MIN_GCC_VER), false, true, true) -$(info IS_MINVER=$(IS_MINVER)) - USE_BPF := 1 MTUNE := -mtune=generic M64 := -m64
Signature · 1 line
2.51.1
Re: [stalld v2 4/6] Makefile: Remove redundant GCC version check
Quoted 36 lines · Wander Lairson Costa
The minimum GCC version check was introduced to handle the
-fcf-protectionflag, which was not available in older compiler versions. However, a more robust method that directly tests for compiler support for this flag has been implemented.This commit removes the now-redundant GCC version check, simplifying the
Makefileand relying on the more accurate feature detection.Signed-off-by Wander Lairson Costa <[email protected]>Cc Derek Barbosa <[email protected]>Cc John Kacur <[email protected]>Cc Juri Lelli <[email protected]>Cc Chunsheng Luo <[email protected]>--- Makefile | 5 ----- 1 file changed, 5 deletions(-)Makefile +0
-5@@ -14,11 +14,6 @@ GCC_VER=$(shell gcc --version | grep ^gcc | cut -f 3 -d ' ' | cut -f 1 -d '.') endif $(info GCC_VER=$(GCC_VER)) -# Does the current GCC compiler have fcf-protection and c99+ as default? -MIN_GCC_VER := 8 -IS_MINVER := $(intcmp $(GCC_VER), $(MIN_GCC_VER), false, true, true) -$(info IS_MINVER=$(IS_MINVER)) - USE_BPF := 1 MTUNE := -mtune=generic M64 := -m64Signature · 1 line
2.51.1
Signature · 2 lines
The United States Coast Guard Ruining Natural Selection since 1790
Re: [stalld v2 4/6] Makefile: Remove redundant GCC version check
In reply to Wander Lairson CostaQuoted 36 lines · Wander Lairson Costa
The minimum GCC version check was introduced to handle the
-fcf-protectionflag, which was not available in older compiler versions. However, a more robust method that directly tests for compiler support for this flag has been implemented.This commit removes the now-redundant GCC version check, simplifying the
Makefileand relying on the more accurate feature detection.Signed-off-by Wander Lairson Costa <[email protected]>Cc Derek Barbosa <[email protected]>Cc John Kacur <[email protected]>Cc Juri Lelli <[email protected]>Cc Chunsheng Luo <[email protected]>--- Makefile | 5 ----- 1 file changed, 5 deletions(-)Makefile +0
-5@@ -14,11 +14,6 @@ GCC_VER=$(shell gcc --version | grep ^gcc | cut -f 3 -d ' ' | cut -f 1 -d '.') endif $(info GCC_VER=$(GCC_VER)) -# Does the current GCC compiler have fcf-protection and c99+ as default? -MIN_GCC_VER := 8 -IS_MINVER := $(intcmp $(GCC_VER), $(MIN_GCC_VER), false, true, true) -$(info IS_MINVER=$(IS_MINVER)) - USE_BPF := 1 MTUNE := -mtune=generic M64 := -m64Signature · 1 line
2.51.1
Signature · 1 line
Derek <[email protected]>
PATCH v2 5/6 Makefile: Print BPF tool versions for debugging
In reply to Wander Lairson CostaThis commit adds informational messages to the Makefile to print the kernel version, clang version, and bpftool version. This will help in debugging BPF-related compilation issues by providing clear information about the build environment.
--- Makefile | 4 ++++ 1 file changed, 4 insertions(+)
Makefile +4 -0
@@ -121,6 +121,10 @@ VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL) VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ $(wildcard $(VMLINUX_BTF_PATHS)))) +$(info KERNEL=$(KERNEL_REL)) +$(info $(shell $(CLANG) --version | head -1)) +$(info $(shell $(BPFTOOL) --version)) + ifeq ($(ARCH),x86_64) CLANGARCH="-D__x86_64__" endif
Signature · 1 line
2.51.1
Re: [stalld v2 5/6] Makefile: Print BPF tool versions for debugging
Quoted 32 lines · Wander Lairson Costa
This commit adds informational messages to the
Makefileto print the kernel version, clang version, and bpftool version. This will help in debugging BPF-related compilation issues by providing clear information about the build environment.Signed-off-by Wander Lairson Costa <[email protected]>Cc Derek Barbosa <[email protected]>Cc John Kacur <[email protected]>Cc Juri Lelli <[email protected]>Cc Chunsheng Luo <[email protected]>--- Makefile | 4 ++++ 1 file changed, 4 insertions(+)Makefile +4
-0@@ -121,6 +121,10 @@ VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL) VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ $(wildcard $(VMLINUX_BTF_PATHS)))) +$(info KERNEL=$(KERNEL_REL)) +$(info $(shell $(CLANG) --version | head -1)) +$(info $(shell $(BPFTOOL) --version)) + ifeq ($(ARCH),x86_64) CLANGARCH="-D__x86_64__" endifSignature · 1 line
2.51.1
Looks good to me
Signature · 2 lines
The United States Coast Guard Ruining Natural Selection since 1790
PATCH v2 6/6 gitignore: Exclude Serena and Claude Code metadata
In reply to Wander Lairson CostaThis commit adds .serena and CLAUDE.md to the .gitignore file to prevent Serena IDE metadata and Claude Code documentation from being tracked in version control. These files are development environment specific and should not be part of the repository.
The .serena directory contains IDE-specific configuration and cache files, while CLAUDE.md is used for AI-assisted development guidance. Both are local-only files that vary between development environments and should remain untracked.
--- .gitignore | 2 ++ 1 file changed, 2 insertions(+)
.gitignore +2 -0
@@ -18,3 +18,5 @@ node_modules/ patches/ tests/legacy/test01 *.patch +.serena +CLAUDE.md
Signature · 1 line
2.51.1
Re: [stalld v2 6/6] gitignore: Exclude Serena and Claude Code metadata
Quoted 28 lines · Wander Lairson Costa
This commit adds .serena and CLAUDE.md to the .gitignore file to prevent Serena IDE metadata and Claude Code documentation from being tracked in version control. These files are development environment specific and should not be part of the repository.
The .serena directory contains IDE-specific configuration and cache files, while CLAUDE.md is used for AI-assisted development guidance. Both are local-only files that vary between development environments and should remain untracked.
Signed-off-by Wander Lairson Costa <[email protected]>--- .gitignore | 2 ++ 1 file changed, 2 insertions(+).gitignore +2
-0@@ -18,3 +18,5 @@ node_modules/ patches/ tests/legacy/test01 *.patch +.serena +CLAUDE.mdSignature · 1 line
2.51.1
Signature · 2 lines
The United States Coast Guard Ruining Natural Selection since 1790
Quoted 31 lines · Wander Lairson Costa
This patch series improves the stalld build system to be more portable across different architectures and compiler toolchains while adding better debugging capabilities. The main motivation is to eliminate hard-coded compiler version checks that were brittle and could fail on non-standard toolchains or different architectures.
The changes replace minimum version checks with direct compiler feature detection tests, ensuring that compiler flags are only used when actually supported. This approach tests each flag by attempting to compile a minimal test program, making the build system resilient to variations in compiler implementations across architectures like
x86_64, aarch64, s390x, i686, and powerpc. Additionally, the series adds build environment information output and cleans up redundant checks to improve maintainability.The series also includes minor improvements to explicitly specify the test target invocation and exclude development environment metadata from version control.
Wander Lairson Costa (6):
Makefile: Conditionally add -mno-omit-leaf-frame-pointer
Makefile: Improve compiler flag detection for -fcf-protection
Makefile: Explicitly run the 'test' target in the tests directory
Makefile: Remove redundant GCC version check
Makefile: Print BPF tool versions for debugging
gitignore: Exclude Serena and Claude Code metadata.gitignore | 2 ++ Makefile | 42 ++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 18 deletions(-)
Quoted 5 lines
Signed-off-by Wander Lairson Costa <[email protected]>Cc Derek Barbosa <[email protected]>Cc John Kacur <[email protected]>Cc Juri Lelli <[email protected]>Cc Chunsheng Luo <[email protected]>
Ack for the series (note that I have this now in my devel branch, which is based on v1.25.1)
Signature · 2 lines
The United States Coast Guard Ruining Natural Selection since 1790