From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mQAbCzRaemoUtRsAWB0awg (envelope-from ) for ; Mon, 10 Aug 2026 19:09:40 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=aDO9gN/r; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 28CDE1E166; Mon, 10 Aug 2026 19:09:40 -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 [38.145.34.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 9B9891E09B for ; Mon, 10 Aug 2026 19:09:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D6AF4BB3BBA for ; Mon, 10 Aug 2026 23:09:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D6AF4BB3BBA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=aDO9gN/r Received: from seahorse.cherry.relay.mailchannels.net (seahorse.cherry.relay.mailchannels.net [23.83.223.161]) by sourceware.org (Postfix) with ESMTPS id E30B44BB3BD9 for ; Mon, 10 Aug 2026 23:09:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E30B44BB3BD9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=palves.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E30B44BB3BD9 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.223.161 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786403350; cv=none; b=LvmIinkCfk3zle+J/Nrp/DCYlmeA32hXFO3F1NjN9jyOcqXAI20hebcx8aZ7Gf6pb1rLyixi31cUjpIquwRHKk3DQc8EYcSJlOzpyXk/IA8zIsfWz9rX46x2pFJ98d06sn2nlsOi2TwxdP+uUD5rB+0BLMJRE1nP8i+F3hDNGXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786403350; c=relaxed/simple; bh=rIQ54GXgO18y+oxCT3241mBJBcbVqv8plTjRnzYcMwA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EVC/ee+Fu1b8Uo0ssPFcmQNvmKpLOg/kyKvOA16O8NbvpbUPxMkF+7NDvqTEnrNzau7xQ1gEG1U8DrW9WagUnEXritOQFXrdSchxafVLr3M+5coPVHdccE+iOyzng4tklNT3XCw6vMbf8/I/JLFf/HEGleDInL/2+1Ch3JjnrcA= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=aDO9gN/r DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E30B44BB3BD9 X-Sender-Id: dreamhost|x-authsender|pedro@palves.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E0AD9463FAE for ; Mon, 10 Aug 2026 23:09:08 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (100-112-42-149.trex-nlb.outbound.svc.cluster.local [100.112.42.149]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B544746268D for ; Mon, 10 Aug 2026 23:09:08 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|pedro@palves.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|pedro@palves.net X-MailChannels-Auth-Id: dreamhost X-Share-Duck: 44c54a2a1038b35e_1786403348780_218492795 X-MC-Loop-Signature: 1786403348780:3803445668 X-MC-Ingress-Time: 1786403348780 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.112.42.149 (trex/8.0.2); Mon, 10 Aug 2026 23:09:08 +0000 Received: from localhost (bl21-204-140.dsl.telepac.pt [2.82.204.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pedro@palves.net) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4hJr6X1dt6z1056 for ; Mon, 10 Aug 2026 16:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1786403348; bh=TmVmcP//Zc0Dt0Hd2ipkH9VLRQBXvAzlwhrqqsHAxJU=; h=From:To:Subject:Date:Content-Transfer-Encoding; b=aDO9gN/r4v6fHiyQO3DXiwIWW/LOuyRzxhYX8YxgB8MuNiX3SpoELndpiI8CnbVEo Q4YFbV+enu1JdeHcIhjfDzA4NiRW0b6eCS4Qx/Poa66hVl8RnuXKZI6RAyqrqBPSPu /9LCZSAnryepYWoOR5cIiYOOdoTIyeEjOF+9tiDB1hL5Qyt9uZkP+L0X1RTZo0i195 ZUJ1dKCukchEijnlsFh4SCvRcf3IVETG4hlQRhmvY2d3j0KNqszlf4hZhS7YlZzNQ6 KhJ0tAWzLjpd2b2UHYD0ovjGbqqE0zm3bTx16zR/VlgfnBFR26wBfoX/+2W1u6N0v3 Y4DlvLW+eCU1w== From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/2] testsuite/lib/set_unbuffered_mode.c: Use constructor priority Date: Tue, 11 Aug 2026 00:08:26 +0100 Message-ID: <20260810230826.3466696-3-pedro@palves.net> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260810230826.3466696-1-pedro@palves.net> References: <20260810230826.3466696-1-pedro@palves.net> 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 On native Windows, we link in testsuite/lib/set_unbuffered_mode.c to all executables. That file has a constructor function that disables output buffering. We want that constructor to run before the constructors of global C++ objects, in case those objects print to output. Currently, that is done by relying on the link order of object files on the link line affecting the global ctor order. On Windows, with gcc and clang targeting the GNU ABI, constructors are run in reverse link order. I.e., the constructors from the last objfile on the link line run first. That is not true if we compile with clang targeting the MSVC ABI, though. There, global ctors run on link line order. Like on Linux. This can instead be handled by setting a constructor priority. Constructors with a priority run before the global C++ objects' constructors. The GCC feature to allow specifying a constructor with a priority only appeared in GCC 4.3, released in 2008, and I added this set_unbuffered_mode feature to GDB also in 2008, so back then it was too early to rely on the priority feature. It's 2025 now, and I think we can safely assume nobody is testing on Windows with such an old compiler. So this patch gives an explicit priority to the testsuite/lib/set_unbuffered_mode.c constructor, and tweaks the comments in testsuite/lib/gdb.exp to no longer talk about controlling ctor order with link order. Tested with both GCC and Clang. Change-Id: Ia5f8972f2ef45f070e63cb0a1b0aa9918957ea8e --- gdb/testsuite/lib/gdb.exp | 9 ++++----- gdb/testsuite/lib/set_unbuffered_mode.c | 7 +++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 6fb04869605..fecb9af4883 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7046,13 +7046,12 @@ proc gdb_compile {source dest type options} { verbose "gdb_saved_set_unbuffered_obj already compiled" } - # Rely on the internal knowledge that the global ctors are ran in - # reverse link order. In that case, we can use ldflags to - # avoid copying the object file to the host multiple - # times. # This object can only be added if standard libraries are - # used. Thus, we need to disable it if -nostdlib option is used + # used. Thus, we need to disable it if -nostdlib option + # is used. if {[lsearch -regexp $options "-nostdlib"] < 0 } { + # Use ldflags to avoid copying the object file to the + # host multiple times. lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj" } } diff --git a/gdb/testsuite/lib/set_unbuffered_mode.c b/gdb/testsuite/lib/set_unbuffered_mode.c index 6d69ccabaeb..3b5badcf780 100644 --- a/gdb/testsuite/lib/set_unbuffered_mode.c +++ b/gdb/testsuite/lib/set_unbuffered_mode.c @@ -19,8 +19,11 @@ #include -static void __gdb_set_unbuffered_output (void) __attribute__ ((constructor)); -static void +/* Use an explicit priority so that this runs before constructors of + namespace-scope C++ objects (which may output to stdout/stderr). + Lower priorities run first. Constructor priorities from 0 to 100 + are reserved for the implementation. */ +static void __attribute__ ((constructor (101))) __gdb_set_unbuffered_output (void) { setvbuf (stdout, NULL, _IONBF, BUFSIZ); -- 2.54.0