From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +akoHKj6mmrw5CgAWB0awg (envelope-from ) for ; Fri, 04 Sep 2026 13:06:48 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=Bw9bF2kJ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 69FAD1E166; Fri, 04 Sep 2026 13:06:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 65EF71E033 for ; Fri, 04 Sep 2026 13:06:47 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 031814BB58E1 for ; Fri, 4 Sep 2026 17:06:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 031814BB58E1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=Bw9bF2kJ Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 118ED4BB3B96 for ; Fri, 4 Sep 2026 17:05:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 118ED4BB3B96 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 118ED4BB3B96 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788541555; cv=none; b=USXWI5NwRfG4QPY+aFaC5FXAmKUvHQTNuOHU46dFsm0oNIX28Memr0zMMkoxHcEWTYVj0F1uYZyU9qumpHDtMz3xEGNIYPAD8k0iUX0UjEcW+Y9JYGuf3ZQmxVx1yS+x/A4AcrtcbAOyyxbl8v9WgMaGTEDG3yAq9lTvJszX8CI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788541555; c=relaxed/simple; bh=bn+zwSRHc3hE5wHKl9aPWAsOuHlC5bTmrFaAUK2wgmg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aw+QkVvEPCyTktkCRcaEvHVI6qyZUNAIqLTFyIAGeeASE8Bk0Tv/3fYW70miRd7JAaZv4+s8EP5n6zeYkqGsr/xC7p3bkOpkRdAcz7MN1JQr3/67FOldS7Hf61wus6knpDshhN7ZL9GQ0+5/m4wtVQOY/7JDpWz+OpCQuPHbyJc= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=Bw9bF2kJ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 118ED4BB3B96 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 684H5mio142329 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 4 Sep 2026 13:05:53 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 684H5mio142329 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1788541553; bh=I3oCuPBBm0PZzOGXGXotGFdnUd5rCaTMettJbaD2V/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=Bw9bF2kJAKzRv4gJBrqUa3RjPasTzjSVVJ2XwK1LXSo3WS4f3eS9va+Ma7Vb9kGE1 87wEP1AB73YF9sIGYvggHcUDOBYJGN54gz7RB/GhpmIpo1GNESQ8dabVacb4uODYfD iDW7lg4NSd+I+Ee2RaQRbgQtT57wk5sXqAvYSL+eVG0A/f9GyUw2aO7kxktbliZhLV U/MkrKtf/C2m5kCH6IRexZKC6uYiS+CyW31lwckJWwNcnc9iSgUOMbKN5LMth1gNP6 VI4dUpDTuf30hQBl+FRjNO32qVbNdix7lMZy0sjTa69UVQob7QMYn/S9Cs24lOCpDy SlZS5G7rxl/Dg== Received: by simark.ca (Postfix) id 452501E033; Fri, 04 Sep 2026 13:05:48 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 08/17] gdb: add check for stale build generated files Date: Fri, 4 Sep 2026 12:56:40 -0400 Message-ID: <20260904170338.1643894-9-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904170338.1643894-1-simon.marchi@polymtl.ca> References: <20260904170338.1643894-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 4 Sep 2026 17:05:48 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi Before this series, building gdb generates a file called cp-name-parser.c, from cp-name-parser.y. After this series, cp-name-parser.c is a source file written by hand checked in git. When doing out of tree builds, a leftover generated cp-name-parser.c in the build directory would interfere with the build. To make "cp-name-parser.o", it will prefer the stale cp-name-parser.c from the build directory rather than the good cp-name-parser.c from the source directory. Debugging the build failure that arises from this can be difficult and time consuming, especially if you have never hit the problem before. I propose to add a check in the Makefile to point out if there exists a file in the build directory that is known to be stale and that could interfere with the build. The alternative is obviously to avoid naming the new file "cp-name-parser.c", but I don't want to avoid using a good and logical file name just because of that. The check looks like this when it catches something: Error: stale generated files found in the build directory: cp-name-parser.c They are left over from an older build of GDB and shadow the source files with the same name. Run "make clean" (or delete them manually) then build again. I made "make clean" remove those files, because why not, it seems convenient. The check and removal in "make clean" only happen when the source directory is different from the build directory. For in-tree builds, a stale generated cp-name-parser.c file would presumably prevent checking out a git commit that has a tracked cp-name-parser.c file. This patch only adds the machinery, the following patch adds cp-name-parser.c to the STALE_GENERATED_FILES list. I have done it in this order to avoid having some commits that could present the conflict but don't have the check. Change-Id: I109ba215b3e30debe82b711efb8826668fea0969 --- gdb/Makefile.in | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index e6c1587f4767..6cb5482bbc66 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2074,6 +2074,15 @@ YYOBJ = $(filter-out ada-lex-gen.o,$(patsubst %.c,%.o,$(YYFILES))) # The headers bison/byacc and flex generate alongside the files above. YYHFILES = $(patsubst %-gen.c,%-gen.h,$(YYFILES)) +# Files that used to be generated in the build directory (for builds from git +# at least), but are now committed source files. A leftover copy in an +# existing build directory would shadow the real source file with the same name +# and cause a hard to debug build failure. +# +# Files in there can be removed after a while, once build directories with them +# are unlikely to be around. +STALE_GENERATED_FILES = + # Things which need to be built when making a distribution. DISTSTUFF = $(YYFILES) $(YYHFILES) @@ -2091,9 +2100,32 @@ generated_files = \ # Flags needed to compile Python code PYTHON_CFLAGS = @PYTHON_CFLAGS@ -all: gdb$(EXEEXT) $(CONFIG_ALL) gcore gstack gdb-add-index +all: check-stale-generated-files gdb$(EXEEXT) $(CONFIG_ALL) gcore \ + gstack gdb-add-index @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=$(SUBDIRS)" subdir_do +# Error out if the build directory contains known stale generated files, which +# would shadow the source files with the same name and cause a hard to debug +# build failure. See STALE_GENERATED_FILES above. +.PHONY: check-stale-generated-files +check-stale-generated-files: + @if test "$(srcdir)" != "."; then \ + stale=""; \ + for f in $(STALE_GENERATED_FILES); do \ + if test -f "$$f"; then \ + stale="$$stale $$f"; \ + fi; \ + done; \ + if test -n "$$stale"; then \ + echo "Error: stale generated files found in the build directory:" >&2; \ + echo " $$stale" >&2; \ + echo "They are left over from an older build of GDB and shadow the" >&2; \ + echo "source files with the same name. Run \"make clean\" (or delete" >&2; \ + echo "them manually) then build again." >&2; \ + exit 1; \ + fi; \ + fi + # Rule for compiling .c files. %.o: %.c $(COMPILE) $< @@ -2417,6 +2449,9 @@ clean mostlyclean: $(CONFIG_CLEAN) for d in $(ALL_DEPDIRS); do \ if test -d "$$d"; then rmdir "$$d" || exit 1; fi; \ done + if test "$(srcdir)" != "."; then \ + rm -f $(STALE_GENERATED_FILES); \ + fi # This used to depend on c-exp.c m2-exp.c TAGS # I believe this is wrong; the makefile standards for distclean just -- 2.55.0