From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iaJ/FPmZm2pT4SsAWB0awg (envelope-from ) for ; Sat, 05 Sep 2026 00:26:33 -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=UiWiglO6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4ECF01E09E; Sat, 05 Sep 2026 00:26:33 -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 E96AE1E091 for ; Sat, 05 Sep 2026 00:26:31 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80B664BB590D for ; Sat, 5 Sep 2026 04:26:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80B664BB590D 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=UiWiglO6 Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 9080D4BA2E0F for ; Sat, 5 Sep 2026 04:26:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9080D4BA2E0F 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 9080D4BA2E0F 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=1788582367; cv=none; b=G59CBy0cPQIK6a7kCQQFuKUx2eaS8cbH/BdPS0iIKRrOqUHN6EUclFWu0C6S9XI52xWLxapS32h2tUImHSvfygEF/5yVYU1NMMnshfT9vz24HQQHNc/0My2ozJn3d5GR2BuDhqPuSLHdGRuVFLHt60c2pXX9Mze1vptTiwG/K0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788582367; c=relaxed/simple; bh=bn+zwSRHc3hE5wHKl9aPWAsOuHlC5bTmrFaAUK2wgmg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=G+5EXMXg/ubMIVmDTZmNHx25HYJnk7ig1OH1r08QI8pi679TbG0TkHnegO3bimjXCZ1rOnWfLXwgjf/WFLBuKEc2AqYxopLUKb17sU+1KKoyVnqFcT+rIud1CkK/sUn88YwTzQkGUhPOOcZE6T/GKNzkkJEamLT4y/3SzoEAhKs= 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=UiWiglO6 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9080D4BA2E0F 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 6854Q1Lp081801 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 5 Sep 2026 00:26:06 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 6854Q1Lp081801 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1788582366; bh=I3oCuPBBm0PZzOGXGXotGFdnUd5rCaTMettJbaD2V/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=UiWiglO6mxQjnsKEgu3tC96Rmi5toMkG8r8R0tisA2zBRzx0sIO8PV3BXKelS11su Z03Vw4pmZzxvgTytYCZfz/JSf0Dcq53u4VSvrTHDk2lTAqbxT85qo7E0j6xxUe9TLi ocMVBzAHNwDoP16qB15VN/tdi9PG8RD8pwOdICCPtszQHcdnqUsrItDSSk8yu22nCc 1bv1zkoCkdffHOdhvNZQOl5cwZCi0usLZfh3HN09nzBjyHhNC3TsNdXrHnMwNKunGg 4aZHEc+rxgvH3KHhk9zVA7R/OyeE6L15AqkS+Wh0RyWsUDZXe+MArohmzVR71lIiKo L6snHV8O47ETQ== Received: by simark.ca (Postfix) id 12E381E09B; Sat, 05 Sep 2026 00:26:01 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 09/19] gdb: add check for stale build generated files Date: Sat, 5 Sep 2026 00:23:12 -0400 Message-ID: <20260905042353.1702204-10-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260905042353.1702204-1-simon.marchi@polymtl.ca> References: <20260905042353.1702204-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 5 Sep 2026 04:26:01 +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