From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id zrSaEOfET2qLsAAAWB0awg (envelope-from ) for ; Thu, 09 Jul 2026 11:57:27 -0400 Received: by simark.ca (Postfix, from userid 112) id 35E9F1E070; Thu, 09 Jul 2026 11:57:27 -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.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 9A33F1E070 for ; Thu, 09 Jul 2026 11:57:26 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89D244BA23E0 for ; Thu, 9 Jul 2026 15:57:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89D244BA23E0 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by sourceware.org (Postfix) with ESMTPS id C03474BA2E07 for ; Thu, 9 Jul 2026 15:57:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C03474BA2E07 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C03474BA2E07 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783612621; cv=none; b=FvzEKQ6Li92d/9tQMzIpWZ7FNDGZPKuggq8N0JbVKkTkCqaBMYMDj1kLWiZ1DImwzsMPIZcqRSSVs3dxI9V2UNmS3sjmx7T4se4duxDxryOrwtpHmEjQYNjJ6AgOMpCsvE8mPFPuV9uZkl+cV932pJse5sqQoZ2gX/q4tZHEdsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783612621; c=relaxed/simple; bh=4Fai7t3ufXjBDCXM174ZeTpfv4WSLY70Z3B2hX5ngX4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PzzUC9NiCeuPp2rNu/UQWqZFQT3PNysjP/ptm05M+qf9c4HEPqXeEcePIlwmqUd6ddSpzEQWbuFoeImlZpbvBzXvETcUU2jRCk6Vh9jkP+nzfRz/LMOfCxY8pj4rla540xEietYSupBmxsTJMo1HbqY8mvJxgsCvtCUZsSldRS4= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C03474BA2E07 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-493c7902f47so16547585e9.1 for ; Thu, 09 Jul 2026 08:57:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783612621; x=1784217421; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=+AF1gweBFcF5tDBGBlkHS9UmWvNjOGG8D0lyLESXYEI=; b=UETePse98/JVivrKJrHWoJxm09rFkurno9mcPXY1eJ+1ds3F9tWIa0jMMl0g4dBFQl T3cipGW+NsJ3JB0rDSJd9xoIiXn/0kUHcMURm2k6csAJqTVzyNoNCHFmH3f1PJDJitfv CgRMlww/uVwR4inRWt+Q7XSM93G/MNZRPVyc8mcpGK+nhDhDTuZLlNqAVOBGIPzGT6WG WaF39ACNQTjhmeiE+XEGL5iWXOheYqByCuRMti7Fm/rp1RHhplFp+GvI+jqqdVQG4QCZ cx7VufV2cJxIkRTs8huhw4rmcepxbGFk6mNlewYCEj9s2VVy2cBLhMry2gwb7V5BPwto OoMg== X-Gm-Message-State: AOJu0YxjcCEda5i4ARj1DyLsnwxWTy+MC0zWdwMG/hqMyoH8mQvYE9AW BoFnkQX7HmB4tGCuSLH3oKYtga60xQRtOxk+wLDbvmzCudjwLlV8euP0hviFiOaW X-Gm-Gg: AfdE7cnQc9pV++J7c6/hzPvnF38hNFKHzkKTpCFWJwsaFd8TbB8cC/XYZrEBOCz78jl 5x7DJIDFoTga9dV5pVjl24onGyqE3XYXczWTJMOMb170Jc+9ZvLy+sdP9eMjjSidJB17VYskUfN 0zLtkMug93WuwRP+wYQNEXGehkKN0EuEGbEeAWxBdacz6eSQY6LGoQRhv8VCHP3CRPaf4iYG3RN ikUqXOKZLqpwiRJoO8v94BZuvGf+RxBHSEj/2I72UA22bi8trZOG9N1gWwDtkT6GreT3Bfye6tW wDbSB7bGlPdNoZJkmmzK9MBbB6dG1daBGLNrbttmWR3IGNj2LUEVDvR9lLsBf58NRdkb7YlbZmJ uVRHX7jdB4tshXVv3fyDwEuK+WDXylP/Y3kryZxOzXAZ2dQOdvO8t8ZORVm5YQDwEw/Mu7A1vSW JFsvvYrNskxw== X-Received: by 2002:a05:600c:354e:b0:493:b87c:c87d with SMTP id 5b1f17b1804b1-493e683ab6bmr78941595e9.11.1783612620510; Thu, 09 Jul 2026 08:57:00 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:3700:fc87:ea6:fb9f:13e3]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-493eb66beddsm78187925e9.0.2026.07.09.08.56.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jul 2026 08:56:59 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Windows: Fix set_unbuffered_mode.o file rename race Date: Thu, 9 Jul 2026 16:56:57 +0100 Message-ID: <20260709155657.412594-1-pedro@palves.net> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The atomic file rename for set_unbuffered_mode.o can fail in this scenario: | process A | process B | |---------------------------------+---------------------------| | compiles temp .o | compiles temp .o | | moves .o | | | links with .o file (locks file) | moves .o (fails w/ EBUSY) | Here's what it looks like: builtin_spawn -ignore SIGHUP /mingw64/bin/clang -fdiagnostics-color=never -Wno-unknown-warning-option -w -c -o /c/msys2/home/alves/gdb/build-testsuite/temp/53930/set_unbuffered_mode-c.o /c/rocgdb/src/gdb/testsuite/lib/set_unbuffered_mode.c pid is 54259 -54259 pid is -1 output is status 0 ERROR: tcl error sourcing /c/rocgdb/src/gdb/testsuite/gdb.base/step-over-no-symbols.exp. ERROR: tcl error code POSIX EBUSY {file busy} ERROR: error renaming "/c/msys2/home/alves/gdb/build-testsuite/temp/53930/set_unbuffered_mode.o" to "/c/msys2/home/alves/gdb/build-testsuite/set_unbuffered_mode.o": file busy while executing "file rename -force -- $unbuf_obj $gdb_saved_set_unbuffered_mode_obj" (procedure "gdb_compile" line 559) invoked from within "gdb_compile $source $dest $type $options" (procedure "gdb_compile" line 42) invoked from within "$func $objects "${binfile}" executable $options" (procedure "build_executable_from_specs" line 50) invoked from within "build_executable_from_specs {*}$arglist" (procedure "build_executable" line 11) invoked from within "build_executable "failed to build" ${testfile} $srcfile" (file "/c/rocgdb/src/gdb/testsuite/gdb.base/step-over-no-symbols.exp" line 21) invoked from within "source /c/rocgdb/src/gdb/testsuite/gdb.base/step-over-no-symbols.exp" ("uplevel" body line 1) invoked from within "uplevel #0 source /c/rocgdb/src/gdb/testsuite/gdb.base/step-over-no-symbols.exp" invoked from within "catch "uplevel #0 source $test_file_name" msg" UNRESOLVED: gdb.base/step-over-no-symbols.exp: testcase '/c/rocgdb/src/gdb/testsuite/gdb.base/step-over-no-symbols.exp' aborted due to Tcl error If we get EBUSY, it's because another parallel worker already managed to build and move its set_unbuffered_mode.o copy to the final destination. So fix it by simply ignoring EBUSY. Put the rename in its own procedure, as I expect this will be used in more places. (Note: the set_unbuffered_mode.o path is Windows-specific.) Change-Id: I6a32d17364a19337d7f55e4376de736e1cca799d --- gdb/testsuite/lib/gdb.exp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index a40c87c6727..db5a0dd7afc 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6402,6 +6402,25 @@ proc quote_for_host { args } { return $str } +# Rename SRC to DST, ignoring EBUSY. This is used when multiple +# parallel workers all want to rename their copy of SRC to DST, as an +# atomic commit, and it doesn't matter which one wins, as all the +# copies are identical. +proc file_rename_atomic {src dst} { + set rc [catch { file rename -force -- $src $dst } err opts] + + if {$rc} { + set code [dict get $opts -errorcode] + if {[llength $code] >= 2 && [lindex $code 1] eq "EBUSY"} { + # Normal parallel race loss. + } else { + error $err $opts + } + } + + return $rc +} + # Compile source files specified by SOURCE into a binary of type TYPE at path # DEST. gdb_compile is implemented using DejaGnu's target_compile, so the type # parameter and most options are passed directly to it. @@ -6922,7 +6941,7 @@ proc gdb_compile {source dest type options} { # Make sure to write the .o file atomically. # (Note GDB_PARALLEL mode does not support remote # host testing.) - file rename -force -- $unbuf_obj $gdb_saved_set_unbuffered_mode_obj + file_rename_atomic $unbuf_obj $gdb_saved_set_unbuffered_mode_obj } else { remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj } base-commit: b43c744924b3f5df3677dbe97d12608e63ca5a4d -- 2.54.0