From 5ba1ff9fa5aefafa54bd53ebcfddf8b75048bb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 19:31:31 +0000 Subject: [PATCH 1/5] CA-407107: drop release mode, it is unused MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xha.spec does a 'make install' which installs the debug build by default. The only difference between debug and release is NDEBUG (no -O flags are used), but considering that we've always shipped the debug version in production builds, keep that one. There are some advantages to shipping the debug version: * stacktraces may work better than at O2 * if the assertions finds a bug in the code it might be better to stop, rather than continue and do something incorrect (corrupt memory, etc.). Given that in the past years that we've been shipping XHA with asserts on we haven't really found failed assertions, keep them on. Signed-off-by: Edwin Török --- Makefile | 32 +++----------------------------- default-debug.mk | 3 +-- default-release.mk | 27 --------------------------- readme | 2 -- 4 files changed, 4 insertions(+), 60 deletions(-) delete mode 100755 default-release.mk diff --git a/Makefile b/Makefile index c099041..c22100d 100755 --- a/Makefile +++ b/Makefile @@ -2,13 +2,11 @@ # Top-level Makefile # # This makefile installs the debug version (compiled without NDEBUG). -# To install release version, do "make release-install" or -# modify this makefile to do release install by default. See #here below. # -.PHONY: build clean debug release +.PHONY: build clean debug -all: debug release +all: debug debug: @mkdir -p debug @@ -18,15 +16,7 @@ debug: @cd commands; make DEFMAKE=default-debug.mk @cd scripts; make DEFMAKE=default-debug.mk -release: - @mkdir -p release - @cd include; make DEFMAKE=default-release.mk - @cd lib; make DEFMAKE=default-release.mk - @cd daemon; make DEFMAKE=default-release.mk - @cd commands; make DEFMAKE=default-release.mk - @cd scripts; make DEFMAKE=default-release.mk - -clean: debug-clean release-clean +clean: debug-clean debug-clean: @cd include; make clean DEFMAKE=default-debug.mk @@ -36,14 +26,6 @@ debug-clean: @cd scripts; make clean DEFMAKE=default-debug.mk -rmdir debug -release-clean: - @cd include; make clean DEFMAKE=default-release.mk - @cd lib; make clean DEFMAKE=default-release.mk - @cd daemon; make clean DEFMAKE=default-release.mk - @cd commands; make clean DEFMAKE=default-release.mk - @cd scripts; make clean DEFMAKE=default-release.mk - -rmdir release - #here install: debug-install @@ -54,11 +36,3 @@ debug-install: @cd daemon; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk @cd commands; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk @cd scripts; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk - -release-install: - @mkdir -p release - @cd include; make install DESTDIR=$(DESTDIR) DEFMAKE=default-release.mk - @cd lib; make install DESTDIR=$(DESTDIR) DEFMAKE=default-release.mk - @cd daemon; make install DESTDIR=$(DESTDIR) DEFMAKE=default-release.mk - @cd commands; make install DESTDIR=$(DESTDIR) DEFMAKE=default-release.mk - @cd scripts; make install DESTDIR=$(DESTDIR) DEFMAKE=default-release.mk diff --git a/default-debug.mk b/default-debug.mk index 80577aa..d292ee1 100755 --- a/default-debug.mk +++ b/default-debug.mk @@ -6,7 +6,6 @@ CC=gcc SOURCEDIR=.. CFLAGS=-g -Wall -Wno-multichar -Werror=pointer-to-int-cast - OBJDIR=$(SOURCEDIR)/debug INCDIR=$(SOURCEDIR)/include @@ -16,7 +15,7 @@ HALIBS=$(OBJDIR)/libxha.a INSDIR=/usr/libexec/xapi/cluster-stack/xhad LOGCONFDIR=/etc/logrotate.d -.PHONY: build clean debug release +.PHONY: build clean debug %.o: %.c $(INCDIR)/*.h $(CC) $(CFLAGS) $(INCLUDES) -c $< diff --git a/default-release.mk b/default-release.mk deleted file mode 100755 index 44960fe..0000000 --- a/default-release.mk +++ /dev/null @@ -1,27 +0,0 @@ -# -# default-release.mk -# - -CC=gcc -SOURCEDIR=.. -CFLAGS=-g -Wall -Wno-multichar -Werror=pointer-to-int-cast - -CFLAGS+=-DNDEBUG -OBJDIR=$(SOURCEDIR)/release - -INCDIR=$(SOURCEDIR)/include -INCLUDES=-I$(INCDIR) -LIBS=-lxml2 -lrt -HALIBS=$(OBJDIR)/libxha.a -INSDIR=/usr/libexec/xapi/cluster-stack/xhad -LOGCONFDIR=/etc/logrotate.d - -.PHONY: build clean debug release - -%.o: %.c $(INCDIR)/*.h - $(CC) $(CFLAGS) $(INCLUDES) -c $< - -%.a: %.c $(INCDIR)/*.h - $(CC) $(CFLAGS) $(INCLUDES) -c $< - @$(AR) rv $@ $*.o - @$(RM) $*.o diff --git a/readme b/readme index 5c7bc02..7d129e4 100644 --- a/readme +++ b/readme @@ -41,8 +41,6 @@ Date: April 18, 2008 Top-level makefile of xha. default-debug.mk Various make defaults for debug build. - default-release.mk - Various make defaults for release build. commands/ Source files of utility programs for the HA scripts. daemon/ From 33447f5c6c46bd49048b21c6d14cd710a38e1d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 19:34:43 +0000 Subject: [PATCH 2/5] CA-407107: Use -Og MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GCC manual recommends this over O0 to improve the debugging experience: > It is a better choice than -O0 for producing debuggable code because some compiler passes > that collect debug information are disabled at -O0.:w It is also better than -O2 that rpmbuild would use because according to the GCC manual: > To get more accurate stack traces, it is possible to use options such as -O0, -O1, or -Og (which, for instance, prevent most function inlining), -fno-optimize-sibling-calls (which prevents optimizing sibling and tail recursive calls; this option is implicit for -O0, -O1, or -Og), or -fno-ipa-icf (which disables Identical Code Folding for functions) `-ipa-icf` is only enabled at -O2 and above, so using -Og here should be fine. (stacktraces are printed by log.c) Signed-off-by: Edwin Török --- default-debug.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default-debug.mk b/default-debug.mk index d292ee1..b10c02c 100755 --- a/default-debug.mk +++ b/default-debug.mk @@ -4,7 +4,7 @@ CC=gcc SOURCEDIR=.. -CFLAGS=-g -Wall -Wno-multichar -Werror=pointer-to-int-cast +CFLAGS=-g -Wall -Wno-multichar -Werror=pointer-to-int-cast -Og OBJDIR=$(SOURCEDIR)/debug From 68a55d4c4fb3ad457efbb94b3bcf5984795657d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 19:52:59 +0000 Subject: [PATCH 3/5] CA-407107: honor LDFLAGS from rpmbuild MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add it to LIBS at the end. Signed-off-by: Edwin Török --- daemon/Makefile | 3 +-- default-debug.mk | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/daemon/Makefile b/daemon/Makefile index 9bf3d9c..c4eec71 100755 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -1,7 +1,6 @@ # # daemon/Makefile # - TARGET_DIR=daemon DEFMAKE=default-debug.mk include ../$(DEFMAKE) @@ -33,7 +32,7 @@ OBJS +=$(OBJDIR)/hostweight.o all: $(TARGET) $(LST) $(TARGET): $(OBJS) $(HALIBS) - $(CC) -o $@ $(LIBS) $(OBJS) $(HALIBS) $(LIBS) + $(CC) -o $@ $(OBJS) $(HALIBS) $(LIBS) @chmod 0755 $@ $(LST): $(TARGET) diff --git a/default-debug.mk b/default-debug.mk index b10c02c..15cf4b7 100755 --- a/default-debug.mk +++ b/default-debug.mk @@ -10,7 +10,7 @@ OBJDIR=$(SOURCEDIR)/debug INCDIR=$(SOURCEDIR)/include INCLUDES=-I$(INCDIR) -LIBS=-lxml2 -lrt +LIBS=-lxml2 -lrt $(LDFLAGS) HALIBS=$(OBJDIR)/libxha.a INSDIR=/usr/libexec/xapi/cluster-stack/xhad LOGCONFDIR=/etc/logrotate.d From 9df87754f125acb7ea50f0668a9b1a2014efabba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 19:52:59 +0000 Subject: [PATCH 4/5] CA-407107: Use -Og MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stacktraces are printed by log.c, to make them better use -Og which prevents some optimizations that would alter stacktraces significantly. Signed-off-by: Edwin Török --- default-debug.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default-debug.mk b/default-debug.mk index 15cf4b7..3631560 100755 --- a/default-debug.mk +++ b/default-debug.mk @@ -4,7 +4,7 @@ CC=gcc SOURCEDIR=.. -CFLAGS=-g -Wall -Wno-multichar -Werror=pointer-to-int-cast -Og +override CFLAGS+=-g -Wall -Wno-multichar -Werror=pointer-to-int-cast -Og OBJDIR=$(SOURCEDIR)/debug From e0d8153e27bf309ee15ba86a1f7c9cfbd12898fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 21 Feb 2025 20:13:56 +0000 Subject: [PATCH 5/5] CA-407107: make rules parallel-build-safe and enable parallel builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parallel builds can be enabled by using `$(MAKE)` instead of `make`. However the current rules have race conditions and do not fully declare their dependencies: * the .a rule was producing an archive out of whatever .o files it could fine at the time it ran, and it also deleted the files it produced * the .a rule always rebuilt all the files * the .a rule produced some file that were also produced by the %.o: %.c rule, leading to a race condition Move the .a rule to the lib subdirectory, and explicitly specify dependencies and only use files during a build that have been declared as a dependency of a rule. Also enable incremental builds by removing the PHONY from buildid.h. During an RPM build we'll get a clean build and redefined buildid anyway. Signed-off-by: Edwin Török --- .gitignore | 3 +++ Makefile | 30 +++++++++++++++--------------- default-debug.mk | 4 ---- include/Makefile | 1 - lib/Makefile | 7 +++++-- stubs/Makefile | 4 ++-- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 8a1ce60..13c1c43 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ include/mtcerrno.h scripts/generr scripts/generr.o scripts/ha_errnorc +stubs/cfread +*.o +*.a diff --git a/Makefile b/Makefile index c22100d..62df803 100755 --- a/Makefile +++ b/Makefile @@ -10,20 +10,20 @@ all: debug debug: @mkdir -p debug - @cd include; make DEFMAKE=default-debug.mk - @cd lib; make DEFMAKE=default-debug.mk - @cd daemon; make DEFMAKE=default-debug.mk - @cd commands; make DEFMAKE=default-debug.mk - @cd scripts; make DEFMAKE=default-debug.mk + $(MAKE) -C include DEFMAKE=default-debug.mk + $(MAKE) -C lib DEFMAKE=default-debug.mk + $(MAKE) -C daemon DEFMAKE=default-debug.mk + $(MAKE) -C commands DEFMAKE=default-debug.mk + $(MAKE) -C scripts DEFMAKE=default-debug.mk clean: debug-clean debug-clean: - @cd include; make clean DEFMAKE=default-debug.mk - @cd lib; make clean DEFMAKE=default-debug.mk - @cd daemon; make clean DEFMAKE=default-debug.mk - @cd commands; make clean DEFMAKE=default-debug.mk - @cd scripts; make clean DEFMAKE=default-debug.mk + @cd include; $(MAKE) clean DEFMAKE=default-debug.mk + @cd lib; $(MAKE) clean DEFMAKE=default-debug.mk + @cd daemon; $(MAKE) clean DEFMAKE=default-debug.mk + @cd commands; $(MAKE) clean DEFMAKE=default-debug.mk + @cd scripts; $(MAKE) clean DEFMAKE=default-debug.mk -rmdir debug #here @@ -31,8 +31,8 @@ install: debug-install debug-install: @mkdir -p debug - @cd include; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk - @cd lib; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk - @cd daemon; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk - @cd commands; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk - @cd scripts; make install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk + @cd include; $(MAKE) install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk + @cd lib; $(MAKE) install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk + @cd daemon; $(MAKE) install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk + @cd commands; $(MAKE) install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk + @cd scripts; $(MAKE) install DESTDIR=$(DESTDIR) DEFMAKE=default-debug.mk diff --git a/default-debug.mk b/default-debug.mk index 3631560..e7bae28 100755 --- a/default-debug.mk +++ b/default-debug.mk @@ -20,7 +20,3 @@ LOGCONFDIR=/etc/logrotate.d %.o: %.c $(INCDIR)/*.h $(CC) $(CFLAGS) $(INCLUDES) -c $< -%.a: %.c $(INCDIR)/*.h - $(CC) $(CFLAGS) $(INCLUDES) -c $< - @$(AR) rv $@ $*.o - @$(RM) $*.o diff --git a/include/Makefile b/include/Makefile index 2e526bc..25ae6ec 100755 --- a/include/Makefile +++ b/include/Makefile @@ -14,7 +14,6 @@ all: $(TARGET) mtcerrno.h: errdef.awk mtcerrno.def gawk -f errdef.awk mtcerrno.def > $@ -.PHONY: buildid.h buildid.h: sh buildid.sh > $@ diff --git a/lib/Makefile b/lib/Makefile index afed6a2..2ea8647 100755 --- a/lib/Makefile +++ b/lib/Makefile @@ -13,11 +13,14 @@ OBJS +=config.o OBJS +=error.o OBJS +=weightio.o -TARGET=$(HALIBS)($(OBJS)) +TARGET=$(HALIBS) + +$(HALIBS): $(OBJS) + @$(AR) rv $@ $(OBJS) all: $(TARGET) install: $(TARGET) clean: - rm -f $(HALIBS) + rm -f $(HALIBS) $(OBJS) diff --git a/stubs/Makefile b/stubs/Makefile index bc50cfa..8703210 100755 --- a/stubs/Makefile +++ b/stubs/Makefile @@ -16,12 +16,12 @@ TARGET= $(SCRIPTDIR)/cfread \ $(FRC) all: - (cd cfread-libxml2; make) + $(MAKE) -C cfread-libxml2 install: -mkdir -p $(DESTDIR)$(SCRIPTDIR) -cp ha_* cfread $(DESTDIR)$(SCRIPTDIR) clean: - (cd cfread-libxml2; make clean) + $(MAKE) -C cfread-libxml2 clean -rm -f $(TARGET)